Javascript 如何更改传单中的标记颜色?
我有一个在谷歌地图上有效的方法,但在传单上不起作用。我在下图中显示了返回的方法: 我想用我的方法改变颜色。现在我有了一个默认图标Javascript 如何更改传单中的标记颜色?,javascript,angular,typescript,leaflet,Javascript,Angular,Typescript,Leaflet,我有一个在谷歌地图上有效的方法,但在传单上不起作用。我在下图中显示了返回的方法: 我想用我的方法改变颜色。现在我有了一个默认图标 private getMarkerIcon(marker: OpMarker): any { if (marker.iconImage) { if (marker.iconImage.indexOf('data:image/') > -1) return marker.iconImage
private getMarkerIcon(marker: OpMarker): any {
if (marker.iconImage) {
if (marker.iconImage.indexOf('data:image/') > -1)
return marker.iconImage
return 'data:image/*;base64,' + marker.iconImage
}
else if (marker.iconURL) {
return marker.iconURL
}
else {
let iconConfig: any = null
if (this.$scope.options.defaultMarkerIconOptions != null) {
iconConfig = _.clone(this.$scope.options.defaultMarkerIconOptions)
let color: string = null
if (marker.fillColor) {
color = marker.fillColor
//TODO: add alpha (opacity)
if (color.charAt(0) === '#') {
color = color.replace('#', '').slice(0, 6)
}
if (color.length > 6) {
color = color.slice(0, 6)
console.warn('Colors in the RGBA model are not supported!')
}
}
if (color != null) {
iconConfig.fillColor = `#${color}`
}
}
return iconConfig
}
}
我的方法是创建一个新的标记
const icon: any = this.getMarkerIcon(marker)
if (icon == null) {
console.warn(StreetMapProvider.LOG_STRING, "No default marker icon options. Using the default leaflet maps one.")
}
let mapMarker: any = new L.marker([marker.coords.latitude, marker.coords.longitude], {iconUrl: icon})
给你的图标分类并改变它的风格
marker._icon.classList.add("yourclass");
给你的图标分类并改变它的风格
marker._icon.classList.add("yourclass");
可以使用css更改传单标记。我不能使用css,我必须阅读svg并添加图标。在这种情况下,有点难以准确理解问题所在,您能否在stackblitz或类似工具中创建最小复制?这将是一个问题,所以我有一个函数,可以在base64中加载图标并返回路径颜色等。您可以在图片上看到。当我创建标记时,我必须阅读此图标并添加返回我的函数的颜色
getMarkerIcon
您可以使用css更改传单标记。我不能使用css,我必须阅读svg并添加图标。在这种情况下,有点难以准确理解问题所在,您能否在stackblitz或类似工具中创建最小复制?这将是一个问题,所以我有一个函数,可以在base64中加载图标并返回路径颜色等。您可以在图片上看到。当我创建标记时,我必须阅读此图标并添加返回函数的颜色getMarkerIcon