javascript - 如何使用 RequireJS 填充 Leaflet + mapbox?
问题描述
我正在尝试填充传单和地图框。
在我的垫片下面:
require.config({
paths: {
'leaflet': '/app/res/libs/leaflet/js/leaflet-1.6.0',
'leaflet-draw': '/app/res/libs/leaflet/js/leaflet.draw-1.0.4',
'mapbox': '/app/res/libs/leaflet/js/mapbox-1.6.2'
},
shim: {
'leaflet': {
exports: 'L'
},
'leaflet-draw': {
deps: ['leaflet']
},
'mapbox': {
deps: ['leaflet'],
},
} // end Shim Configuration
});
define(["leaflet", "leaflet-draw", "mapbox"], function (L, dummy0, dummy1) {
return L;
});
使用地图上方的垫片可以正常工作,但是当我尝试使用应该由 Mapbox 提供的东西时,我得到一个错误。
例如,下面的代码可以正常工作:
// Add layers to the map
L.control.layers({
'Esri Satellite Map': L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
}).addTo(map)
}).addTo(map);
但是,如果我尝试使用 Mapbox 中的 tileLayer:
L.control.layers({
'Mapbox Satellite Map': L.mapbox.tileLayer('bobbysud.map-l4i2m7nd', {
detectRetina: true
}).addTo(map),
'Esri Satellite Map': L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
})
}).addTo(map);
我收到以下错误:
TypeError: Cannot read property 'tileLayer' of undefined
我怎样才能让 Mapbox 工作?
解决方案
推荐阅读
- github-actions - 在 GitHub Action Error/Warning/Notice Messages 中指定参数有什么意义
- image-processing - 通过发布请求发送 .tif
- r - 来自父 UI 输入的模块服务器观察事件
- laravel - 使用 Laravel 基于商店时间表的订单取货系统
- c - C程序没有输出
- reactjs - 是否可以使用 reactjs 打开 chrome 扩展?
- redis - 有没有办法实现仅在密钥已经存在时才弹出的 BLPOPX?
- mysql - 在子查询之外使用子查询的结果
- regex - mod_rewrite 匹配编码的 URL
- sql - 如果 id 存在于另一个表中,则有条件地插入另一个表,否则插入到 oracle 中的两个表中