传单:如何在 geojson 图层上使用自定义标记? [英] Leaflet: how to use a custom marker on a geojson layer?
本文介绍了传单:如何在 geojson 图层上使用自定义标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Leaflet 地图上放置一个 geojson,并且在我使用默认的蓝光标记之前一切正常.
I'm trying to put on a Leaflet map a geojson and all works fine until I use the default blu marker.
现在我想使用一个自定义标记(一个小 .png 图标),并在下面更改了我的代码
Now I'd like to use a custom marker (a little .png icon) and I've changed my code in the follow
var my_json;
$.getJSON('../Dati/my-geojson.geojson', function(data) {
my_json = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
var smallIcon = L.Icon({
options: {
iconSize: [27, 27],
iconAnchor: [13, 27],
popupAnchor: [1, -24],
iconUrl: 'icone/chapel-2.png'
}
});
return L.marker(latlng, {icon: smallIcon});
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.ATT1 + '<br />'
+ feature.properties.ATT2);
}
});
my_json.addTo(markers.addTo(map));
TOC.addOverlay(my_json, "My layer name in TOC");
map.removeLayer(my_json);
});
我在 Firebug 中看到的错误是
the error that I can see in Firebug is
TypeError: this.options.icon is undefined
var anchor = L.point(this.options.icon.options.popupAnchor || [0, 0]);
出了点问题,但我不知道如何解决.
something is going wrong but I don't know how to fix it.
任何建议将不胜感激
切萨雷
推荐答案
查看 L.icon 文档:你不需要设置 { options: { ... } }
.只需直接输入选项,就像文档中所说的那样,并在示例中显示.
See the documentation for L.icon: you don't need to set { options: { ... } }
. Just put the options in directly, like it says in the documentation and shows in the example.
这篇关于传单:如何在 geojson 图层上使用自定义标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文