我们在此处使用javascript映射,并尝试使用map.scrollWheelZoom.disable();
这会产生一个错误:未捕获的TypeError:无法读取未定义的属性“ disable”
还有其他选择吗?
这是地图部分中的代码:
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1542186754" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
<div id="map" style="width: 100%; height: 500px; background: grey" />
<script type="text/javascript" charset="UTF-8" >
function addMarkerToGroup(group, coordinate, html) {
var marker = new H.map.Marker(coordinate);
marker.setData(html);
group.addObject(marker);
}
function addInfoBubble(map) {
var group = new H.map.Group();
map.addObject(group);
group.addEventListener('tap', function (evt) {
var bubble = new H.ui.InfoBubble(evt.target.getPosition(), {
content: evt.target.getData()
});
ui.addBubble(bubble);
}, false);
addMarkerToGroup(group, {lat:47.367800, lng:8.532460},
'<div>Zürich' + '</div><div>Gartenstrasse 33<br>8002 Zürich</div>');
addMarkerToGroup(group, {lat:47.186080, lng:8.519480},
'<div >Baar' + '</div><div>Grabenstrasse 5B<br>6340 Baar</div>');
addMarkerToGroup(group, {lat:47.166000, lng:9.555373},
'<div>Liechtenstein' + '</div><div >Schliessa 16<br>9495 Triesen</div>');
}
var platform = new H.service.Platform({
app_id: 'devportal-demo-20180625',
app_code: '9v2BkviRwi9Ot26kp2IysQ',
useHTTPS: true
});
var pixelRatio = window.devicePixelRatio || 1;
var defaultLayers = platform.createDefaultLayers({
tileSize: pixelRatio === 1 ? 256 : 512,
ppi: pixelRatio === 1 ? undefined : 320
});
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map,{
center: {lat: 47.224350, lng:8.984120},
zoom: 10,
pixelRatio: pixelRatio
});
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);
addInfoBubble(map);
// Disable mousewheel zoom
map.scrollWheelZoom.disable();
</script>
</section>
答案 0 :(得分:1)
对 H.mapevents.Behavior 实例变量使用disable
方法:
[...]
var behavior = new H.mapevents.Behavior( new H.mapevents.MapEvents(map) )
// disable wheel zoom behavior
behavior.disable(H.mapevents.Behavior.WHEELZOOM)
或者,您可以在实例化 H.mapevents.Behavior 对象时选择要启用的行为。为此,请使用可选的第二个参数,如下所示:
var behavior = new H.mapevents.Behavior(
new H.mapevents.MapEvents(map),
{
enabled: H.mapevents.Behavior.DRAGGING | H.mapevents.Behavior.DBLTAPZOOM
}
);