Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "venus-map", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "tq-fed-map", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
@@ -19,2 +19,12 @@ import Vector from 'ol/source/Vector' | ||
const DEFAULT_TEXT_STYLE = { | ||
offset: [0, -20], | ||
color: '#000', | ||
font: '14px sans-serif', | ||
} | ||
const DEFAULT_TEXT_RENDER = feature => { | ||
const { _exData = { name: 'test' }} = feature | ||
return _exData.name | ||
} | ||
export default class MarkerLayer extends EventBus { | ||
@@ -34,4 +44,6 @@ constructor(map, opt = {}) { | ||
initOption(option) { | ||
const { icon } = option | ||
const { icon, text, render } = option | ||
this.iconStyle = Object.assign({}, icon, DEFAULT_ICON_STYLE) | ||
this.textStyle = Object.assign({}, text, DEFAULT_TEXT_STYLE) | ||
this.textRender = render || DEFAULT_TEXT_RENDER | ||
this.defaultFeatureStyle = this.getFeatureStyle(this.iconStyle) | ||
@@ -100,3 +112,3 @@ this.selector = {} | ||
*/ | ||
getFeatureStyle(icon) { | ||
getFeatureStyle(icon, text, render) { | ||
const img = new Image() | ||
@@ -111,2 +123,12 @@ img.src = icon.src | ||
}), | ||
text: new Text({ | ||
text: render ? render(feature) : feature.get('features').length.toString(), | ||
placement: 'point', | ||
offsetX: text.offset[0], | ||
offsetY: text.offset[1], | ||
font: text.font, | ||
fill: new Fill({ | ||
color: text.color, | ||
}), | ||
}), | ||
}) | ||
@@ -121,5 +143,7 @@ } | ||
updateStyle(opt) { | ||
const { icon = {}} = opt | ||
const { icon = {}, text = {}, render } = opt | ||
this.iconStyle = Object.assign({}, this.iconStyle, icon) | ||
this.layer.setStyle(this.getFeatureStyle(this.iconStyle)) | ||
this.textStyle = Object.assign({}, this.textStyle, text) | ||
this.textRender = render || this.textRender | ||
this.layer.setStyle(this.getFeatureStyle(this.iconStyle, this.textStyle, this.textRender)) | ||
} | ||
@@ -136,3 +160,3 @@ | ||
hoverHandler(style = {}) { | ||
const { icon = {}} = style | ||
const { icon = {}, text = {}, render } = style | ||
const selectListener = new Select({ | ||
@@ -142,3 +166,5 @@ condition: condition.pointerMove, | ||
style: this.getFeatureStyle( | ||
Object.assign({}, this.iconStyle, icon) | ||
Object.assign({}, this.iconStyle, icon), | ||
Object.assign({}, this.textStyle, text), | ||
render ? render : this.textRender | ||
), | ||
@@ -179,3 +205,3 @@ }) | ||
clickHandler(style = {}) { | ||
const { icon = {}} = style | ||
const { icon = {}, text = {}, render } = style | ||
const selectListener = new Select({ | ||
@@ -185,3 +211,5 @@ condition: condition.click, | ||
style: this.getFeatureStyle( | ||
Object.assign({}, this.iconStyle, icon) | ||
Object.assign({}, this.iconStyle, icon), | ||
Object.assign({}, this.textStyle, text), | ||
render || this.textRender | ||
), | ||
@@ -188,0 +216,0 @@ }) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3035848
4097