2017-02-07 38 views
0

在談到這個例子mapbox-GL-JS ... https://www.mapbox.com/mapbox-gl-js/example/3d-extrusion-floorplan/擠出多邊形的3D室內映射......在Mapbox

當我與我的API密鑰運行此示例代碼,我只得到了地圖以「自然史博物館」爲中心,沒有任何牆壁擠壓。我在這裏錯過了什麼?其他示例似乎直接從複製粘貼中運行。

<!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> 

謝謝大家對你的幫助

+1

它在爲我工作在http://jsbin.com/vevefalope/edit?html,output 當您嘗試它時,您是否在控制檯中看到錯誤? – mollymerp

+1

您的geojson加載出了問題我想,您可以自己託管geojson或將json複製並粘貼到代碼中。 –

+1

使用''data':'https://cors-anywhere.herokuapp.com/https:// www.mapbox.com/mapbox-gl-js/assets/data/indoor-3d-map.geojson'' (也就是說,在URL前加上https:// cors-anywhere.herokuapp.com /'),有關說明,請參閱*如何使用CORS代理來解決「無訪問控制 - 允許 - 來源標題「問題*部分的答案在https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141 – sideshowbarker

回答

0

因爲你的數據和代碼不在同一個域名。您可以構建服務器,然後發佈數據和代碼。你可以做到。