Give back default behavior of map on dblclick Open LayerOpenlayers: zooming WFS sometimes return to first zoom levelOpen Layer map with multple lineOpenlayers 2.12 Select Feature when z index is setOnly one popup on Vector OpenLayersMultiple info boxes showing up when I click on map (GeoServer layers)Openlayers 4 - Make layer invisible on feature clickOpenlayers 4: Changing the draw order of selected featuresOpenLayers 4 styling draw featuresCapturing mousemove for a single layer in OpenLayersOpenLayers 3 Style Function for dynamic feature font setting

What's the physical meaning of the statement that "photons don't have positions"?

Another "name-that-distribution" question

Soft constraints and hard constraints

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?

Do gauntlets count as armor?

What is the difference between uniform velocity and constant velocity?

When will the last unambiguous evidence of mankind disappear?

What is the minimum wait before I may I re-enter the USA after a 90 day visit on the Visa B-2 Program?

What would be the effects of (relatively) widespread precognition on the stock market?

Redirection operator, standard input and command parameters

Aren't all schwa sounds literally /ø/?

Could Europeans in Europe demand protection under UN Declaration on the Rights of Indigenous Peoples?

Conditional statement in a function for PS1 are not re-evalutated

Where can I find standards for statistical acronyms and whether they should be capitalized or lower case?

I want light controlled by one switch, not two

Applying for jobs when I have an obvious scar

How to tell readers that I know my story is factually incorrect?

Do I have to mention my main characters age?

Satellite in orbit in front of and behind the Moon

Why didn't Balak request Bilam to bless his own people?

What does Windows' "Tuning up Application Start" do?

What is the intuition for higher homotopy groups not vanishing?

Is this guy trying to scam me?

Brute-force the switchboard



Give back default behavior of map on dblclick Open Layer


Openlayers: zooming WFS sometimes return to first zoom levelOpen Layer map with multple lineOpenlayers 2.12 Select Feature when z index is setOnly one popup on Vector OpenLayersMultiple info boxes showing up when I click on map (GeoServer layers)Openlayers 4 - Make layer invisible on feature clickOpenlayers 4: Changing the draw order of selected featuresOpenLayers 4 styling draw featuresCapturing mousemove for a single layer in OpenLayersOpenLayers 3 Style Function for dynamic feature font setting






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















After clicking on a button I overwrite the default behaviour of map.on('dblclick') which is zoom in.



I would like to retrieve this behavior in other part of code.



How can I do that?



EDIT: For better explanation. I have a button which when I click I override the behavior on map dblclick



$('#RemoveArea').on('click', function()
map.getInteractions().pop()
map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)


How to on click on other btn again make the map behave the same as before, it is zoom in the map



 $('#OtherBtn').on('click', function()
//...
)


Is it possible?










share|improve this question
























  • May I know what is wrong with a question??

    – goskan
    Mar 26 at 13:46

















-2















After clicking on a button I overwrite the default behaviour of map.on('dblclick') which is zoom in.



I would like to retrieve this behavior in other part of code.



How can I do that?



EDIT: For better explanation. I have a button which when I click I override the behavior on map dblclick



$('#RemoveArea').on('click', function()
map.getInteractions().pop()
map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)


How to on click on other btn again make the map behave the same as before, it is zoom in the map



 $('#OtherBtn').on('click', function()
//...
)


Is it possible?










share|improve this question
























  • May I know what is wrong with a question??

    – goskan
    Mar 26 at 13:46













-2












-2








-2








After clicking on a button I overwrite the default behaviour of map.on('dblclick') which is zoom in.



I would like to retrieve this behavior in other part of code.



How can I do that?



EDIT: For better explanation. I have a button which when I click I override the behavior on map dblclick



$('#RemoveArea').on('click', function()
map.getInteractions().pop()
map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)


How to on click on other btn again make the map behave the same as before, it is zoom in the map



 $('#OtherBtn').on('click', function()
//...
)


Is it possible?










share|improve this question
















After clicking on a button I overwrite the default behaviour of map.on('dblclick') which is zoom in.



I would like to retrieve this behavior in other part of code.



How can I do that?



EDIT: For better explanation. I have a button which when I click I override the behavior on map dblclick



$('#RemoveArea').on('click', function()
map.getInteractions().pop()
map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)


How to on click on other btn again make the map behave the same as before, it is zoom in the map



 $('#OtherBtn').on('click', function()
//...
)


Is it possible?







openlayers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 15:49







goskan

















asked Mar 26 at 12:26









goskangoskan

13110 bronze badges




