I am creating a data editing map using OpenLayers. I have two main states that the map editor can be in - editing existing features, or adding new ones. When a user clicks the "Edit Features" button, the editOnClick
event is registered to the map. When the user clicks the "Add Feature" button, the drawFeatureOnClick
event is registered to the map. I want to include a simple if
statement to prevent OpenLayers from registering the same event multiple times, as well as remove the other button's event if it is active. Here's some pseudocode for the edit button:
$("#editfeatures").button({text: "Edit Features"}).click(function() {
if (<editOnClick not already registered>) {
map.events.register("click", map, editOnClick);
}
if (<drawFeatureOnClick currently registered>) {
map.events.unregister("click", map, drawFeatureOnClick);
}
}
I tried inspecting the map object using the Chrome debug tools, but I couldn't find an obvious way to tell if an event is currently registered on the map. How can I see what event listeners are registered on the map?