mapbox gl fill-extrusion-height-transition不起作用

时间:2018-06-29 16:00:30

标签: mapbox mapbox-gl-js

我一直在尝试在过渡中使用fill-extrusion-height,但似乎没有用。其他过渡(例如fill-extrusion-height-opacity)正在运行。

有人反对吗或有任何想法?我已经解决了mapbox gl的github问题,它确认了挤出高度应该是可转换的

这里发生的事的示例:https://jsfiddle.net/xpvt214o/331073/

mapboxgl.accessToken = 'pk.eyJ1IjoidGFkaXJhbWFuIiwiYSI6IktzUnNGa28ifQ.PY_hnRMhS94SZmIR2AIgug';
var map = new mapboxgl.Map({
    style: 'mapbox://styles/mapbox/light-v9',
    center: [-74.0066, 40.7135],
    zoom: 15.5,
    pitch: 45,
    bearing: -17.6,
    container: 'map'
});

$('button').click(function() {
map.setPaintProperty('3d-buildings', 'fill-extrusion-height', 75);
})

// The 'building' layer in the mapbox-streets vector source contains building-height
// data from OpenStreetMap.
map.on('load', function () {
    // Insert the layer beneath any symbol layer.
    var layers = map.getStyle().layers;

    var labelLayerId;
    for (var i = 0; i < layers.length; i++) {
        if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
            labelLayerId = layers[i].id;
            break;
        }
    }

    map.addLayer({
        'id': '3d-buildings',
        'source': 'composite',
        'source-layer': 'building',
        'filter': ['==', 'extrude', 'true'],
        'type': 'fill-extrusion',
        'minzoom': 15,
        'paint': {
            'fill-extrusion-color': '#aaa',

            // use an 'interpolate' expression to add a smooth transition effect to the
            // buildings as the user zooms in
            'fill-extrusion-height': [
                "interpolate", ["linear"], ["zoom"],
                15, 0,
                15.05, ["get", "height"]
            ],
            'fill-extrusion-base': [
                "interpolate", ["linear"], ["zoom"],
                15, 0,
                15.05, ["get", "min_height"]
            ],
            'fill-extrusion-height-transition':{
                duration: 2000,
                delay: 0
            },
            'fill-extrusion-opacity': .6
        }
    }, labelLayerId);
});

1 个答案:

答案 0 :(得分:2)

我认为效果很好。您的示例是从数据驱动的属性切换为常量,并且那个似乎是不可转换的。但是从一个常量过渡到另一个常量是可行的,如您在代码的此稍作调整的版本中所见:

https://jsfiddle.net/tyf76u0d/2/

 $('button').click(function() {

        map.setPaintProperty('3d-buildings', 'fill-extrusion-height', Math.random()*250 + 50);

    })