Answer the question
In order to leave comments, you need to log in
Why doesn't it override the default reaction to the event?
When double-clicking on the layer, the zoom remains, although it costs event.preventDefault()
And with the same handler, but clicking on the map it works, why so?
<!DOCTYPE html>
<html>
<head>
<title>Map</title>
<meta charset="utf-8">
<script src="//api-maps.yandex.ru/2.0-stable/?load=package.standard,package.geoObjects,package.regions&lang=ru-RU" type="text/javascript"></script>
<style type="text/css">
html, body, #container {
width: 100%;
height: 100%;
}
</style>
<script src="regions.js" type="text/javascript"></script>
</head>
<body>
<div id="container"></div>
</body>
</html>
var lcln = {},
fmap = function( geoMap, lang, color ) {
ymaps.regions.load( lang, {
lang: 'ru',
quality: 3
} ).then( function ( result ) {
var lastCollection = result.geoObjects;
lcln[ lang ] = lastCollection;
lastCollection.options.set( {
zIndex: 1,
zIndexHover: 2,
draggable: false,
fillColor: color,
strokeColor: color
} );
console.log( lastCollection.events );
lastCollection.events.add( 'dblclick', function ( event ) {
event.preventDefault() // не отменяет зум по слою
} );
geoMap.geoObjects.add( lastCollection );
}, function () {
} );
};
ymaps.ready( function () {
geoMap = new ymaps.Map( 'container', {
center: [ 65, 104 ],
type: "yandex#map",
zoom: 4
} );
geoMap.events.add( 'dblclick', function ( event ) {
event.preventDefault(); // а здесь отменяет зум по карте
} );
geoMap.behaviors.enable( 'scrollZoom' );
var lng = 'ru',
level = 3;
fmap( geoMap, 'RU', 'rgba(13, 91, 58, 0.2)' );
fmap( geoMap, 'UA', 'rgba(203, 37, 37, 0.2)' );
} );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question