【发布时间】:2018-01-11 19:09:32
【问题描述】:
我试图在我的地图上显示一些 GeoJSON,但它不起作用。我正在从数据库中提取复杂的多边形,但为了简单起见,我尝试手动构建一个基本多边形。我也无法显示。
我尝试创建一个 zIndex 为 10000 的新窗格并在那里添加图层但无济于事。我尝试交换纬度/经度以防我以某种方式颠倒它们,但这也不起作用。我使用了 10px 的权重来确保不会遗漏。
这是一个基本示例,我只是想将一个多边形将曼哈顿边界添加到地图上。
var mapDivId = 'map';
var leafletMap = L.map(mapDivId,
{'boxZoom': true,
'doubleClickZoom': false,
'scrollWheelZoom': true,
'touchZoom': true,
'zoomControl': true,
'dragging': true});
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
osm.addTo(leafletMap);
var districtOutlineStyle = {
"color": "black",
"weight": "10px",
"opacity": "0.5"
};
var overlaySimplePolygonAroundManhattan = function() {
xmin = 40.68291;
xmax = 40.87903;
ymin = -74.04772;
ymax = -73.90665;
geoJsonShape = {'type': "Polygon",
'coordinates': [[[xmin, ymin], [xmin, ymax], [xmax, ymax], [xmax, ymin], [xmin, ymin]]]};
districtsOverlay = L.geoJSON(geoJsonShape,
{style: districtOutlineStyle});
leafletMap.addLayer(districtsOverlay);
};
overlaySimplePolygonAroundManhattan();
知道为什么它不显示多边形吗?这是传单 1.1.0。
谢谢!
【问题讨论】:
标签: leaflet gis polygon geojson