繁体   English   中英

GeoJson渲染正确,但没有要求的颜色

[英]GeoJson is rendered correctly but without the requested color

我有以下方法“ ajax_geojson”,它会生成geo json:

    geo_json = [ {"type": "Feature",
                    "properties": {
                        "id":  c_name,
                        "marker-color": "#f80530",
                        "marker-size": "medium",
                        "marker-symbol": "",
                        "popupContent":  content , 
                        }, 
                    "geometry": {
                        "type": "Point",
                        "coordinates": [lon, lat] }}
                    for c_name,content, lon,lat in zip(country_name, content, longtitude, latitude) ]     

   return JsonResponse(geo_json, safe=False)  

javascript使用jQuery呈现此代码:

              $.ajax({
                url: '/research/ajax_geojson',
                success: function (collection) 
                {                           
                   L.geoJson(collection, {onEachFeature: onEachFeature}).addTo(map);

                   function onEachFeature(feature, layer) 
                   {
                        if (feature.properties && feature.properties.popupContent) 
                        {
                            layer.bindPopup(feature.properties.popupContent); 
                        }  
                    }                       

                }
        }); 

虽然标记是根据要求在地图上精确显示的,但颜色似乎没有任何作用(#f80530为红色)

我的问题:是否需要在layer.bindPopup下的javascript中添加任何内容? 我的印象是,在geo_json中定义颜色应该在地图中显示。 我在这里想念什么?

在此处输入图片说明

尝试在geo_json设置对象中的“几何”之后添加“样式”对象:

    geo_json = [ {"type": "Feature",
                    "properties": {
                        "id":  c_name,
                        "marker-color": "#f80530",
                        "marker-size": "medium",
                        "marker-symbol": "",
                        "popupContent":  content , 
                        }, 
                    "geometry": {
                        "type": "Point",
                        "coordinates": [lon, lat] },
                    "style":{
                      //all SVG styles allowed
                      "fill":"red",
                      "stroke-width":"3",
                      "fill-opacity":0.6 }}
                    for c_name,content, lon,lat in zip(country_name, content, longtitude, latitude) ]     

   return JsonResponse(geo_json, safe=False)  

暂无
暂无

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

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