1

It's the first time I'm trying to make a Leaflet plugin (also first time with Github).

With the plugin you can select a box on a map. When the box is drawn, I want to fire an event.

I can launch an event like:

map.fire("selected");

and then I can see it in my script with

map.on("selected", function() { .... });

But what about firing a custom event like:

map.fire("areaSelected").

I tried to search in the Documentation, but didn't find a way...

A jsFiddle: Fiddle The github page: Github

1 Answer 1

0

There's an unrelated error that's breaking this jsfiddle:

enter image description here

2
  • OK, strange. Maybe it was the old fiddle. I only get the error: "Uncaught TypeError: Cannot read property 'fire' of undefined" when I'm resize the square. It's because I cant fire events like map.fire("test"); or map.fire("areaSelected"); Thank you for your help. jsfiddle.net/zoutepopcorn/UQ9G2/5 doesnt fire the above error Jul 3, 2014 at 10:04
  • 1
    That isn't a problem with 'fire': you're not correctly managing the map variable, so it's undefined when you're trying to call it. Please read other plugins that correctly manage the map reference rather than juggling it as a global.
    – tmcw
    Jul 3, 2014 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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