3D Extrusion with mapbox based on local geojson file

后端 未结 1 895
后悔当初
后悔当初 2021-01-06 19:03

I have seen this example online which does data-driven building extrusion but doesn\'t provide the code at all.

I would very much like to achieve the same thing. I h

相关标签:
1条回答
  • 2021-01-06 19:37

    Since you added a remote geojson file, you need to change the checks and the way you get and process the data:

      map.on('sourcedata', function(e) {
    
        // if (e.sourceId !== 'total') return
        if (e.sourceId !== 'data') return
        if (e.isSourceLoaded !== true) return
    
        var data = {
          "type": "FeatureCollection",
          "features": []
        }
    
        // e.source.data.features.forEach(function(f) {
        map.querySourceFeatures('data').forEach(function(f) {
          var object = turf.centerOfMass(f)
          var center = object.geometry.coordinates
          var radius = 10;
          var options = {
            steps: 16,
            units: 'meters',
            properties: object.properties
          };
          data.features.push(turf.circle(center, radius, options))
        })
        map.getSource('extrusion').setData(data);
      })
    

    [ https://jsfiddle.net/vd2crsob/ ]

    0 讨论(0)
提交回复
热议问题