开发者可通过调用mapController.setLocationInfo方法对定位图层进行定位数据、展示配置等控制。也可通过单独调用setLocation单独对定位数据进行设置,或者单独调用setLocationConfig对定位个性化展示配置进行设置。
配置项参数如下:
定位点数据设置项ILocation:
定位图层配置项ILocationConfig:
MapComponent({ onReady: async (err, mapController) => {if (!err) {// 获取地图的控制器类,用来操作地图this.mapController= mapController;let myLocation: ILocation = {latlng: new LatLng(39.907916, 116.408599),direction: 90,radius: 1000}this.mapController?.setLocationInfo(this.myLocation, {locationMode: SysEnum.LocationMode.NORMAL});}}, mapOptions: this.mapOpt}).width('100%').height('100%')
通过ILocationConfig来构造定位图层的配置,定位模式、是否开启方向、设置自定义定位图标、精度圈填充颜色等。开发者可以利用mapController中的setLocationInfo或者setLocationConfig方法来设置地图类型,下面做简单展示。
地图SDK支持三种定位模式:NORMAL(普通态), FOLLOWING(跟随态),COMPASS(罗盘态)
//默认普通态this.mapController?.setLocationConfig({locationMode:SysEnum.LocationMode.NORMAL})//跟随态this.mapController?.setLocationConfig({locationMode:SysEnum.LocationMode.FOLLOWING})//罗盘态this.mapController?.setLocationConfig({locationMode:SysEnum.LocationMode.COMPASS})
const flower = await this.createBitmapDescriptor($rawfile('flower.png'));const arrow = await this.createBitmapDescriptor($rawfile('end.png'));let config:ILocationConfig = {isEnableCustom:true, // 开启个性化配置arrow: end, //箭头图标设置arrowSize: 2, //箭头大小设置customMarker:flower, //定位marker图标设置markerSize: 0.2, //定位marker大小设置isNeedAnimation: true //开启气泡动画}this.mapController.setLocationConfig(config)
显示效果如下:
await this.copyRawFileToAppFiles(this.context,'icon_cat.gif');let config:ILocationConfig = {isEnableCustom:true,arrow: end,arrowSize: 2,isNeedAnimation: false, //关闭呼吸动画gifMarker: `${this.context.tempDir}/icon_cat.gif`, //设置定位marker为gif资源markerSize: 0.2,accuracyCircleFillColor: '#FFC0CB' //设置精度圈为粉色}this.mapController.setLocationConfig(config)
显示效果如下:
上一篇
下一篇