apicloud中bMap模块应用
来源:互联网 发布:万德数据库电话 编辑:程序博客网 时间:2024/05/16 04:15
var map = nullapiready = function () { // 加载百度地图模块 map = api.require( 'bMap' ); // 判断定位功能是否开启 map.getLocationServices( function ( ret, err ) { if ( ret.enable ) {} else { alert( "未开启定位功能!" ); } } ); // 监听到进入后台时停止定位 api.addEventListener( { name: 'pause' }, function ( ret, err ) { map.stopLocation(); } ); //开启地图 openMap();}// 打开地图function openMap() { map.open( { // (可选项)模块的位置及尺寸 rect: { x: 0, //(可选项)数字类型;地图左上角的 x 坐标(相对于所属的 Window 或 Frame);默认:0 y: 0, //(可选项)数字类型;地图左上角的 y 坐标(相对于所属的 Window 或 Frame);默认:0 w: api.frameWidth, //(可选项)数字类型;地图的宽度;默认:所属的 Window 或 Frame 的宽度 h: api.frameHeight //(可选项)数字类型;地图的高度;默认:所属的 Window 或 Frame 的高度 }, zoomLevel: 18, //(可选项)设置百度地图缩放等级,取值范围:3-18级 showUserLocation: true, //(可选项)是否在地图上显示用户位置 fixedOn: api.frameName, //(可选项)模块视图添加到指定 frame 的名字(只指 frame,传 window 无效) fixed: true //(可选项)模块是否随所属 window 或 frame 滚动 }, function ( ret ) { if ( ret.status ) { // 显示用户的位置 map.showUserLocation( { isShow: true, trackingMode: 'none' //罗盘compass } ); // 是否显示比例尺 map.setScaleBar( { show: true, position: { x: 25, //(可选项)数字类型;比例尺左上角的 x 坐标(相对于地图);默认:0 y: api.frameHeight - 60 //(可选项)数字类型;比例尺左上角的 y 坐标(相对于地图);默认:0 } } ); //搜索路线 map.searchRoute( { type: 'drive', policy: 'ecar_fee_first', start: { lon: 116.403838, lat: 39.914437 }, end: { lon: 116.384852, lat: 39.989576 } }, function ( ret, err ) { if ( ret.status ) { //绘制路线 map.drawRoute( { id: 1, autoresizing: false, index: 0, styles: { start: { icon: 'widget://image/bmap_start.png' }, end: { icon: 'widget://image/bmap_end.png' } } }, function ( ret ) { api.alert( { msg: JSON.stringify( ret ) } ); } ); } else { api.alert( { msg: JSON.stringify( err ) } ); } } ); } else { alert( "地图打开失败" ); } } );}//关闭地图function closeMap() { map.close();}//地图监听事件function addEventListener() { map.addEventListener( { name: 'viewChange' }, function ( ret ) { if ( ret.status ) { alert( JSON.stringify( ret ) ); } } );}//判断已知点是否在指定的多边形区域内function isPolygonContantsPoint() { map.isPolygonContantsPoint( { point: { lon: 116.39432327, lat: 39.98963192 }, points: [ { lon: 116.39432327, lat: 39.98963192 }, { lon: 116.49432328, lat: 39.98963192 }, { lon: 116.39432327, lat: 39.88933191 } ] }, function ( ret ) { alert( ret.status ); } );}//获取地图缩放等级function getZoomLevel() { map.getZoomLevel( function ( ret ) { alert( ret.level ); } );}// 已打点地块addPolygon形成轨迹function addPolygon( num, pointArr ) { map.addPolygon( { id: 2, styles: { borderColor: '#ffc65c', borderWidth: 3, fillColor: '#ffc65c' }, points: [ { lon: 116.39432327, lat: 39.98963192 }, { lon: 116.49432328, lat: 39.98963192 }, { lon: 116.39432327, lat: 39.88933191 } ] } );}//调用addLine方法画轨迹function addline( lineId, pointsArr ) { map.addLine( { id: 1, styles: { borderColor: '#49aff0', borderWidth: 3 }, points: [ { lon: 116.39432327, lat: 39.98963192 }, { lon: 116.49432328, lat: 39.98963192 }, { lon: 116.39432327, lat: 39.88933191 } ] } );};//调用addCircle方法画轨迹function addCircle( CirId, pointsObj ) { map.addCircle( { id: 4, center: { lon: 116.39432327, lat: 39.98963192 }, radius: 500, styles: { borderColor: '#FF0000', borderWidth: 3, fillColor: '#0000ff' } } );};//地图添加布告牌function addBillboard( billBoardId, position, bgImgUrl, title, illusUrl ) { map.addBillboard( { id: 4, coords: { lon: 116.233, lat: 39.134 }, bgImg: 'widget://image/bMapTest.png', content: { title: '大标题大标题大标题大标题', subTitle: '概述内容概述内容概述内容', illus: 'http://ico.ooopic.com/ajax/iconpng/?id=145044.png' }, styles: { titleColor: '#000', titleSize: 16, subTitleColor: '#999', subTitleSize: 12, illusAlign: 'left' } }, function ( ret ) { if ( ret ) { alert( JSON.stringify( ret ) ); } } );}//地图添加标注信息function annotation_( pointArr, iconUrl ) { map.addAnnotations( { annotations: [ { id: 1, lon: 116.297, lat: 40.109 }, { id: 2, lon: 116.29, lat: 40.109 }, { id: 3, lon: 116.298, lat: 40.11 } ], icon: 'widget://', draggable: true }, function ( ret ) { if ( ret ) { alert( ret.id ); } } );}//设置当前中心位置function nowPosition() { map.getLocation( { accuracy: '10m', autoStop: true, filter: 10 }, function ( ret, err ) { if ( ret.status ) { map.setCenter( { coords: { lon: ret.lon, lat: ret.lat }, animation: true } ); } else { api.alert( { msg: "获取位置信息失败,请重试!" } ); } } );}// 重新设置我的位置function ownPositionEvent() { bMap.getLocation( { accuracy: '100m', autoStop: true, filter: 10 }, function ( ret, err ) { if ( ret.status ) { bMap.setCenter( { coords: { lon: ret.lon, lat: ret.lat }, animation: true } ); } else { api.alert( { msg: "获取位置信息失败,请重试!" } ) } } )}//获取地图两点之间距离function getDistance() { map.getDistance( { start: { lon: 106.486654, lat: 29.490295 }, end: { lon: 106.581515, lat: 29.615467 } }, function ( ret ) { if ( ret.status ) { alert( ret.distance ); } } )}//点击标注时弹出气泡信息function setBubble( bubbleId, bgImgUrl, title, illusUrl ) { map.setBubble( { id: 2, bgImg: 'widget://res/bubble_bg.png', content: { title: '大标题', subTitle: '概述内容', illus: 'http://ico.ooopic.com/ajax/iconpng/?id=145044.png' }, styles: { titleColor: '#000', titleSize: 16, subTitleColor: '#999', subTitleSize: 12, illusAlign: 'left' } }, function ( ret ) { if ( ret ) { alert( JSON.stringify( ret ) ); } } );}// 将地图切换到卫星地图模式function satellite() { map.setMapAttr( { type: 'satellite' } );}// 将地图切换到标准模式function standard() { map.setMapAttr( { type: 'standard' } );}// 显示地图function show() { map.show();}// 隐藏地图function hide() { map.hide();}
阅读全文
0 0
- apicloud中bMap模块应用
- APICloud bMap api
- apiCloud应用笔记(三)————UILoading模块
- APICloud协同开发应用使用单个模块以及多个模块包得使用
- apicloud应用 用js跳转到苹果safari浏览器中
- APICloud应用基础
- apicloud数据交互mcm模块
- Apicloud中引导界面
- 百度地图BMap API的应用实例
- 百度地图BMap API的应用实例
- 百度地图BMap API的应用实例
- 百度地图BMap API的应用实例
- 百度地图BMap API的应用实例
- apicloud应用笔记(一)
- apicloud应用笔记(二)
- APICloud
- APICloud
- APICloud 图片轮播模块 UIScrollPicture
- Android性能指标FPS获取的JAVA实现
- 类的static成员函数与普通成员函数的区别
- 2D 太空打飞机游戏 Bitfighter源码下载(C/C++ Lua)
- RK3288
- [LeetCode]728. Self Dividing Numbers
- apicloud中bMap模块应用
- CSDN如何转载别人的文章
- 设计模式 装饰者模式 带你重回传奇世界
- Python的zip函数
- Mybatis中的resultType和resultMap
- 基础数据机构之WeakHashMap源码分析
- 使用doc4j生成word文档
- 【Spring+SpringMVC+MyBatis深入学习及搭建】11.SpringMVC架构
- MySQL数据类型和常用字段属性总结