[英]openWeatherMap not displaying leaflet layers & geoJSON
我尝试使用传单地图和 openWeatherAPI 在我的地图上显示圆形和多边形,标记有效,但其他标记无效! 你能帮我找出问题所在吗?
var circle = L.circle([51.508, -0.11], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500 }).addTo(map);
L.geoJSON(circle).addTo(map);
//polygon on map
var polygon = L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.044]
]).addTo(map);
L.geoJSON(polygon).addTo(map);
var geojsonFeature = {
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": [-104.99404, 39.75621]
}
};
L.geoJSON(geojsonFeature).addTo(map);
我也有这个代码并且有效:
var map = L.map('map').setView({ lon: 0, lat: 0 }, 2);
// add the OpenStreetMap tiles
L.tileLayer('http://mt0.google.com/vt/lyrs=p&hl=en&x={x}&y={y}&z={z}&s=Ga', {
maxZoom: 19,
attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
// show the scale bar on the lower left corner
L.control.scale().addTo(map);
map.on('dblclick', function(ev) {
app.request.get('http://api.openweathermap.org/data/2.5/weather', { appid: '38e6ae7b7f30d96079f5e8a9df837472', lon:''+ev.latlng.lng ,lat:''+ev.latlng.lat }, function (data)
{
var JsonWeatherData=JSON.parse(data);
alert(JsonWeatherData.weather[0].description);
});
L.marker({ lon: ev.latlng.lng, lat: ev.latlng.lat }).bindPopup('The center of the world').addTo(map);
});
如果L.geoJSON
组不是 geojson 特征,请不要将这样的图层添加到L.geoJSON
组中。
var circle = L.circle([51.508, -0.11], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500 });
var circleGroup = L.geoJSON().addTo(map)
circleGroup.addLayer(circle);
//polygon on map
var polygon = L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.044]
]);
var polyGroup = L.geoJSON().addTo(map)
polyGroup.addLayer(polygon);
但是,如果您不需要 geoJSON 组中的这些图层,请使用L.featureGroup(circle).addTo(map)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.