Quiero mostrar los marcadores en diferentes colores basados en los valores de la columna (rastervalues) en el folleto. Mis datos geojson son
{'geojson': "[{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'ge
ometry': {'type': 'Point', 'coordinates': [74.886779, 33.571307]}, 'properties':
{'rastvalues': 9, 'id': 1, 'species': 'Poa pratensis L.'}}, {'type': 'Feature',
'geometry': {'type': 'Point', 'coordinates': [75.015556, 33.588333]}, 'properti
es': {'rastvalues': 9, 'id': 2, 'species': 'Poa pratensis L.'}}, {'type': 'Featu
re', 'geometry': {'type': 'Point', 'coordinates': [75.06231, 33.592838]}, 'prope
rties': {'rastvalues': 9, 'id': 3, 'species': 'Phleum alpinium L.'}}, {'type': '
Feature', 'geometry': {'type': 'Point', 'coordinates': [75.196944, 33.550556]},
'properties': {'rastvalues': 12, 'id': 4, 'species': 'Pinus roxburghii Sargent'}
}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [75.224722,
33.540278]}, 'properties': {'rastvalues': 12, 'id': 5, 'species': 'Pinus roxburg
hii Sargent'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates':
[75.103889, 34.485833]}, 'properties': {'rastvalues': 3, 'id': 6, 'species': 'P
inus roxburghii Sargent'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'c
oordinates': [75.143611, 34.536667]}, 'properties': {'rastvalues': 3, 'id': 7, '
species': 'Phleum alpinium L.'}}, {'type': 'Feature', 'geometry': {'type': 'Poin
t', 'coordinates': [74.329145, 33.818276]}, 'properties': {'rastvalues': 9, 'id'
: 8, 'species': 'Pinus roxburghii Sargent'}}]}]"}
Mi código javacript es
function main_map_init (map, options) {
var promise = $.getJSON('{% url "datapot" %}');
// Download GeoJSON via Ajax
promise.then(function(data) {
var allbusinesses = L.geoJson(data);
var cafes = L.geoJson(data, {
filter: function(feature, layer) {
return feature.properties.rastvalues == "3";
},
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {
}).on('mouseover', function() {
this.bindPopup(feature.properties.species).openPopup();
});
}
});
var others = L.geoJson(data, {
filter: function(feature, layer) {
return feature.properties.rastvalues != "3";
},
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {
}).on('mouseover', function() {
this.bindPopup(feature.properties.species).openPopup();
});
}
});
map.fitBounds(allbusinesses.getBounds(), {
padding: [50, 50]
});
cafes.addTo(map)
others.addTo(map)
});
}
</script>
En el depurador de Chrome, para la línea filter: function(feature, layer) {
Obtengo el siguiente valor
feature = Object {type: "Feature", id: 1,properties: Object, geometry: Object}, layer = undefined
Las propiedades, es decir, las especies y los valores de rastreo, no aparecen.
¿Cómo solucionarlo?
solución es
def extract_raster_points(request):
conn = psycopg2.connect(dbname="geodjango",host='localhost',user='postgres', password='postgres', port=5433)
cur=conn.cursor()
dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
res=dict_cur.execute("""SELECT row_to_json(fc) FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features FROM (SELECT 'Feature' As type, ST_AsGeoJSON(lg.geom)::json As geometry ,row_to_json((SELECT l FROM (SELECT id, species,rastvalues) As l )) As properties FROM pft_account As lg ) As f ) As fc;""")
points=dict_cur.fetchone()
#datapot = json.loads(str(points))
datapot = json.loads(json.dumps(points))
datapotg=datapot[0]
print(datapotg)
return JsonResponse(datapotg,safe=False)