Reputation: 627
In reference to this example for mapbox-gl-js... https://www.mapbox.com/mapbox-gl-js/example/3d-extrusion-floorplan/
When I run this example code with my api key, I only get the map centered on the "Field Museum of Natural History" without any walls extruded. What am I missing here? The other examples seem to work straight out of copy paste.
<!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>
Thanks Everyone for your help
Upvotes: 0
Views: 1163
Reputation: 915
This example has a CORS issue
Failed to load file:///mapbox-gl-js/assets/indoor-3d-map.geojson: Cross origin requests are only supported for protocol schemes:
A simple workaround is to download the geojson from the github gist and save it locally in the same directory as your .html file. Then you can add it as a mapbox layer source, e.g:
'data': 'indoor_3D_map_example.geojson'
Upvotes: 2
Reputation: 13
Because your data and code aren't in the same domain name. You can build a sever, then publish the data and code. You can make it.
Upvotes: 1