As some of you may already know, Newsweek / The Daily Beast has been using CartoDB for some time now, and as such today’s blog post comes from Michael Keller of Newsbeast labs. We’d also like to take the opportunity thank Michael for his amazing contributions to the CartoDB community. Thanks!
I have been reusing code from former projects and so it was about time I standardized them into reusable templates with Leaflet.js. I released them on Github this week.
I made three categories: basic map with hover states, hover states + hover infowindow, and all of that with templated infowindows using Underscore.js.
In each of these categories you’ll see a template for a point map, a polygon map, and a map with both points and polygons.
On point + polygon templates, the polygon hover state turns off when you hover over a point.
Hover windows follow the mouse and respect the boundaries of the map-canvas. I find it most useful to have hover windows close to the mouse so your eye doesn’t have to leave that map region to see that region’s details
Templates with Underscore.js hover windows include sample formatHelper functions to act as a formatting layer between your data values and how you want them to display. For instance, you could store all your feature attributes as boolean variables and run them through various formatHelpers functions to return nice display strings.
The hover states work by storing a simplified GeoJSON representation of that feature as a feature attribute. On featureOver, that GeoJSON is plotted as a vector using Leaflet.js.
Point + polygon templates add a secondary style class to hover windows when hovering over points to differentiate from polygons.
If you have any questions, I’m at @mhkeller. If you have improvements, pull requests at http://github.com/mhkeller/cartodb-templates
When CARTO was founded in 2012, the main areas of focus were conservation and biodiversity projects. Fast forward exactly 10 years and CARTO is proud to be one of the leadi...Use Cases
The Great Resignation, The Big Quit or The Big Reshuffle? The employment landscape has been given many names since early 2021, but they all have one thing in common. They a...Use Cases
On the 26th July it was announced that the United Kingdom would be hosting 2023’s Eurovision Song Contest. No fewer than 13 cities are expected to bid for the honor of host...Use Cases
Please fill out the below form and we'll be in touch real soon.