Mapbox JS,来自URL的GeoJSON featureCollection对象只添加了一个标记

Mapbox JS, GeoJSON featureCollection object from URL only adds one marker

本文关键字:一个 添加 来自 JS URL 对象 featureCollection GeoJSON Mapbox      更新时间:2023-09-26

此映射,http://lastablaslift.es/explorador/,正在通过csv2geojson插件加载一个本地CSV文件,以添加一些带有弹出窗口的标记。

我们正试图将一个URL端点组合在一起,以从mysql DB而不是CSV中获取geoJSON。

这个地图,http://lastablaslift.es/explorador/map_test.php,是相同的,但使用了我们URL中的geoJSON。

我们似乎已经得到了返回正确格式GeoJSON的URL,但正如您所看到的,只有"features"数组中的第一个对象在map_test.php 上呈现

我正在将两个geoJSON对象记录到控制台中,当我比较它们时,它们在我看来是一样的。也没有报告相关的错误,那么我们URL中的geoJSON有什么问题?

请参阅这个JSFiddle示例。我认为会有与function change() {}相关的问题,您将其放置在$.getJSON成功函数中。试着把它放在外面。,您的map_jsonurl.jssholud是这样的

(function() {
    var image = new Image();
    image.onload = function() {
        if (image.width > 0) {
            document.documentElement.className += (document.documentElement.className != '') ? ' images-on' : 'images-on';
        }
    };
    image.src = '/img/px.png';
}());
//toggle the filter menu
/*$("#f_tog").on("click", function(){
    $("#filters").slideToggle();
    $("#f_tog span").toggle();
});*/
// load the map data
$.getJSON("//civicliftmapeurope.azurewebsites.net/api/Listing", function(data) {
    //initialize the map
    var map = L.mapbox.map('map', 'ptw111.lgof8gop')
        .setView([40.5023056, -3.6704803], 14);
    //center marker on click
    map.markerLayer.on('click', function(e) {
        map.panTo(e.layer.getLatLng());
    });
    // Add custom popups to each using our custom feature properties
    map.featureLayer.on('layeradd', function(e) {
        var marker = e.layer,
            feature = marker.feature;
        //string functions, cleaning up geoJSON for display.
        //clean up address
        var addr;
        var zip = feature.properties.zip;
        if (feature.properties.addr) {
            addr = feature.properties.addr + ', ' + zip + '<br>' + feature.properties.city + ', Espa&ntilde;a';
        }
        //check for description
        var desc;
        if (feature.properties.description) {
            desc = feature.properties.description;
        } else {
            desc = '';
        }
        //check for phone numbers
        var phone;
        if (feature.properties.phone) {
            phone = '<strong>' + feature.properties.phone + '</strong>';
        } else {
            phone = '';
        }
        // create custom popup content
        var popupContent = '<div class="tooltip"><h2>' + feature.properties.name + '</h2>' +
            phone +
            '<div class="addr"><p>' +
            addr +
            '</p></div><span>' +
            desc +
            '</span></div>';
        // http://leafletjs.com/reference.html#popup
        marker.bindPopup(popupContent, {
            closeButton: false,
            minWidth: 150,
        });
    });
    // Add features to the map
    map.featureLayer.setGeoJSON(data);
    //filter locations by color/type
    var filters = document.getElementById('filters');
    var checkboxes = document.getElementsByClassName('filter');
    // When the form is touched, re-filter markers
       filters.onchange = change;
    // Initially filter the markers
       change();
});
function change() {
    // Find all checkboxes that are checked and build a list of their values
    var on = [];
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) on.push(checkboxes[i].value);
    }
    // The filter function takes a GeoJSON feature object
    // and returns true to show it or false to hide it.
    map.markerLayer.setFilter(function(f) {
        // check each marker's color to see if its value is in the list
        // of colors that should be on, stored in the 'on' array
        return on.indexOf(f.properties['marker-color']) !== -1;
    });
    return false;
}