我有一个json文件,它接受两个坐标
"_id" : ObjectId("59407457838b932e0677999e"),
"type" : "MultiPoint",
"name" : "points",
"coordinates" : [
[
-73.958,
40.8003
],
[
-73.9814,
40.7681
]
]
我使用传单库来标记Google地图中的坐标,使用节点js和mongo。
我的map.pug文件是
extends layout.pug
block content
#map
script(type='text/javascript').
var map = L.map('map').setView([#{lat},#{lng}], 14);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON('/maplayers',function(result){
$.each(result, function(i, mlayer){
$.getJSON('/mapjson/' + mlayer.name, function(data) { addLayer(data, mlayer.name ) });
});
});
function addLayer(layer, name) {
var leaf_layer;
if (layer.type == "MultiPoint") {
leaf_layer = L.geoJson(layer, { pointToLayer: function (feature, latlng) {return L.circleMarker(latlng, layer.style); }})
leaf_layer.bindPopup(layer.type);
}
leaf_layer.addTo(map);
$('#' + name).click(function(e) {
if (map.hasLayer(leaf_layer)) {
map.removeLayer(leaf_layer);
} else {
map.addLayer(leaf_layer);
}
});
}
这些值与浏览器(http://localhost:3000/map)中的标记一起显示在地图上。
但是,如果我用一个坐标像下面这样更改Json文件,就不会显示它。
"_id" : ObjectId("594061ea838b932e0677999d"),
"type" : "MultiPoint",
"name" : "points",
"coordinates" : [
-73.958,
40.8003
]
浏览器控制台中的错误为
leaflet.js:6 Uncaught Error: Invalid LatLng object: (NaN, NaN)
有谁能解释一下如何解决这个问题,用一个坐标在地图上显示吗?
发布于 2017-06-14 02:28:27
GeoJSON MultiPoint
几何类型期望coordinates
作为嵌套位置的数组。每个“位置”是一个由2个值组成的数组,即[longitude, latitude]
。(海拔可能在第三位)
如果只提供一个位置,而不是嵌套在父数组中,则您的几何图形不再兼容GeoJSON。
相反,您还应该将几何类型更改为Point
,这确实希望coordinates
作为一个lat位置。
https://stackoverflow.com/questions/44533161
复制相似问题