【发布时间】:2020-05-08 12:02:43
【问题描述】:
我正在尝试实现我在搜索条件中选择的建筑物的动态 3D 模型,到目前为止我所做的代码如下。
map.on('load', function () {
// Listen for the `geocoder.input` event that is triggered when a user
// makes a selection
geocoder.on('result', function (ev) {
debugger;
var layers = map.getStyle().layers;
var styleSpec = ev.result;
var styleSpecBox = document.getElementById('json-response');
var styleSpecText = JSON.stringify(styleSpec, null, 2);
var syntaxStyleSpecText = syntaxHighlight(styleSpecText);
styleSpecBox.innerHTML = syntaxStyleSpecText;
map.addSource('floorplan', {
// GeoJSON Data source used in vector tiles, documented at
// https://gist.github.com/ryanbaumann/a7d970386ce59d11c16278b90dde094d
'type': 'geojson',
'data': 'https://docs.mapbox.com/mapbox-gl-js/assets/indoor-3d-map.geojson'
});
map.addLayer({
'id': 'room-extrusion',
'type': 'fill-extrusion',
'source': 'floorplan',
'paint': {
// See the Mapbox Style Specification for details on data expressions.
// https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions
// Get the fill-extrusion-color from the source 'color' property.
'fill-extrusion-color': ['get', 'color'],
// Get fill-extrusion-height from the source 'height' property.
'fill-extrusion-height': ['get', 'height'],
// Get fill-extrusion-base from the source 'base_height' property.
'fill-extrusion-base': ['get', 'base_height'],
// Make extrusions slightly opaque for see through indoor walls.
'fill-extrusion-opacity': 0.5
}
});
});
});
因为我试图添加我在此链接上找到的这个 json URL (https://docs.mapbox.com/mapbox-gl-js/assets/indoor-3d-map.geojson):https://docs.mapbox.com/mapbox-gl-js/example/3d-extrusion-floorplan/ 它仅显示第二个 URL 中给出的建筑物的 3D 固定位置。
现在实际上我想在地图上实现一个特定的 3D 建筑,当我使用搜索条件时,它只是动态的。
【问题讨论】:
标签: javascript jquery mapbox mapbox-gl-js mapbox-gl