GeoJSON的正确,但不渲染所要求的颜色

问题描述 投票:0回答:1

我有以下方法“ajax_geojson”产生的地理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定义颜色应该提出自己在地图上的印象。我缺少的是在这里吗?

enter image description here

javascript jquery django leaflet geojson
1个回答
0
投票

尝试将“风格”的对象按照你的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)  
© www.soinside.com 2019 - 2024. All rights reserved.