Javascript 删除传单divIcon“;点“;当图标大小设置为0,0时
我有以下资料:Javascript 删除传单divIcon“;点“;当图标大小设置为0,0时,javascript,jquery,html,css,leaflet,Javascript,Jquery,Html,Css,Leaflet,我有以下资料: var myLatLng = new L.LatLng(lat, lng); var labelIcon = L.divIcon( { iconSize: [0, 0], html: "<div style='font-family:arial; margin-left:0px; margin-top:0px; font-size:" + fontSize + "px;'>" + labelText + "</div>
var myLatLng = new L.LatLng(lat, lng);
var labelIcon = L.divIcon(
{
iconSize: [0, 0],
html: "<div style='font-family:arial; margin-left:0px; margin-top:0px; font-size:" + fontSize + "px;'>" + labelText + "</div>"
});
var myMarker = L.marker(myLatLng, { icon: labelIcon, riseOnHover: false, draggable: true, ID: labelID });
var mylatng=新的拉特液化天然气(拉特,液化天然气);
var labelIcon=L.divIcon(
{
iconSize:[0,0],
html:“+labelText+”
});
var myMarker=L.marker(myLatLng,{icon:labelIcon,riseonhaver:false,draggable:true,ID:labelID});
当它出现在我的地图上时,我会在div中显示文本,但我认为,这个小点是由图标大小为0,0产生的。我试图设置div的不透明度,但这并不影响图标的不透明度。有没有办法消除或隐藏标记留下的“点”?
iconSize
对于创建divIcon
不是必需的。您可以传入一个className
,然后通过CSS设置大小。这里是传单文档的链接,这里是代码片段<代码>标签就是我用它创建的geoJSON。我将geoJSON保存到一个变量中,稍后对该变量进行迭代并添加到map
,这是一个传单映射
var labels = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Juneau"
},
"geometry": {
"type": "Point",
"coordinates": [
-134.42115783691406,
58.30209338988363
]
}
},
{
"type": "Feature",
"properties": {
"name": "Fort Yukon"
},
"geometry": {
"type": "Point",
"coordinates": [
-145.27410507202148,
66.5648589947054
]
}
}
};
labels.features.forEach(function(feature) {
return L.marker(
[feature.geometry.coordinates[1], feature.geometry.coordinates[0]], {
icon: L.divIcon({
className: 'label',
html: feature.properties.name
})
}).addTo(map);
});
另外,这里是我最近用来设计地图样式的CSS。您需要将光标更改为inherit
,这样它就不会变成指针。文本阴影
为文本提供浅黑色轮廓,使标签在地图上更可见
.label {
font-family: 'IM Fell DW Pica', serif;
color: #fec623;
font-size: 150%;
line-height: 20px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
cursor: inherit;
}
请制作一个JSFIDLE,以便我们能更好地帮助您。请看这里: