gpt4 book ai didi

javascript - 根据 geojson 数据在传单 map 上绘制标记

转载 作者:行者123 更新时间:2023-11-30 21:08:19 24 4
gpt4 key购买 nike

如何将geoJson数据(超过2000个坐标)导入传单 map ?这是 geo json 的简短示例

{
"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 数据和 map token 时出错。我完全是初学者。预先感谢。

最佳答案

您的代码中似乎有很多问题。首先,您的 html 中不存在 ID 为“map”的元素,因此无法放置 map 图层。您必须在以下代码中添加“cmap”作为 id。

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

此外,您的代码中似乎没有定义 meta1nJson,因此下面的代码无法运行。

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

cupcakeTiles 似乎已定义,但从未添加到 map 中。您在下面的代码中还有一个杂散字符串,应该将其删除。

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

关于javascript - 根据 geojson 数据在传单 map 上绘制标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46401877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com