lj_zhgd-app/node_modules/vue-baidu-map/components/overlays/Polygon.vue

106 lines
2.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
import commonMixin from '../base/mixins/common.js'
import bindEvents from '../base/bindEvent.js'
import {createPoint} from '../base/factory.js'
export default {
name: 'bm-polygon',
render () {},
mixins: [commonMixin('overlay')],
props: {
path: {
type: Array,
default () {
return []
}
},
strokeColor: {
type: String
},
strokeWeight: {
type: Number
},
strokeOpacity: {
type: Number
},
strokeStyle: {
type: String
},
fillColor: {
type: String
},
fillOpacity: {
type: Number
},
massClear: {
type: Boolean,
default: true
},
clicking: {
type: Boolean,
default: true
},
editing: {
type: Boolean,
default: false
}
},
watch: {
path: {
handler (val, oldVal) {
this.reload()
},
deep: true
},
strokeColor (val) {
this.originInstance.setStrokeColor(val)
},
strokeOpacity (val) {
this.originInstance.setStrokeOpacity(val)
},
strokeWeight (val) {
this.originInstance.setStrokeWeight(val)
},
strokeStyle (val) {
this.originInstance.setStrokeStyle(val)
},
fillColor (val) {
this.originInstance.setFillColor(val)
},
fillOpacity (val) {
this.originInstance.setFillOpacity(val)
},
editing (val) {
val ? this.originInstance.enableEditing() : this.originInstance.disableEditing()
},
massClear (val) {
val ? this.originInstance.enableMassClear() : this.originInstance.disableMassClear()
},
clicking (val) {
this.reload()
}
},
methods: {
load () {
const {BMap, map, path, strokeColor, strokeWeight, strokeOpacity, strokeStyle, fillColor, fillOpacity, editing, massClear, clicking} = this
const overlay = new BMap.Polygon(path.map(item => createPoint(BMap, {lng: item.lng, lat: item.lat})), {
strokeColor,
strokeWeight,
strokeOpacity,
strokeStyle,
fillColor,
fillOpacity,
// enableEditing: editing,
enableMassClear: massClear,
enableClicking: clicking
})
this.originInstance = overlay
map.addOverlay(overlay)
bindEvents.call(this, overlay)
// 这里有一个诡异的bug直接给 editing 赋值时会出现未知错误,因为使用下面的方法抹平。
editing ? overlay.enableEditing() : overlay.disableEditing()
}
}
}
</script>