参考mapbox-gl-js的这个例子...... https://www.mapbox.com/mapbox-gl-js/example/3d-extrusion-floorplan/
当我用我的api键运行这个示例代码时,我只能将地图集中在" Field Museum of Natural History"没有挤压的墙壁。我在这里错过了什么?其他例子似乎直接用于复制粘贴。
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'>
</div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYWtpbmh3YW4iLCJhIjoiY2lwNGYxNDhlMDAwcnZsbTVnY3R0eXo3ZSJ9.XED4AbQBkX8E9qqnwplnWw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-87.61694, 41.86625],
zoom: 15.99,
pitch: 40,
bearing: 20
});
map.on('load', function() {
map.addLayer({
'id': 'room-extrusion',
'type': 'fill-extrusion',
'source': {
// Geojson Data source used in vector tiles, documented at
// https://gist.github.com/ryanbaumann/a7d970386ce59d11c16278b90dde094d
'type': 'geojson',
'data': 'https://www.mapbox.com/mapbox-gl-js/assets/data/indoor-3d-map.geojson'
},
'paint': {
// See the Mapbox Style Spec for details on property functions
// https://www.mapbox.com/mapbox-gl-style-spec/#types-function
'fill-extrusion-color': {
// Get the fill-extrusion-color from the source 'color' property.
'property': 'color',
'type': 'identity'
},
'fill-extrusion-height': {
// Get fill-extrusion-height from the source 'height' property.
'property': 'height',
'type': 'identity'
},
'fill-extrusion-base': {
// Get fill-extrusion-base from the source 'base_height' property.
'property': 'base_height',
'type': 'identity'
},
// Make extrusions slightly opaque for see through indoor walls.
'fill-extrusion-opacity': 0.5
}
});
});
</script>
</body>
</html>
感谢大家的帮助
答案 0 :(得分:2)
此示例有一个CORS问题
Error in mutate_impl(.data, dots) :
Evaluation error: no slot of name "group" for this object of class "derivedDefaultMethod".
一个简单的解决方法是从github gist下载geojson并将其保存在本地与.html文件相同的目录中。然后,您可以将其添加为地图框图层源,例如:
Failed to load file:///mapbox-gl-js/assets/indoor-3d-map.geojson: Cross origin requests are only supported for protocol schemes:
答案 1 :(得分:1)
因为您的数据和代码不在同一个域名中。您可以构建服务器,然后发布数据和代码。你可以做到。