如何使用mapboxgl.js向地图添加平铺图层 [英] How to add tile layer to map using mapboxgl.js

查看:107
本文介绍了如何使用mapboxgl.js向地图添加平铺图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里添加了使用tiff创建的图块

Here m adding tile created using tiff

mapboxgl.accessToken ='pk.eyJ1IjoiZ2F1cmF2Y2F0c3RlY2giLCJhIjoiY2l1cGo0MTl4MDAxajJ1bng5a2xieTY0diJ9.0fDXNulI91U85ngSc4jGCg';
var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/light-v9',
  zoom: 13,
  center: [-122.447303, 37.753574]
});

map.on('load', function () {
  map.addSource('terrain-data', {
    type: 'raster',
    url:'mapbox://gaurav.2on6cgzq'
  });
  map.addLayer({
    "id": "terrain-data",
    "type": "line",
    "source": "terrain-data",
    "source-layer": "contour",
    "layout": {
      "line-join": "round",
      "line-cap": "round"
    },
    "paint": {
      "line-color": "#ff69b4",
      "line-width": 1
    }
  });
});

我得到了:

错误:源地形数据"上不存在源层轮廓"由样式层terrain-data"指定

Error: Source layer "contour" does not exist on source "terrain-data" as specified by style layer "terrain-data"

推荐答案

我认为"source-layer":"contour" 根本不适用于栅格源.参见 https://www.mapbox.com/mapbox-gl-js/example/map-tiles/因此,摆脱掉这一行.看起来您将需要在源代码中同时包含一个"tileSize":256 选项.

I do not believe the "source-layer": "contour" is applicable for raster sources whatsoever. See https://www.mapbox.com/mapbox-gl-js/example/map-tiles/ So get rid of that line.Looks like you will need a "tileSize": 256 option included as well on the source.

同样也不需要布局和绘画选项,这些都是矢量或geojson源的选项.这些类型的控件在栅格上不可用.

Also your layout and paint options are going to be unneeded as well.Those are options for vector or geojson sources. Those types of controls are not available on raster.

这篇关于如何使用mapboxgl.js向地图添加平铺图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