填充拉伸无法使用 mapbox-gl-js 正确显示

fill-extrusion not displaying correctly with mapbox-gl-js

这是我的数据集的样子:

Seattle Crime Dataset

我想做的是根据频率列更改挤压高度。我可以成功地将这些显示为点,但每当我使用填充挤压时,我都会为此苦苦挣扎。你能帮我指出正确的方向吗?

    map.addLayer({
    'id': 'total',
    'type': 'circle',
    'source': {
        type: 'vector',
        url: 'mapbox://askakdagr8.9tklrr8g'
    },
    'source-layer': 'GroupedOutput-9i6ink',
    'paint': {
        // make circles larger as the user zooms from z12 to z22
        'circle-radius': {
            'base': 1.75,
            'stops': [
                [12, 2],
                [22, 180]
            ]
        },
        'circle-color': '#ff7770'
    }
});

由于 mapbox-gl-js 目前没有拉伸圆的功能,您需要用多边形替换点,然后对圆进行插值,例如,通过函数 turf.circle:

  map.on('sourcedata', function(e) {
    if (e.sourceId !== 'total') return
    if (e.isSourceLoaded !== true) return

    var data = {
      "type": "FeatureCollection",
      "features": []
    }
    e.source.data.features.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);
  })

[http://jsfiddle.net/zjLek40n/]