Bergen88 Bergen88 - 7 months ago 19
Javascript Question

Polygon highlighting with Mapbox or Leaflet

I am trying to replicate polygon highlighting on mouseover event in mapbox.js or leaflet.js similar to the example below:

http://projects.nytimes.com/census/2010/explorer?view=raceethnicity&lat=40.6311&lng=-73.994&l=12

How does this work?

Answer

Using Leaflet, you simply have to define a function to set the style of the polygon on mouseover event. For example:

polygonLayer.on('mouseover', function (this) {
    this.setStyle({
        fillOpacity: 0,
        color: 'black'
        });
});