我有一个问题,贴上中心或只是一个多边形,在一般使用传单1.0RC-3。
用于添加多边形并将标记关联的代码im如下
.leaflet-label {
background:none;
left: -22px;
border:none;
background-clip:none;
}
.leaflet-label:before {
border-right: 0px solid black;
border-right-color: inherit;
left: -10px;还有js
var lotss = L.geoJson(lots, {
style: function(feature) {
switch (feature.properties.SOLD) {
case 'Y': return {color: "#FF0000", weight:1};
}
switch (feature.properties.TYPE) {
case 'EASEMENT': return {color: "#FFFFFF", weight:1};
case 'LOT': return {color: "#00FF00", weight:1};
case 'ROAD': return {color: "#000000", weight:1};
}
}
}).addTo(map);
var label = new L.Label()
label.setContent("test")
label.setLatLng(lotss.getBounds().getCenter())
map.showLabel(label);但它似乎不起作用,我能真正看到的唯一引用是上面提到的标签代码。我做错了吗?这是一系列的包裹批次,我正试着让它给中间的批号贴上标签。
谢谢你的建议
发布于 2016-11-19 15:35:10
正如@chrki所评论的,您使用的是插件(因为L.Label不在传单代码中)
如果您使用的是https://github.com/Leaflet/Leaflet.label,您必须知道传单1.0不推荐使用
使用传单1.0,您必须使用工具提示。
map.openTooltip("test", geojsonLayer.getBounds().getCenter());下面是一个例子:https://yafred.github.io/ajax-geojson-and-labels/index4.html
如果您不喜欢工具提示的外观,可以使用带有L.DivIcon的标记来探索解决方案
L.marker(lotss.getBounds().getCenter(), {
icon: new L.DivIcon({
className: 'my-div-icon',
html: '<h2>There are n lots here</h2>'
})
}).addTo(map);

https://stackoverflow.com/questions/40689694
复制相似问题