当我包含以下代码时,没有标记出现,并且控制台中的错误是:


  未捕获的TypeError:this.callInitHooks不是pointToLayer上的函数。


如果您知道任何解决方案,请分享。

var map = L.map('map', {
            center: [53.423933, -7.94069],
            zoom: 7,
            layers: [grayscale]
        });

var url = "howdy.json";

var geojsonMarkerOptions = L.icon({
            iconUrl: 'howdy.png',
            iconSize:     [16, 28],
            iconAnchor:   [8, 18],
            popupAnchor:  [-3, -13]
        });

function forEachFeature(feature, layer) {

        var popupContent =
        feature.properties.Cabin+
        feature.properties.Crew +
        feature.properties.Mobile;

        if (feature.properties && feature.properties.popupContent) {
            popupContent += feature.properties.popupContent;
        }
            layer.bindPopup(popupContent);
        };

      var howdy = L.geoJSON(null, {
        onEachFeature: forEachFeature,
        pointToLayer: function (feature, latlng) {
            return L.Marker(latlng, geojsonMarkerOptions);
        }
  });

$.getJSON(url, function(data) {
        Shelter.addData(data);
});

Shelter.addTo(map);

最佳答案

该错误很可能是由您的行引起的:

return L.Marker(latlng, geojsonMarkerOptions);


...您尝试实例化调用L.Marker类构造函数的Leaflet Marker,而没有触发实例化的new JavaScript关键字。

请注意与Leaflet提供的工厂L.marker(小写首字母m)不同,后者只是new L.Marker的别名。

关于javascript - 如何在L.geoJSON pointToLayer中实例化Marker,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50420327/

10-12 13:56