13110 bronze badges












  • May I know what is wrong with a question??

    – goskan
    Mar 26 at 13:46

















  • May I know what is wrong with a question??

    – goskan
    Mar 26 at 13:46
















May I know what is wrong with a question??

– goskan
Mar 26 at 13:46





May I know what is wrong with a question??

– goskan
Mar 26 at 13:46












2 Answers
2






active

oldest

votes


















2














You can disable the interaction when you create the map



var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false),
view: new ol.View(
center: [x, y],
zoom: z
)
);


To be able to switch an interaction on/off you need to assign it to a variable instead of creating it with the defaults:



var dcz = new ol.interaction.DoubleClickZoom();

var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [x, y],
zoom: z
)
);


to switch off and on :



dcz.setActive(false);

dcz.setActive(true);





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





Either keep your double click listener permanently active and let it test whether your buttons have turned on or off the double click zoom:



map.on('dblclick', function(evt) 
if (!dcz.getActive())
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)

);

$('#RemoveArea').on('click', function()
dcz.setActive(false);
)

$('#OtherBtn').on('click', function()
dcz.setActive(true);
)


or you need to store the key of the double click listener so you can unset it later



$('#RemoveArea').on('click', function()
key = map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)

$('#OtherBtn').on('click', function()
ol.Observable.unByKey(key)
)





share|improve this answer

























  • This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

    – goskan
    Mar 26 at 15:50











  • I've added that to my answer.

    – Mike
    Mar 26 at 16:05











  • But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

    – goskan
    Mar 26 at 17:16







  • 1





    It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

    – Mike
    Mar 26 at 18:45











  • I can see it works, but still does not work for me :(

    – goskan
    Mar 26 at 19:31


















0














So I didnt find a way to retrieve zoom on dblclick, but I am able to prevent the behavior that I override before. So, after clickin OtherBtn



I added this



 map.on('dblclick', function(evt) 
evt.preventDefault();
)


So as I said, It does not zoom in but also does not do other things.



EDIT: I found the function in which is un and it is opposite of on. So in OtherBtn I set



map.un('dblclick', doubleClickCallback);


where doubleClickCallback is just a function with all the things I was doing after dblclick, and comes back to the deafualt behavior






share|improve this answer




















  • 1





    You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

    – Mike
    Mar 28 at 0:25











  • Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

    – goskan
    Mar 28 at 14:07






  • 1





    Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

    – Mike
    Mar 28 at 15:01













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357147%2fgive-back-default-behavior-of-map-on-dblclick-open-layer%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can disable the interaction when you create the map



var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false),
view: new ol.View(
center: [x, y],
zoom: z
)
);


To be able to switch an interaction on/off you need to assign it to a variable instead of creating it with the defaults:



var dcz = new ol.interaction.DoubleClickZoom();

var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [x, y],
zoom: z
)
);


to switch off and on :



dcz.setActive(false);

dcz.setActive(true);





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





Either keep your double click listener permanently active and let it test whether your buttons have turned on or off the double click zoom:



map.on('dblclick', function(evt) 
if (!dcz.getActive())
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)

);

$('#RemoveArea').on('click', function()
dcz.setActive(false);
)

$('#OtherBtn').on('click', function()
dcz.setActive(true);
)


or you need to store the key of the double click listener so you can unset it later



$('#RemoveArea').on('click', function()
key = map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)

$('#OtherBtn').on('click', function()
ol.Observable.unByKey(key)
)





share|improve this answer

























  • This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

    – goskan
    Mar 26 at 15:50











  • I've added that to my answer.

    – Mike
    Mar 26 at 16:05











  • But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

    – goskan
    Mar 26 at 17:16







  • 1





    It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

    – Mike
    Mar 26 at 18:45











  • I can see it works, but still does not work for me :(

    – goskan
    Mar 26 at 19:31















2














You can disable the interaction when you create the map



var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false),
view: new ol.View(
center: [x, y],
zoom: z
)
);


To be able to switch an interaction on/off you need to assign it to a variable instead of creating it with the defaults:



var dcz = new ol.interaction.DoubleClickZoom();

var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [x, y],
zoom: z
)
);


to switch off and on :



dcz.setActive(false);

dcz.setActive(true);





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





Either keep your double click listener permanently active and let it test whether your buttons have turned on or off the double click zoom:



map.on('dblclick', function(evt) 
if (!dcz.getActive())
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)

);

$('#RemoveArea').on('click', function()
dcz.setActive(false);
)

$('#OtherBtn').on('click', function()
dcz.setActive(true);
)


or you need to store the key of the double click listener so you can unset it later



$('#RemoveArea').on('click', function()
key = map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)

