From 23b4d3dc419ac40d81237c38fa54a1250614b2d1 Mon Sep 17 00:00:00 2001 From: handongxun Date: Thu, 24 Mar 2022 15:39:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20app-vue=20map=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=20polygons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-plus/view/components/map/index.vue | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/platforms/app-plus/view/components/map/index.vue b/src/platforms/app-plus/view/components/map/index.vue index db9e65642..d6de48648 100644 --- a/src/platforms/app-plus/view/components/map/index.vue +++ b/src/platforms/app-plus/view/components/map/index.vue @@ -46,6 +46,7 @@ const attrs = [ 'scale', 'markers', 'polyline', + 'polygons', 'circles', 'controls', 'show-location' @@ -115,6 +116,12 @@ export default { return [] } }, + polygons: { + type: Array, + default () { + return [] + } + }, controls: { type: Array, default () { @@ -186,6 +193,9 @@ export default { }, circles (val) { this.map && this._addMapCircles(val) + }, + polygons (val) { + this.map && this._addMapPolygons(val) } }, mounted () { @@ -199,6 +209,7 @@ export default { map.__markers_map__ = {} map.__lines__ = [] map.__circles__ = [] + map.__polygons__ = [] map.setZoom(parseInt(this.scale)) plus.webview.currentWebview().append(map) if (this.hidden) { @@ -218,6 +229,7 @@ export default { this._addMarkers(this.markers) this._addMapLines(this.polyline) this._addMapCircles(this.circles) + this._addMapPolygons(this.polygons) }) }, beforeDestroy () { @@ -423,6 +435,48 @@ export default { nativeMap.addOverlay(nativeCircle) nativeMap.__circles__.push(nativeCircle) }) + }, + _addMapPolygons (polygons) { + const nativeMap = this.map + + const nativeMapPolygons = nativeMap.__polygons__ + polygons.forEach(polygon => { + nativeMap.removeOverlay(polygon) + }) + nativeMapPolygons.length = 0 + + polygons.forEach(polygon => { + const { + points, + strokeWidth, + strokeColor, + fillColor, + zIndex, + level + } = polygon + const plusPoints = [] + if (points) { + points.forEach(({ latitude, longitude }) => { + plusPoints.push(new plus.maps.Point(longitude, latitude)) + }) + } + const nativePolygon = new plus.maps.Polygon(plusPoints) + if (strokeColor) { + const strokeStyle = parseHex(strokeColor) + nativePolygon.setStrokeColor(strokeStyle.color) + nativePolygon.setStrokeOpacity(strokeStyle.opacity) + } + if (fillColor) { + const fillStyle = parseHex(fillColor) + nativePolygon.setFillColor(fillStyle.color) + nativePolygon.setFillOpacity(fillStyle.opacity) + } + if (strokeWidth) { + nativePolygon.setLineWidth(strokeWidth) + } + nativeMap.addOverlay(nativePolygon) + nativeMapPolygons.push(nativePolygon) + }) } } } -- GitLab