Hello All,
I am trying to get a custom widget(CW) to work that uses a map click event. The widget works as standalone but if also using the OOTB measurement widget(MW) I get weird behavior. If I use the OOTB MW before I use the CW then I get expected behavior for both tools. However, if I use the CW followed by the MW, when I close the CW the symbol it uses is cleared from the map but when using the MW the symbol replaces esri greenpin, the line segments disappear on dbl-clicks, and when MW is closed, the CW symbol remains. Any ideas on how to resolve other than re-implement the OOTB MW(and I did not want to edit the OOTB MW code)? I thought by using onClose() in CW to remove graphic/clear
map would resolve since graphic was removed(but looks like both widgets are bound to event).
Thanks in advance,
Mona
Solved! Go to Solution.
Mona,
The var for the event handler is in the wrong position:
this.own(tmp = on(myMap, "click", lang.hitch(this, this.on_myMapClick)));
Mona,
I sounds like you are forgetting to remove to map click event handler on your CW onClose Event. When you add the map on click event you can assign the click event handler to a var and then your you onClose you can call the .remove() method on the event.
Forgot to add…I received the error:
fail to close widget XY Tool. TypeError: Object doesn't support property or method 'remove'
So I am still researching…
Mona,
Are you assigning a event handler var to your map click event? Maybe you should have some code here to make this easier.
Robert,
My 1st response with code didn't make it through I guess...apologies.
startup: function () {
...
tmp = this.own(on(myMap, "click", lang.hitch(this, this.on_myMapClick)));
...
}
onClose: function() {
console.log('onClose');
myMap.graphics.clear();
//console.dir(myMap);
//console.dir(graphicsLayer);
if(graphicsLayer)
graphicsLayer.remove(this._myMarkerSymbol);
myMap.setInfoWindowOnClick(true);
tmp.remove();
},
Mona,
The var for the event handler is in the wrong position:
this.own(tmp = on(myMap, "click", lang.hitch(this, this.on_myMapClick)));
Should have looked up syntax...
Thanks so much Robert I really appreciate it!
Robert,
If I close the widget and re-open to use, the widget is no longer functional.
If I wanted to re-use the tool n times after it is closed, is there another suggested workflow to implement?
Thanks!
Mona,
On open you need to re add the event listener if the tmp is null.
Robert,
Great! You’ve been awesome!