我想将geoJSON(多边形)文件加载到我的传单地图中。我已经看到了将geoJSON嵌入到javascript代码中的示例,但是找不到任何示例来说明如何使用外部文件来完成它。
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="usStates.geojson" type="text/javascript"></script>
<style>
html, body, #map {
height: 100%;
}
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map" style="height: 100%"</div>
<script src="http://d3js.org/d3.v2.min.js?2.9.3"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script type="text/javascript">
var map = L.map('map').setView([38.57, -94.71], 4);
L.tileLayer('http://{s}.tile.cloudmade.com/9067860284bc491e92d2342cc51d47d9/998/256/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> Imagery © <a href="http://cloudmade.com">CloudMade</a>'}).addTo(map);
var featureStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.2
};
L.geoJson(usStates).addTo(map);
</script>
</body>
将geojson拖放到geojson.io
—
Mapperz
@ Mapperz,OP并未询问如何将其geojson内容粘贴到脚本中。
—
Dave-Evans