Javascript 为什么传单.LayerGroup.Collision不能与我的L.GeoJSON一起使用?
正在尝试使用插件Javascript 为什么传单.LayerGroup.Collision不能与我的L.GeoJSON一起使用?,javascript,text,leaflet,collision-detection,Javascript,Text,Leaflet,Collision Detection,正在尝试使用插件“传单.LayerGroup.Collision.js”。我看不出错误是什么,因为它应该在发生冲突时隐藏文本。所有文本都显示出来了,但仍然相互碰撞,在地图上看起来相当混乱 以下示例中可能有什么错误?我试着尽可能地按照说明去做,但似乎少了一些东西 var point_txt = new L.layerGroup(); function filt_point(feature) { if (feature.properties.size === "villages") retur
“传单.LayerGroup.Collision.js”
。我看不出错误是什么,因为它应该在发生冲突时隐藏文本。所有文本都显示出来了,但仍然相互碰撞,在地图上看起来相当混乱
以下示例中可能有什么错误?我试着尽可能地按照说明去做,但似乎少了一些东西
var point_txt = new L.layerGroup();
function filt_point(feature) {
if (feature.properties.size === "villages") return true;
}
var collisionLayer = L.LayerGroup.collision({ margin: 8 });
$.getJSON("/data/city_villages.geojson", function(json) {
var pointLayer = L.geoJSON.collision(null, {
filter: filt_point,
pointToLayer: function(feature, latlng) {
label = String(('<span class="textLabelclassmall">' + feature.properties.Namn + '</span>');
return new L.marker(latlng, {
icon: createLabelIcon("textLabelclasssmall", label)
});
}
});
var createLabelIcon = function(labelClass, labelText) {
return L.divIcon({
className: labelClass,
html: labelText
});
};
pointLayer.addData(json);
collisionLayer.addLayer(pointLayer);
collisionLayer.addTo(point_txt);
});
传单.LayerGroup.Collision的实例
期望添加到自身的层是L.Markers
,而不是L.LayerGroup的实例
(或派生类的实例,如L.GeoJSON
)-它根本没有为该用例做好准备
在创建它们时添加单个标记,或者考虑使用<代码> L.Gejson。碰撞< /代码>。
< P>我认为在样式中使用“代码”>背景颜色< /代码>。我已经更新了上述代码的工作解决方案。很抱歉,您能否给我更多提示,比如如何编写上述代码,我尝试更改为pointLayer=L.GeoJSON.Collision(空…
但这不起作用…实际上它在一定程度上起作用,但在更改为后仍有大量冲突文本。冲突
并仔细查看。但它与演示站点不太接近。我正在寻找类似的效果…可能需要补充的是,我没有使用任何背景或边框CSS中的文本。我使用开发工具在演示中测试并删除了文本,并且似乎仍然可以工作,我想这应该不是一个问题。。。。
.textLabelclassmall{
left: 1px;
top: -10px;
background-color: transparent;
display: inline-block;
text-align: left;
white-space:nowrap;
letter-spacing: 0.1em;
font-weight: 500;
font-size: 0.5vw;
}