Leaflet 传单绘制多边形的渲染不正确
我有以下多边形: {“类型”:“多边形”,“坐标”:[[-95.1470947265625,42.2685019842801],-94.9493408203125,42.2400409352592],-94.866943359375,42.3213241404624],-95.0372314453125,42.4349444401055],-95.1470947265625,42.2685019842801]] 此多边形在中正确渲染。但是当我在我的页面上呈现它时,它看起来是这样的 以下是用于渲染此对象的完整代码:Leaflet 传单绘制多边形的渲染不正确,leaflet,geojson,mapbox,Leaflet,Geojson,Mapbox,我有以下多边形: {“类型”:“多边形”,“坐标”:[[-95.1470947265625,42.2685019842801],-94.9493408203125,42.2400409352592],-94.866943359375,42.3213241404624],-95.0372314453125,42.4349444401055],-95.1470947265625,42.2685019842801]] 此多边形在中正确渲染。但是当我在我的页面上呈现它时,它看起来是这样的 以下是用于渲
var geometry = {"type":"Polygon","coordinates":[[[-95.1470947265625,42.2685019842801], [-94.9493408203125,42.2400409352592],[-94.866943359375,42.3213241404624],[-95.0372314453125,42.4349444401055],[-95.1470947265625,42.2685019842801]]]};
var mmp_polygon = geometry;
geometry.crs = {"type": "name", "properties": {"name": "EPSG:4326"}};
$('#feeding_operation_map_coords_as_geojson').val(JSON.stringify(geometry));
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
.setView([41.9022517010637, -93.7140816297676], 8);
var featureGroup = L.featureGroup().addTo(map);
var drawControl = new L.Control.Draw({
draw: {
marker: false,
rectangle: false,
polyline: false,
circle: false
},
edit: {
featureGroup: featureGroup
}
}).addTo(map);
var line_points = mmp_polygon.coordinates[0];
// Mapbox wants lat and long swapped
line_points.forEach(function (entry) {
entry.reverse();
});
// Define polyline options
// http://leafletjs.com/reference.html#polyline
var polyline_options = {
color: '#000'
};
// Defining a polygon here instead of a polyline will connect the
// endpoints and fill the path.
// http://leafletjs.com/reference.html#polygon
var polygon = L.polygon(line_points, polyline_options).addTo(featureGroup);
bounds = featureGroup.getBounds();
console.log("bounds");
console.log(JSON.stringify(bounds));
map.fitBounds(bounds, {padding: [50, 50]})
加载地图后,
setView
会导致加载一组与fitBounds
不同的磁贴。我注释掉了setView
,并获得了要加载的正确的磁贴。这里有一个关于我的编辑的例子
GeoJSONLint输出看起来与您发布的图像相同。输出应该是什么样子的?GeoJSONLint版本显示正确的背景平铺,而我的版本不显示。