I have a webapp in django 3 & ol6.
My views.py is like this
def highlightboundary(request):
searchArr = []
output = {}
dist = District.objects.filter(created_on__year__in=[2020,2021])
for d in dist:
searchArr.append({'type': 'Feature',
'properties': {'id': d.id, 'code': d.code},
'geometry': {'type': d.the_geom.geom_type, 'coordinates': d.the_geom.geojson}})
output = {'type': 'FeatureCollection', 'features': searchArr}
return JsonResponse(output)
And my openlayer code is:
window.highltSubmit = function highltSubmit(event) {
$.post('/webapp/highlight/',function(data){ //Returns data from the above view
dist_highlt = new VectorLayer({
title:'Boundary Highlight',
source: new VectorSource({
features: new GeoJSON().readFeatures(data, {
dataProjection: 'EPSG:32643',
featureProjection: 'EPSG:32643',
}),
}),
style: new Style({
stroke: new Stroke({
color: '#319FD3',
width: 2,
}),
fill: new Fill({
color: 'rgba(255, 255, 255, 0.6))',
}),
}),
opacity: 0.5,
});
map.addLayer(dist_highlt);
});
}
}
The view highlightboundary return data to the above post function. But my problem is the polygon(multipolygon) is not hightlighting or color is not filling inside the polygon. if its a point field,it works fine. Whats wrong in my code.
And I am getting error
Uncaught TypeError: f.getLayout is not a function MultiPolygon.js:94:27