Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获得;未捕获类型错误:这是.“u map.hasLayer不是函数”;将传单图层添加到地图框时_Javascript_Jquery_Leaflet_Gis_Mapbox - Fatal编程技术网

Javascript 获得;未捕获类型错误:这是.“u map.hasLayer不是函数”;将传单图层添加到地图框时

Javascript 获得;未捕获类型错误:这是.“u map.hasLayer不是函数”;将传单图层添加到地图框时,javascript,jquery,leaflet,gis,mapbox,Javascript,Jquery,Leaflet,Gis,Mapbox,我正在尝试将传单图层添加到mapbox地图。 我使用了官方传单页面中关于如何向mapbox添加图层的示例 但是leayers没有出现,console返回错误“UncaughtTypeError:this.\u map.hasLayer不是函数” 这是我的密码: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src='h

我正在尝试将传单图层添加到mapbox地图。 我使用了官方传单页面中关于如何向mapbox添加图层的示例

但是leayers没有出现,console返回错误“UncaughtTypeError:this.\u map.hasLayer不是函数”

这是我的密码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css' rel='stylesheet' />

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>

<div id='map' style="position:relative;float:left;width:100%;height:100%;margin:0px 0px 0px 0px;z-index:1;"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYm9zc3RvbjgxMiIsImEiOiJjaW94NnBlY2cwMDNsejBtNTZucnV3ZDJpIn0.U1b4soqANbdiKr_hPGDO8g';

var map = new mapboxgl.Map({
  container: 'map',
  center: [-105.02, 39.61],
  zoom: 10,
  style: 'mapbox://styles/mapbox/streets-v9',
  hash: true,
  transformRequest: (url, resourceType)=> {
    if(resourceType == 'Source' && url.startsWith('http://myHost')) {
      return {
       url: url.replace('http', 'https'),
       headers: { 'my-custom-header': true},
       credentials: 'include'  // Include cookies for cross-origin requests
     }
    }
  }
});

var littleton = L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.'),
    denver    = L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.'),
    aurora    = L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.'),
    golden    = L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.');

var cities = L.layerGroup([littleton, denver, aurora, golden]);

var grayscale = L.tileLayer('mapbox://styles/mapbox/streets-v9', {id: 'MapID'}),
    streets   = L.tileLayer('mapbox://styles/mapbox/streets-v9', {id: 'MapID'});


var baseMaps = {
    "Grayscale": grayscale,
    "Streets": streets
};

var overlayMaps = {
    "Cities": cities
};

L.control.layers(baseMaps, overlayMaps).addTo(map);
</script>

mapboxgl.accessToken='pk.eyj1ijoiym9zc3rvbjgxmiisimeoijjaw94nnbly2cwmdnsejbtntzucnv3zdjpin0.U1b4soqANbdiKr_hPGDO8g';
var map=new mapboxgl.map({
容器:“映射”,
中间:[-105.02,39.61],
缩放:10,
风格:'mapbox://styles/mapbox/streets-v9',
哈什:没错,
transformRequest:(url,resourceType)=>{
if(resourceType=='Source'&&url.startsWith('http://myHost')) {
返回{
url:url.replace('http','https'),
标题:{“我的自定义标题”:true},
凭据:“包括”//包括跨源请求的cookie
}
}
}
});
var littleton=L.marker([39.61,-105.02])。bindPopup('这是littleton,CO.),
丹佛=L.marker([39.74,-104.99])。bindPopup('这是丹佛,CO.),
aurora=L.marker([39.73,-104.8])。bindPopup('这是公司的aurora,'),
golden=L.marker([39.77,-105.23])。bindPopup('这是golden,CO.);
var cities=L.layerGroup([littleton,丹佛,aurora,golden]);
var灰度=L.tileLayer('mapbox://styles/mapbox/streets-v9“,{id:'MapID'}),
街道=L.Tillelayer('mapbox://styles/mapbox/streets-v9“,{id:'MapID'});
变量基本映射={
“灰度”:灰度,
“街道”:街道
};
var overlayMaps={
“城市”:城市
};
L.控制。图层(底图、覆盖图)。添加到(地图);

请帮助我查找问题?

MapboxGL的API与传单的API不兼容。不要期望能够在MapboxGL地图中调用传单功能(例如添加地图控件)

请注意,
mapbox gl js
mapbox js
不同。事实上,后者是以传单为基础的