高德地图加载多个围栏、行政区查询方法

 高德地图开放平台行政区查询跳转链接https://lbs.amap.com/api/jsapi-v2/guide/services/district-search高德地图行政区边界查询官方演示https://lbs.amap.com/demo/jsapi-v2/example/district-search/draw-district-boundaries

export default {

	data() {

		return {

			feld: [
				[
					[

						123.435784,

						41.848393

					],

					[

						123.469704,

						41.855683

					],

					[

						123.431909,

						41.835569

					],

					[

						123.486417,

						41.84349

					]

				],

				[

					[

						123.355632,

						41.855683

					],

					[

						123.35597,

						41.838587

					],

					[

						123.392252,

						41.861716

					],

					[

						123.382127,

						41.837581

					]

				]

			]

		}

	}

	methods: {
		loadMap() {

			AMapLoader.load({

					key: ' 1451fsgsgg', // 申请好的Web端开发者Key,首次调用 load 时必填

					version: '1.4.15', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15

					plugins: [

						'AMap.DistrictSearch',

						'AMap.Geolocation',

						'AMap.Autocomplete',

						'AMap.PlaceSearch',

						'AMap.Scale',

						'AMap.OverView',

						'AMap.ToolBar',

						'AMap.MapType',

						'AMap.PolyEditor',

						'AMap.CircleEditor'

					], // 需要使用的的插件列表,如比例尺'AMap.Scale'等

					AMapUI: {

						// 是否加载 AMapUI,缺省不加载

						version: '1.1', // AMapUI 缺省 1.1

						plugins: [] // 需要加载的 AMapUI ui插件

					},

					Loca: {

						// 是否加载 Loca, 缺省不加载

						version: '1.3.2' // Loca 版本,缺省 1.3.2

					}

				})

				.then((AMap) => {

					console.log(this.feId)

					if (this.feId[0].length > 0) {

						var map = new AMap.Map('container2', {

							resizeEnable: true,

							zoom: 10,

							center: this.feId[0][0]

						})

						for (var x = 0; x < this.feId.length; x++) {

							// 获取地区围栏多边形集合

							var bounds = []

							bounds.push(this.feId[x])

							var polygons = []

							console.log(bounds)

							if (bounds) {

								for (var i = 0, l = bounds.length; i < l; i++) {

									// 生成行政区划polygon

									var polygon = new AMap.Polygon({

										// map: map,

										strokeWeight: 1,

										path: bounds[i],

										fillOpacity: 0.7,

										fillColor: '#CCF3FF',

										strokeColor: '#CC66CC'

									})

									polygons.push(polygon)

								}

							}

							map.add(polygons)

							this.getTraceById(map)

							// 地图自适应

							map.setFitView()

						}

					}

				})

				.catch((e) => {

					console.log(e)

				})

		}
	}
}

效果图

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值