如何在传单地图上动态填充和打印Geojson图层?

时间:2016-05-27 17:09:46

标签: javascript jquery leaflet geojson

我有一个选择列表,我可以在其中选择要在传单地图上打印的表和属性。现在,当我选择第一个表时,它可以工作并打印到传单地图上。但是当我尝试在选择列表中选择第二个表时,我得到了这个语法错误:

JSON.parse: unexpected character at line 1 column 1 of the JSON data
"geometry": JSON.parse(d[fields.length]) //parse geometry  

这是我的代码:

function mapData(data){

    map.eachLayer(function(layer){
        if (typeof layer._url === "undefined"){
                map.removeLayer(layer);
        }
    });

    geojson = {
        "type": "FeatureCollection",
        "features": []
    };

    var dataArray = data.split(", ;");
    dataArray.pop();

    console.log(geojson);

    dataArray.forEach(function(d){
        d = d.split(", "); 

        var feature = {
            "type": "Feature",
            "properties": {}, //properties object container
            "geometry": JSON.parse(d[fields.length]) //parse geometry
        };      

        for (var i=0; i<fields.length; i++){
            feature.properties[fields[i]] = d[i];
        };

        geojson.features.push(feature);
    });
    window["mapDataLayer"] = L.geoJson(geojson).addTo(map);
};

这是第一个succesvol表的回复:

3, 3, McD, , 6.6668000000000, 53.218000000000, {"type":"Point","coordinates":[6.536668
,53.213000]}, ;

这是第二个表的响应,它不会打印到传单映射并抛出语法错误:

1400, 7, 19610, Centrum, 2413052, {"type":"MultiPolygon","coordinates":[[[[6.57886034312177,53.21809972266,41.2845400022343],[6.55981027443664,53.2275880222527,41.2689223056659],[6.5785471610371,53.2184343360823,41.2839346369728],[6.57886034312177,53.21809972266,41.2845400022343]]]]}, ;

0 个答案:

没有答案