微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 ol 6 中的 geojson 数据填充/突出显示多面体?

如何解决如何使用 ol 6 中的 geojson 数据填充/突出显示多面体?

我在 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,0.6))',opacity: 0.5,});
     map.addLayer(dist_highlt);
  });
 }
}

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

我收到错误

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。