提交 23b4d3dc 编写于 作者: d-u-a's avatar d-u-a

feat: app-vue map 组件新增支持 polygons

上级 87f0262d
...@@ -46,6 +46,7 @@ const attrs = [ ...@@ -46,6 +46,7 @@ const attrs = [
'scale', 'scale',
'markers', 'markers',
'polyline', 'polyline',
'polygons',
'circles', 'circles',
'controls', 'controls',
'show-location' 'show-location'
...@@ -115,6 +116,12 @@ export default { ...@@ -115,6 +116,12 @@ export default {
return [] return []
} }
}, },
polygons: {
type: Array,
default () {
return []
}
},
controls: { controls: {
type: Array, type: Array,
default () { default () {
...@@ -186,6 +193,9 @@ export default { ...@@ -186,6 +193,9 @@ export default {
}, },
circles (val) { circles (val) {
this.map && this._addMapCircles(val) this.map && this._addMapCircles(val)
},
polygons (val) {
this.map && this._addMapPolygons(val)
} }
}, },
mounted () { mounted () {
...@@ -199,6 +209,7 @@ export default { ...@@ -199,6 +209,7 @@ export default {
map.__markers_map__ = {} map.__markers_map__ = {}
map.__lines__ = [] map.__lines__ = []
map.__circles__ = [] map.__circles__ = []
map.__polygons__ = []
map.setZoom(parseInt(this.scale)) map.setZoom(parseInt(this.scale))
plus.webview.currentWebview().append(map) plus.webview.currentWebview().append(map)
if (this.hidden) { if (this.hidden) {
...@@ -218,6 +229,7 @@ export default { ...@@ -218,6 +229,7 @@ export default {
this._addMarkers(this.markers) this._addMarkers(this.markers)
this._addMapLines(this.polyline) this._addMapLines(this.polyline)
this._addMapCircles(this.circles) this._addMapCircles(this.circles)
this._addMapPolygons(this.polygons)
}) })
}, },
beforeDestroy () { beforeDestroy () {
...@@ -423,6 +435,48 @@ export default { ...@@ -423,6 +435,48 @@ export default {
nativeMap.addOverlay(nativeCircle) nativeMap.addOverlay(nativeCircle)
nativeMap.__circles__.push(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)
})
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册