我正在为传单标记使用自定义 divIcon.我想用一些简单的 CSS 为我点击的任何标记添加边框:
I'm using custom divIcons for my Leaflet markers. I want to add a border to whatever marker I click on, with some simple CSS:
.selectedMarker {
border: 10px solid gold;
}
但是,以下 jQuery 不起作用:
However, the following with jQuery doesn't work:
$(marker).addClass('selectedMarker');
然后我尝试使用 Leaflet 自己的 addClass() 方法.我尝试通过以下方式调用使用它:
Then I tried to use Leaflet's own addClass() method. I tried to call use it in the following ways:
marker.addClass('selectedMarker');
L.addClass(marker, 'selectedMarker');
addClass(marker, 'selectedMarker');
DomUtil.addClass(marker, 'selectedMarker');
这些都不起作用.如何将 selectedMarker 类添加到我的标记中?
None of these work. How do I add the selectedMarker class to my marker?
我已经通过在标记中添加一个类来实现
I have done it by adding a class to the marker with
var marker = L.marker(loc);
marker.on('click', function() {
$(marker._icon).addClass('selectedMarker');
}
然后使用css
.leaflet-marker-icon.selectedMarker{
//your css
}
这篇关于如何将类添加到传单标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
检查一个多边形点是否在传单中的另一个内部Check if a polygon point is inside another in leaflet(检查一个多边形点是否在传单中的另一个内部)
更改传单标记群集图标颜色,继承其余默认 CSSChanging leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改传单标记群集图标颜色,继承其余默认
触发点击传单标记Trigger click on leaflet marker(触发点击传单标记)
如何更改 LeafletJS 中的默认加载磁贴颜色?How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默认加载磁贴颜色?)
将外部geojson添加到传单层Add external geojson to leaflet layer(将外部geojson添加到传单层)
将 Leaflet 图层控件添加到侧边栏Adding Leaflet layer control to sidebar(将 Leaflet 图层控件添加到侧边栏)