Leaflet.Js - MarkerCluster - Popup并不总是显示

时间:2015-08-11 16:18:48

标签: javascript jquery maps leaflet markerclusterer

所以我正在尝试使用Leaflet.js,使用MarkerCluster并让Popups显示。由于某种原因,它似乎是一种冒犯。每次点击都不显示弹出窗口。

这是地图代码:

var map = L.map('map', {
        attributionControl: false,
        zoomControl: false,
        center: [53, -8],
        zoom: 6
    });

    //  Set the title layer
    L.tileLayer('http://{s}.tile.openstreetmap.se/hydda/full/{z}/{x}/{y}.png').addTo(map);

    //  Add the zoom controls to the right side of the map
    new L.Control.Zoom({ position: 'topright' }).addTo(map);

    //  Custom marker icon
    var myIcon = L.icon({
        iconUrl: '../Content/images/macmillan-marker.png',
        iconSize: [30, 36],
        iconAnchor: [15, 36]
    });

    var markers = new L.MarkerClusterGroup();

    var ajax = $.ajax({
        url: '../Scripts/markers.js',
        dataType: 'json',
        success: function (data) {

            var geoLayer = L.geoJson(data, {
                pointToLayer: function (feature, latlng) {
                    return L.marker(latlng, { icon: myIcon });
                },
                onEachFeature: function (feature, layer) {
                    layer.bindPopup('Title');
                }
            });

            markers.addLayer(geoLayer);
        }

    });

    markers.on('click', function () {
        console.log('clicked');
    });

    map.addLayer(markers);

这是markers.js文件:

[{
    "type": "Point",
    "coordinates": [-8, 53]
},
{
    "type": "Point",
    "coordinates": [-10, 53]
},
{
    "type": "Point",
    "coordinates": [-8, 52]
},
{
    "type": "Point",
    "coordinates": [-8, 51]
},
{
    "type": "Point",
    "coordinates": [-8, 54]
},
{
    "type": "Point",
    "coordinates": [-9, 52]
},
{
    "type": "Point",
    "coordinates": [-8, 53]
}]

这些点在地图上显示得很好,并且正在正确聚集,但正如我所说,点击标记时弹出窗口并不总是显示。我做错了吗?

0 个答案:

没有答案