$('#OtherBtn').on('click', function()
ol.Observable.unByKey(key)
)





share|improve this answer

























  • This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

    – goskan
    Mar 26 at 15:50











  • I've added that to my answer.

    – Mike
    Mar 26 at 16:05











  • But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

    – goskan
    Mar 26 at 17:16







  • 1





    It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

    – Mike
    Mar 26 at 18:45











  • I can see it works, but still does not work for me :(

    – goskan
    Mar 26 at 19:31













2












2








2







You can disable the interaction when you create the map



var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false),
view: new ol.View(
center: [x, y],
zoom: z
)
);


To be able to switch an interaction on/off you need to assign it to a variable instead of creating it with the defaults:



var dcz = new ol.interaction.DoubleClickZoom();

var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [x, y],
zoom: z
)
);


to switch off and on :



dcz.setActive(false);

dcz.setActive(true);





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





Either keep your double click listener permanently active and let it test whether your buttons have turned on or off the double click zoom:



map.on('dblclick', function(evt) 
if (!dcz.getActive())
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)

);

$('#RemoveArea').on('click', function()
dcz.setActive(false);
)

$('#OtherBtn').on('click', function()
dcz.setActive(true);
)


or you need to store the key of the double click listener so you can unset it later



$('#RemoveArea').on('click', function()
key = map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)

$('#OtherBtn').on('click', function()
ol.Observable.unByKey(key)
)





share|improve this answer















You can disable the interaction when you create the map



var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false),
view: new ol.View(
center: [x, y],
zoom: z
)
);


To be able to switch an interaction on/off you need to assign it to a variable instead of creating it with the defaults:



var dcz = new ol.interaction.DoubleClickZoom();

var map = new ol.Map(
layers [myLayer],
target: 'map',
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [x, y],
zoom: z
)
);


to switch off and on :



dcz.setActive(false);

dcz.setActive(true);





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





Either keep your double click listener permanently active and let it test whether your buttons have turned on or off the double click zoom:



map.on('dblclick', function(evt) 
if (!dcz.getActive())
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)

);

$('#RemoveArea').on('click', function()
dcz.setActive(false);
)

$('#OtherBtn').on('click', function()
dcz.setActive(true);
)


or you need to store the key of the double click listener so you can unset it later



$('#RemoveArea').on('click', function()
key = map.on('dblclick', function(evt)
evt.preventDefault();
evt.map.forEachFeatureAtPixel(evt.pixel, function(feature,layer)
featureId = feature.getId()
areaFeature = feature.getGeometry().getArea()/ 10000;
totalSelectedArea -= parseFloat(areaFeature.toFixed(2));
)
);
)

$('#OtherBtn').on('click', function()
ol.Observable.unByKey(key)
)





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>





 var layer = new ol.layer.Tile(
source: new ol.source.OSM()
);

var dcz = new ol.interaction.DoubleClickZoom();

var map1 = new ol.Map(
target: 'map',
layers: [layer],
interactions: ol.interaction.defaults(doubleClickZoom: false).extend([dcz]),
view: new ol.View(
center: [0, 0],
zoom: 1
)
);

function dczOnOff()
dcz.setActive(document.getElementsByName('dcz')[1].checked);

html, body 
margin: 0;
padding: 0;
width: 100%;
height: 100%;

.map
width: 100%;
height: 80%;

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>
<div style="padding-left: 50px;">
<input type="radio" name="dcz" value="0" size="16" onchange="dczOnOff()"> DCZ OFF</br>
<input type="radio" name="dcz" value="1" size="16" onchange="dczOnOff()" checked> DCZ ON</br>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 0:22

























answered Mar 26 at 13:54









MikeMike

4,4042 gold badges2 silver badges14 bronze badges




