Javascript 禁用地图框上的滚动缩放
我正在尝试禁用mapbox地图上的滚动缩放,但它不起作用。有人能告诉我我的代码出了什么问题吗?我得到的错误是“UncaughtTypeError:无法读取未定义的属性'disable'”Javascript 禁用地图框上的滚动缩放,javascript,mapbox,Javascript,Mapbox,我正在尝试禁用mapbox地图上的滚动缩放,但它不起作用。有人能告诉我我的代码出了什么问题吗?我得到的错误是“UncaughtTypeError:无法读取未定义的属性'disable'” L.mapbox.accessToken='pk.token'; var map=L.mapbox.map('map','mapbox.streets'{ 传奇控制:{ 位置:“右上角” } }) .setView([56.3,11.5],7); var popup=newl.popup({autoPan:f
L.mapbox.accessToken='pk.token';
var map=L.mapbox.map('map','mapbox.streets'{
传奇控制:{
位置:“右上角”
}
})
.setView([56.3,11.5],7);
var popup=newl.popup({autoPan:false});
//statesData来自上面包含的“us states.js”脚本
var statesLayer=L.geoJson(statesData{
风格:getStyle,
onEachFeature:onEachFeature
}).addTo(地图);
函数getStyle(功能){
返回{
体重:2,
不透明度:0.1,
颜色:'黑色',
不透明度:0.7,
fillColor:getColor(feature.properties.density)
};
}
//根据“总体密度”值获取颜色
函数getColor(d){
返回d>1000?“#512b00”:
d>500?“#8E4C01”:
d>200?“#cc4c02”:
d>100?“#ec7014”:
d>50?“#Fe9999”:
d>20?“#fec44f”:
d>10?“#感觉391”:
d>5?“#fff7bc”:
#ffffe5";
}
功能onEachFeature(功能,图层){
分层({
穆斯穆夫:穆斯穆夫,
mouseout:mouseout,
单击:缩放自然
});
}
工具提示;
函数mousemove(e){
var层=e.目标;
弹出.setLatLng(即latlng);
popup.setContent(“”+layer.feature.properties.name+“”+
layer.feature.properties.density+feriehuse');
如果(!popup.\u map)popup.openOn(map);
清除超时(关闭工具提示);
//突出显示功能
layer.setStyle({
体重:3,
不透明度:0.3,
填充不透明度:0.9
});
如果(!L.Browser.ie&&!L.Browser.opera){
层。布氏体();
}
}
功能鼠标输出(e){
statesLayer.resetStyle(即目标);
closeTooltip=window.setTimeout(函数(){
map.closePopup();
}, 100);
}
函数ZoomTof性质(e){
fitBounds(e.target.getBounds());
}
map.legendControl.addLegend(getLegendHTML());
函数getLegendHTML(){
风险值等级=[0,5,10,20,50,100,200,500,1000],
标签=[],
从,到,;
对于(变量i=0;i”+
从+(到“–”+到:“+)+”;
}
返回“Antal feriehuse”+标签。加入(“”)+
;
}
//使用“滚动”时禁用地图缩放
map.scrollZoom.disable();
这是一个mapbox.js/sloop地图,而不是mapbox gl js,因此区别在于sloop中的滚动缩放控件称为scrollWheelZoom
非scrollZoom
。如果将脚本的最后一行替换为以下内容,它应该可以工作
这是mapbox.js/单张地图,而不是mapbox gl js,因此区别在于单张中的滚动缩放控件称为
scrollWheelZoom
而不是scrollZoom
。如果将脚本的最后一行替换为以下内容,它应该可以工作
<script>
L.mapbox.accessToken = 'pk.token';
var map = L.mapbox.map('map', 'mapbox.streets', {
legendControl: {
position: 'topright'
}
})
.setView([56.3, 11.5], 7);
var popup = new L.Popup({ autoPan: false });
// statesData comes from the 'us-states.js' script included above
var statesLayer = L.geoJson(statesData, {
style: getStyle,
onEachFeature: onEachFeature
}).addTo(map);
function getStyle(feature) {
return {
weight: 2,
opacity: 0.1,
color: 'black',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.density)
};
}
// get color depending on population density value
function getColor(d) {
return d > 1000 ? '#512b00' :
d > 500 ? '#8E4C01' :
d > 200 ? '#cc4c02' :
d > 100 ? '#ec7014' :
d > 50 ? '#fe9929' :
d > 20 ? '#fec44f' :
d > 10 ? '#fee391' :
d > 5 ? '#fff7bc' :
'#ffffe5';
}
function onEachFeature(feature, layer) {
layer.on({
mousemove: mousemove,
mouseout: mouseout,
click: zoomToFeature
});
}
var closeTooltip;
function mousemove(e) {
var layer = e.target;
popup.setLatLng(e.latlng);
popup.setContent('<div class="marker-title">' + layer.feature.properties.name + '</div>' +
layer.feature.properties.density + ' feriehuse');
if (!popup._map) popup.openOn(map);
window.clearTimeout(closeTooltip);
// highlight feature
layer.setStyle({
weight: 3,
opacity: 0.3,
fillOpacity: 0.9
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}
function mouseout(e) {
statesLayer.resetStyle(e.target);
closeTooltip = window.setTimeout(function() {
map.closePopup();
}, 100);
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
map.legendControl.addLegend(getLegendHTML());
function getLegendHTML() {
var grades = [0, 5, 10, 20, 50, 100, 200, 500, 1000],
labels = [],
from, to;
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<li><span class="swatch" style="background:' + getColor(from + 1) + '"></span> ' +
from + (to ? '–' + to : '+')) + '</li>';
}
return '<span>Antal feriehuse</span><ul>' + labels.join('') + '</ul>';
}
// disable map zoom when using scroll
map.scrollZoom.disable();
</script>
if (map.scrollWheelZoom) {
map.scrollWheelZoom.disable();
}