Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

i want to add the functionality of switching the option to pan the map and put it in a checkbox. But im not quite sure how i can do that.

The reason I want to do this is: I have a layer which displays features and has a select and hover control. So theres no way to pan the map, because the clickEvent triggers direct action from the Handlers (click,hover). I want to add a checkbox where i can activate/deactivate the possibility to pan the map, so i can pan the map when there are features present, which normally would trigger a reaction to the mouseover the feature.

The way ive tried to do it is this one but it didnt work. I attached the function to the checkbox but it never worked :/

function allowPan() {

if(panAct == false){
        highlightCtrl.activate();
        selectedControl.activate();
        alert("controls activated!!")
        panAct = true;
    }     
if(panAct == true){ 
    highlightCtrl.deactivate();
    selectedControl.deactivate();
    alert("controls deactivated!!");
    panAct = false;
    }

}

share|improve this question
3  
we can't help you with only that's small pies of code. Please, post the complete code or give an url. By the way, working with javascript, don't forget to use firebug as debugging tool. –  simo May 5 '11 at 10:04
    
I have this problem too. I tried to deactivate the Navigation and DragPan controls, but it didn´t worked. On this example the map curiosly can´t be panned when we are drawing a regular polygon feature, but i modified it and when I draw a line or a point the map can be panned. openlayers.org/dev/examples/regular-polygons.html (Leandro from Brazil) –  user2882 May 5 '11 at 13:05
    
Leandro, this is not an answer. For more clarity and to follow SE rules, you should have posted this as comment. see the FAQ for more information : gis.stackexchange.com/faq –  simo May 5 '11 at 13:43
    
converted answer to comment with @simo reply –  Mapperz May 5 '11 at 14:34
1  
Ive uploaded a screenshot so you can actually SEE what i mean. bit.ly/kWDEpd , the yellow feature in the middle is the one where my mouse currently sits. if i would click i would activate a popup. i want to use the checkbox that you can see, to ACTIVATE or DEACTIVATE the controls that i have added to the map. Because a simple .deactivate (as shown in my example) didnt work. thanks :) –  1amtoo1337 May 5 '11 at 14:59

2 Answers 2

up vote 2 down vote accepted

It will be tricky to debug that without the full code . How could we know if your variables are globals, if you're calling the right control vars and so on!???

Anyway, the first thing to do would be to test the value of panAct var by adding alert(panAct); instructions just at the beginning of your function.

By the way, it would probably be a great idea to return panAct; var at the end.

share|improve this answer
    
Yes the controls are global.ive tried this already and it worked so far that the value got changed from false to true and vice versa but the .deactivate Part never executed so the controls never got deactivated. But an alert after the .deactivate Part showed up so i dont think that you can just get rid of a control like that :( also (sorry) i wouldnt know what it would help if i would post my selectControl and/or my hovercontrol since its irrelevant what gets done in them.i want to implement functionality to deactivate those,so whats inside doesnt matter.And yeah,thanks for the return idea. –  1amtoo1337 May 5 '11 at 15:50
    
ok, another way to do is to try first to deactivate your control outisde the function. Once it's done, ok to wrap it in a function again! –  simo May 5 '11 at 15:56
    
ok i will try it this way. –  1amtoo1337 May 5 '11 at 16:06
    
Hey folks ive got it fixed. My problem was that i did not add a return inside the if-statement. The way i constructed my function it goes inside the function, checks if panAct is false(which it is by default) then deactivates the controls and sets panAct to true, the next if-statement checks for true and after that activates all the controls again. Ive added a return inside every statement and my checkbox to activate/deactivate panning while having features present works. –  1amtoo1337 May 5 '11 at 16:19
1  
@shitake - it looks like simo's answer to return the panAct variable was correct - you should click on the "Accept Answer" option –  geographika May 5 '11 at 16:31

This is my final working version of the function which ive now added to my Program. i think my boss will be making a joyful leap when he enters office tomorrow :). Thx @simo for pointing me in the right direction.

var panAct = new Boolean(); //panning activator
panAct = false; //panning not activated by default

//this is the function which is connected to the checkbox
//this gets fired when you check/uncheck the box

 function allowPan() {
    alert("in allowPan")
    alert("panAct:" + panAct);

    if(panAct == true){ 
        highlightCtrl.activate();
        selectedControl.activate();
        alert("controls activated!! Panning deactivated!!");
        panAct = false;
        return;
        }

    if(panAct == false){ 
        highlightCtrl.deactivate();
        selectedControl.deactivate();
        alert("controls deactivated!! Panning activated!!");
        panAct = true;
        return;
        }

    alert("panAct:" + panAct);

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.