Javascript GeoJson已正确呈现,但没有请求的颜色
我有以下方法“ajax\u geojson”生成geo-json:Javascript GeoJson已正确呈现,但没有请求的颜色,javascript,jquery,django,leaflet,geojson,Javascript,Jquery,Django,Leaflet,Geojson,我有以下方法“ajax\u geojson”生成geo-json: geo_json = [ {"type": "Feature", "properties": { "id": c_name, "marker-color": "#f80530", "marker-size": "medium",
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.bindpoop下有什么需要添加到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)
不。我以前尝试过这种风格。我没有做这个把戏:-(