4,4042 gold badges2 silver badges14 bronze badges












  • This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

    – goskan
    Mar 26 at 15:50











  • I've added that to my answer.

    – Mike
    Mar 26 at 16:05











  • But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

    – goskan
    Mar 26 at 17:16







  • 1





    It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

    – Mike
    Mar 26 at 18:45











  • I can see it works, but still does not work for me :(

    – goskan
    Mar 26 at 19:31

















  • This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

    – goskan
    Mar 26 at 15:50











  • I've added that to my answer.

    – Mike
    Mar 26 at 16:05











  • But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

    – goskan
    Mar 26 at 17:16







  • 1





    It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

    – Mike
    Mar 26 at 18:45











  • I can see it works, but still does not work for me :(

    – goskan
    Mar 26 at 19:31
















This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

– goskan
Mar 26 at 15:50





This is the oppsoite I need, I only want to override behavior in particular situation and later com back to the old one.

– goskan
Mar 26 at 15:50













I've added that to my answer.

– Mike
Mar 26 at 16:05





I've added that to my answer.

– Mike
Mar 26 at 16:05













But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

– goskan
Mar 26 at 17:16






But unfortunaletly didnt help. Instead evt.preventDefault() I used dcz.setActive(false); and after clicking $('#OtherBtn') I added dcz.setActive(true);, but the previos behavior is still happening. Am I doin it wrong or something?

– goskan
Mar 26 at 17:16





1




1





It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

– Mike
Mar 26 at 18:45





It's working the the snippet above. I suspect changing the setting after an event has fired may be too late to stop it.

– Mike
Mar 26 at 18:45













I can see it works, but still does not work for me :(

– goskan
Mar 26 at 19:31





I can see it works, but still does not work for me :(

– goskan
Mar 26 at 19:31













0














So I didnt find a way to retrieve zoom on dblclick, but I am able to prevent the behavior that I override before. So, after clickin OtherBtn



I added this



 map.on('dblclick', function(evt) 
evt.preventDefault();
)


So as I said, It does not zoom in but also does not do other things.



EDIT: I found the function in which is un and it is opposite of on. So in OtherBtn I set



map.un('dblclick', doubleClickCallback);


where doubleClickCallback is just a function with all the things I was doing after dblclick, and comes back to the deafualt behavior






share|improve this answer




















  • 1





    You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

    – Mike
    Mar 28 at 0:25











  • Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

    – goskan
    Mar 28 at 14:07






  • 1





    Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

    – Mike
    Mar 28 at 15:01















0














So I didnt find a way to retrieve zoom on dblclick, but I am able to prevent the behavior that I override before. So, after clickin OtherBtn



I added this



 map.on('dblclick', function(evt) 
evt.preventDefault();
)


So as I said, It does not zoom in but also does not do other things.



EDIT: I found the function in which is un and it is opposite of on. So in OtherBtn I set



map.un('dblclick', doubleClickCallback);


where doubleClickCallback is just a function with all the things I was doing after dblclick, and comes back to the deafualt behavior






share|improve this answer




















  • 1





    You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

    – Mike
    Mar 28 at 0:25











  • Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

    – goskan
    Mar 28 at 14:07






  • 1





    Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

    – Mike
    Mar 28 at 15:01













0












0








0







So I didnt find a way to retrieve zoom on dblclick, but I am able to prevent the behavior that I override before. So, after clickin OtherBtn



I added this



 map.on('dblclick', function(evt) 
evt.preventDefault();
)


So as I said, It does not zoom in but also does not do other things.



EDIT: I found the function in which is un and it is opposite of on. So in OtherBtn I set



map.un('dblclick', doubleClickCallback);


where doubleClickCallback is just a function with all the things I was doing after dblclick, and comes back to the deafualt behavior






share|improve this answer















So I didnt find a way to retrieve zoom on dblclick, but I am able to prevent the behavior that I override before. So, after clickin OtherBtn



I added this



 map.on('dblclick', function(evt) 
evt.preventDefault();
)


So as I said, It does not zoom in but also does not do other things.



EDIT: I found the function in which is un and it is opposite of on. So in OtherBtn I set



map.un('dblclick', doubleClickCallback);


where doubleClickCallback is just a function with all the things I was doing after dblclick, and comes back to the deafualt behavior







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 14:11

























answered Mar 27 at 13:35









goskangoskan

13110 bronze badges




13110 bronze badges







  • 1





    You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

    – Mike
    Mar 28 at 0:25











  • Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

    – goskan
    Mar 28 at 14:07






  • 1





    Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

    – Mike
    Mar 28 at 15:01












  • 1





    You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

    – Mike
    Mar 28 at 0:25











  • Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

    – goskan
    Mar 28 at 14:07






  • 1





    Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

    – Mike
    Mar 28 at 15:01







1




1





You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

– Mike
Mar 28 at 0:25





You need to turn of the dblclick listener you originally set, not set a new one. Or you could keep it active and let it test if you have changed double click zoom. I've added more samples to my answer,

– Mike
Mar 28 at 0:25













Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

– goskan
Mar 28 at 14:07





Thank you @Mike for your involvement to my question, I didnt check your solution, cause I found out other one. (see edit above)

– goskan
Mar 28 at 14:07




1




1





Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

– Mike
Mar 28 at 15:01





Yes, using a named function with un will have the same effect as using unByKey with the key from an unnamed function.

– Mike
Mar 28 at 15:01

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357147%2fgive-back-default-behavior-of-map-on-dblclick-open-layer%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript