【问题标题】:Extrude Polygons for 3D Indoor Mapping...in Mapbox用于 3D 室内映射的拉伸多边形...在 Mapbox 中
【发布时间】:2017-02-07 17:57:49
【问题描述】:

参考这个 mapbox-gl-js 的例子... https://www.mapbox.com/mapbox-gl-js/example/3d-extrusion-floorplan/

当我使用我的 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>

感谢大家的帮助

【问题讨论】:

  • 它在jsbin.com/vevefalope/edit?html,output 为我工作,您在尝试时是否在控制台中看到错误?
  • 我认为您的 geojson 加载有问题,请自己托管 geojson 或将 json 复制并粘贴到您的代码中。
  • 改用'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代理绕过“无访问控制” -stackoverflow.com/questions/43871637/…stackoverflow.com/questions/43871637/…答案的“允许来源标题”问题部分

标签: html 3d mapbox geojson mapbox-gl-js


【解决方案1】:

此示例存在 CORS 问题

Failed to load file:///mapbox-gl-js/assets/indoor-3d-map.geojson: Cross origin requests are only supported for protocol schemes:

一个简单的解决方法是从github gist 下载geojson 并将其保存在与.html 文件相同的目录中。然后您可以将其添加为 mapbox 图层源,例如:

'data': 'indoor_3D_map_example.geojson'

【讨论】:

    【解决方案2】:

    因为您的数据和代码不在同一个域名中。您可以构建一个服务器,然后发布数据和代码。你可以做到的。

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2019-01-22
      相关资源
      最近更新 更多