simplegeo / polymaps

Polymaps is a free JavaScript library for making dynamic, interactive maps in modern web browsers.
http://polymaps.org/
Other
1.6k stars 213 forks source link

Attaching event listeners to geoJson layer #138

Closed renanmzmendes closed 10 years ago

renanmzmendes commented 10 years ago

I can't seem to figure out how to listen to a click event on a geoJson layer.

It seems that the way to do it is through dispatch (http://polymaps.org/docs/dispatch.html) but I couldn't understand the documentation. Can someone provide me with an example? Please, assume I have an array of features already in the right format, and that I did the following in order to add them to my map:

var geoJsonLayer = po.geoJson().features(features)
map.add(geoJsonLayer)

I appreciate the help! Thanks

renanmzmendes commented 10 years ago

Looking at this post (http://thinkwhere.wordpress.com/2011/08/02/pubs-in-england-how-to-do-it-with-polymaps-and-geocommons-filters/), I found the answer. You need to add the listener directly to the element attribute in the feature.