简体   繁体   English

如何根据传单地图中多边形属性中的选项添加图像叠加层?

[英]How can i an add image overlay depending on the options in the polygon properties in a leaflet map?

I have a multi-polygon geojson file ( mapInfo ) that has one of the properties named "field_hazards". 我有一个包含名称为“ field_hazards”的属性之一的多多边形geojson文件(mapInfo)。 The hazards include "gale/storm, heavy rain, thunderstorm and Freezing rain " How can i an add image overlay depending on the field_hazard options? 危险包括“大风/暴风雨,大雨,雷暴和冻雨”,如何根据field_hazard选项添加图像叠加层?

Note the geojson file is got dynamically as a drupal feed. 请注意,geojson文件是作为drupal feed动态获取的。 I have made the following code but it returns an empty map, the polygons are not rendered. 我已经编写了以下代码,但是它返回了一个空的地图,不渲染多边形。

 function getImage(d) {
 return d === 'Freezing Rain' ? "http://mymap:8082/images/weather-images/43n.png" :
        d === 'Thunderstorm' ? "http://mymap:8082/images/weather-images/11.png" :
        d === 'Heavy Rain' ? "http://my:8082/weather-images/02n.png" :
        d === 'Gale\/Storm' ? "http://mymap:8082/images/weather-images/15.png" :
                        "http://my:8082/images/weather-images/09.png";

}
var imageUrl = getImage(feature.properties.field_hazards);
var imageLayer = L.imageOverlay(imageUrl, imageBounds).addTo(map).bringToBack();
var boxOptions = {fillOpacity:0, opacity:0, onEachFeature: onEachBox};
//create the image interaction box
var imageBox = L.geoJson(mapInfo, boxOptions).addTo(map);
//zoom in to fit GeoJSON layer
map.fitBounds(imageBox.getBounds());

I have looked at this example " add image to rect polygon in leaflet ", but it requires me to have the image url preset as a property its self. 我看过这个示例“ 在传单中将图像添加到矩形中 ”,但是它要求我将图像url预先设置为其自身的属性。

I got a solution from this link. 我从此链接获得了解决方案。 Posted it in case some else is interested. 张贴它,以防其他人感兴趣。

Adding image overly in leaflet map from a property 从属性在传单地图中添加图像过多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM