2017-09-25 79 views
1

如何將geoJson數據(超過2000個座標)導入到小冊子地圖中? 這是地緣JSON的短樣品從geojson數據在小冊子地圖上繪製標記

{ 
    "type": "FeatureCollection", 
    "features": [ 
    { 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 44.8242557024,20.4048512901 ] 
    }, 
    "properties": { 
    } 
    }, 
    { 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 44.8242557024,20.4048512901 ] 
    }, 
    "properties": { 
    } 
    },...] 

代碼我已經試過:

<!doctype html> 
<html> 
<head> 
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" /> 
    <!--[if lte IE 8]> 
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.ie.css" /> 
    <![endif]--> 
    <style type="text/css"> 
    body { 
     padding: 0; 
     margin: 0; 
    } 

    html, body, #cmap { 
     height: 100%; 
    } 

    </style> 
    <script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script> 
    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> 
</head> 
<body> 
    <div id="cmap"></div> 
    <script> 
    var cupcakeTiles = L.tileLayer('https://api.mapbox.com/v4/mapbox.emerald/page.html?access_token=cj5h2mqa63sc92srx3bu62e2j', { 
    maxZoom: 18 
    }); 

    $.getJSON("convertcsv.geojson", function(data) { 
    var geojson = L.geoJson(data, { 
     onEachFeature: function (feature, layer) { 
     layer.bindPopup(feature.properties.name);cj5h2mqa63sc92srx3bu62e2j 
     } 
    }); 

var map = L.map('map', { 
    center: [44, 20], 
    zoom: 7 
}); 

L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {  
    id: 'examples.map-20v6611k' 
}).addTo(map); 

new L.GeoJSON(meta1nJson).addTo(map); 
    }); 
    </script> 
</body> 
</html> 

但什麼也沒有發生,它只是一個灰色背景。我不確定錯誤在哪裏(可能有多個),但可能導入geojson數據和地圖標記時出錯。 我完全是初學者。預先感謝。

回答

1

您似乎必須在代碼中遇到很多問題。首先,id爲'map'的元素不存在於您的html中,因此無法放置地圖圖層。你必須在下面的代碼中添加'cmap'作爲id。

var map = L.map('cmap', { 
    center: [44, 20], 
    zoom: 7 
}); 

而且meta1nJson似乎並沒有在你的代碼中定義,所以下面的代碼是行不通的。

new L.GeoJSON(meta1nJson).addTo(map); 

cupcakeTiles似乎被定義,但從未添加到地圖。在下面的代碼中還應該刪除一個流浪字符串。

$.getJSON("convertcsv.geojson", function(data) { 
var geojson = L.geoJson(data, { 
    onEachFeature: function (feature, layer) { 
    layer.bindPopup(feature.properties.name); //cj5h2mqa63sc92srx3bu62e2j 
    } 
}); 
相關問題