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 am attempting to allow for the pop-up to be toggled on and off by pressing a checkbox. Here are some snippets of the code:

var clickHandler

function popupOn(evt){
var query = new esri.tasks.Query();
query.geometry = pointToExtent(map,evt.mapPoint,10);
var deferred = featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
}

function clickConnect(connect){
if(connect){
//perform the identify task on click 
clickHandler = dojo.connect(map, "onClick", popupOn);
}
else{
//disconnect the click handler 
dojo.disconnect(clickHandler);
clickHandler = null;
}
}

<input type='checkbox' data-dojo-type="dijit.form.CheckBox" checked="checked" data-dojo-props="onClick: dojo.connect('true')"/><label>Tick here to turn selecting on.</label><br/>
share|improve this question
    
What type of error are you getting? –  MLowry Jun 15 '12 at 20:08
    
It's not working, in short. Basically, I've added this code and now the popup does not work at all. However, prior to attempting to add the toggle function, the popup worked just fine. It also seems like part of the post was truncated. This should be on the end around the "tick here to turn selecting on": type='checkbox' data-dojo-type="dijit.form.CheckBox" checked="checked" data-dojo-props="onClick: dojo.connect('true')" –  jwx Jun 15 '12 at 20:14

1 Answer 1

Well, there are a bunch of things wrong with this.

1) You're firing "dojo.connect('true')" whenever the checkbox is checked, which does nothing. The first argument to dojo.connect should be an object and the second argument should be the name of an event to listen for. Given the fact that you've defined a "clickConnect" event anyway, it seems like you intended to execute this function whenever the box is checked. In that case, you'd want:

<input type='checkbox' data-dojo-type="dijit.form.CheckBox" checked="checked" data-dojo-props="onClick: clickConnect(true)"/>

...however, this means that any time the checkbox is clicked (regardless of whether or not it's checked), you're creating a new onClick event handler for the map. Not only is this redundant, but you're also never executing the else block of your clickConnect function, since you're always passing true as the argument.

2) It's unclear what your intention really is. Are you trying to allow the checkbox to toggle the InfoWindow itself on or off, or do you want the checkbox to control whether or not an InfoWindow will appear when a user clicks the map?

My guess is that when a user clicks on the map, unless the checkbox is unchecked, you always want to execute a query and display the results in an InfoWindow. I also assume you want any existing InfoWindow to disappear whenever you uncheck the checkbox. Given these assumptions, the following code should work (although it is untested):

var clickHandler;

function popupOn(evt){
    var query = new esri.tasks.Query();
    query.geometry = pointToExtent(map,evt.mapPoint,10);
    var deferred = featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
    map.infoWindow.setFeatures([deferred]);
    map.infoWindow.show(evt.mapPoint);
}

function clickConnect(connect){
    if(connect){
        clickHandler = dojo.connect(map, "onClick", popupOn);
    } else {
        //disconnect the click handler 
        dojo.disconnect(clickHandler);
        clickHandler = null;
    }
}

function checkboxClicked(checkbox) {
    if (checkbox && checkbox.checked) {
        clickConnect(true);
    } else {
        map.infoWindow.hide();
        clickConnect(false);
    }
}

// Call clickConnect(true) after the map loads (assumes 'map' is your JS API map object):
dojo.connect(map, "onLoad", function(){ clickConnect(true); });

....

<input type='checkbox' data-dojo-type="dijit.form.CheckBox" checked="checked" data-dojo-props="onClick: function() { checkboxClicked(this); }"/><label>Tick here to turn selecting on.</label><br/>
share|improve this answer
    
Thanks for getting back, but I managed to figure out what the issue I was having was. Apparently one snippet of code I didn't include here was pretty key. Once I started working with that bit of code I got it figured out. –  jwx Jun 15 '12 at 22:44

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.