gpt4 book ai didi

javascript - 传单:geojson 层上的标记图标大小

转载 作者:行者123 更新时间:2023-11-29 19:55:42 24 4
gpt4 key购买 nike

我正在使用 Leaflet 显示 Geojson 层。我想更改默认标记图标大小。

这是我想出的代码:

    $.ajax({
type: "GET",
url: "data.json",
dataType: 'json',
success: function (response) {
geojsonLayer = L.geoJson(response, {
pointToLayer: function(featuer, latlng) {
var smallIcon = L.Icon.extend({
options: {
'iconSize': [10, 10]
}
});
var myIcon = new smallIcon();
return L.marker(latlng, {icon: smallIcon});
},
onEachFeature: onEachFeature
}).addTo(map);
}
});

但是,我在加载页面时遇到 javascript 错误:

Uncaught TypeError: Cannot read property 'popupAnchor' of undefined 

有什么线索吗?

最佳答案

我认为当您扩展 L.Icon 类时,您必须指定 IconUrl,这是指向用于图标的图像文件的链接。请参阅文档:http://leafletjs.com/reference.html#icon

由于 smallIcon 构造函数不满足所有必需的选项,myIcon 将是未定义的。

试试这个:

var myIcon = L.icon({
iconUrl: 'leaflet/images/marker-icon.png',
iconSize: [10,10],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
shadowUrl: 'leaflet/images/marker-shadow.png',
shadowSize: [68, 95],
shadowAnchor: [22, 94]
});

L.marker(latlng, {icon: myIcon}).addTo(map);

关于javascript - 传单:geojson 层上的标记图标大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16168188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com