我一直在尝试在 Leaflet 地图上添加一个多边形并给它一个样式。我一直在关注他们在http://leafletjs.com/examples/geojson.html上的教程,但是没有成功。
我的代码如下:
var myStyle = {
"color": "#0000FF",
"fill": true,
"opacity": 0.65
};
var myPolygon = [{
"type": "Feature",
"properties": {
"name": "Poly test",
"popupContent": "this is my test!",
},
"geometry": {
"type": "Polygon",
"coordinates": [[
[6.0, 52], // top right
[5.9, 52], // top left
[5.9, 51.5], // bottom left
[6.0, 51.5]
]]
}
}];
// Create a map with standard location
map = L.map('map').setView([52.2, 6.5], 9);
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osm = new L.TileLayer(osmUrl, {minZoom: 3, maxZoom: 14});
// Ask the user to get their current location
map.locate({setView : true});
// Add the tilelayer to the map
map.addLayer(osm);
L.geoJson(myPolygon, {
style: myStyle
}).addTo(map);
// Add event listeners
map.on('locationfound', myMarker);
绘制多边形外线,但使用标准蓝色。有人可以为我指出如何正确执行此操作的正确解决方案吗?
谢谢!