0

我在 django 3 和 ol6 中有一个 webapp。

我的views.py是这样的

   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) 

我的openlayer代码是:

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);
  });
 }
}

视图highlightboundary将数据返回给上述post函数。但我的问题是多边形(多多边形)没有突出显示或颜色没有填充在多边形内。如果它是一个点场,它工作正常。我的代码有什么问题。

我收到错误

未捕获的类型错误:f.getLayout 不是函数 MultiPolygon.js:94:27

4

0 回答 0