.json
矢量层到传单.js地图,
viewable here via GitHub page
source code here
下面是该文件的一个简短版本供参考(上面链接的GitHub页面显示它在上下文中工作)。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- LEAFLET-->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
#map {
width: 600px;
height: 600px;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
var map = L.map('map').setView([-7.08, -78.5565467], 12);
let osmLayer = L.tileLayer('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}@2x.png', {
attribution: 'Wikimedia maps beta | © <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
let marker = L.marker([-7.2861634, -78.579712])
.addTo(map);
let marker2 = L.marker([-7.1605494, -78.5392218])
.addTo(map);
///let test_L = L.geoJSON("test.json", {
///weight: 2,
/// color: '#100'
///}).addTo(map);
//let layerGroup = L.geoJSON(watersheds, {
// onEachFeature: function (feature, layer) {
//layer.bindPopup('</h1><p>name: '+feature.properties.WTSHNAME+'</p>');
// }
// }).addTo(map);
//street layer using mapbox basic
// Changed to OSM just to avoid the token requirement, for the purpose of demo.
var mapboxbasic = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
zIndex: 1
});
//aerial layer using mapbox satellite
// Changed to OSM just to avoid the token requirement, for the purpose of demo.
var mapboxsat = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
zIndex: 2
});
var Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
});
var basemap = {
'Streets': mapboxbasic,
'Aerials': mapboxsat,
'ESRI Imagery': Esri_WorldImagery
} // Refer to the individual Tile Layers only. They will go into the tilePane.
;
L.control.layers(basemap).addTo(map); // Layers Control just to switch between the 2 basemaps.
</script>
</body>
</html>
.json文件
这个
.json文件
使用调用文件
<script src="test.json" type="text/javascript"></script>
[与
.json文件
hosted on GitHub
]
我试过的代码是:
let test_L = L.geoJSON(test, {
weight: 2,
color: '#100'
}).addTo(map);
遵循官方示例:
https://leafletjs.com/examples/geojson/
以及:
$.getJSON("test.json",function(data){
L.geoJson(data).addTo(newMap);
});
here on StackOverflow
,开
this forum
,并作为模型
with this gist
--一切都无济于事。
很明显我遗漏了什么,但我不明白是什么。
作为比较,我设法
this example working on Observable
.
有人能帮我指出正确的方向吗?我真的很感激!!
提前感谢您的时间和指导,
亚伦