Adding extra styles to taxonomy terms in openlayers
Primary tabs
Introduction
This tutorial is a direct follow on from Contextual Filters where a number of requests asked about how to add a number of styles to the contextual filter example.
I'll be using one to three stars rating as an example on top of the Springfield restaurants tutorial. Each restaurant will be represented as a star rating on the map itself.
Synopsis
To implement this we will be
- Adding the stars to the openlayers styles
- Creating a new taxonomy field to represent the star ratings
- Making clones of the openlayers display and adding an extra filter for each star
- Enabling the view's displays in openlayers as layers
Pre-requirsites
Contextual Filters must be completed first because it also contains all the configuration and setup information.
Method
- Add the star images to the openlayers styles
- Create a new taxonomy vocabulary for the star ratings and add the rating terms to that vocabulary
- Go into the content type and add a new term reference field and assign it to the correct vocabulary
- Now edit the contents to assign a star rating to the taxonomy field
-
Go the openlayers data overlay display in the views settings
- I'm going to change the display name to one stars
-
In the filter criteria section add the taxonomy field that you created in the content type. In my case it was called Restaurant Rating
- Select the rating for the vocabulary
- And Dropdown for the selection type
- In the following overlay window, select the appropriate rating term, in my case for this display it will be one stars
- Clone this display and rename it to two stars
- Go down to the filter criteria and change the taxonomy term to two stars
- And then clone this display again and change the taxonomy term filter to three stars
-
Edit your openlayers map, select the Layers & Styles section
- And enable and activate the layers that you created from your view's displays
- And select the appropriate style for each layer
- That should be it and the default dot should now be replaced by the star ratings.
Conclusion
This tutorial was a direct follow on from Contextual Filters, where we spent more time on creating additional styles, mapping those styles to taxonomy terms via the views displays.
You do need to manually create the extra views displays and the extra filter criterias which some people may find a little clunky so I'm going to checkout the same solution using openlayers taxonomy module to see if that will be a more graceful approach.
Thanks for watching and remember don't forget to flush your cache!
Latest Updates
Recent comments
Recent Tweets
- New post: Posting location co-ordinates to a drupal service - Part 2 http://t.co/MQhlVKBNKC — 1 month 1 week ago
- New post: Posting location co-ordinates to a drupal service - Part 1 http://t.co/2xlYgqFaJ0 — 1 month 1 week ago
- New post: Connecting a drupal service with a mobile application - Part 2 http://t.co/01cFtAunDs — 1 month 1 week ago
- New post: Using drupal services to connect to mobile applications - Part 1 http://t.co/VEURftHCef — 1 month 1 week ago
- New post: Creating Drupal 7 video gallery http://t.co/HvpKU7uT — 3 months 1 week ago









Comments
Very Nice
Hi Nigel,
I just saw your new tutorial now. Fantastic, it´s almost the same I´ve done.
But it´s easier to understand the way it´s done by watching your tutorial, than reading it the way I explained it. ;)
Very nice and thank you. :)
Perhaps it helps others. An convenient way could be, putting this all in a Feature and offer it for download, as you done before.
All the many layers and styles and maps could be very confusing for beginners and perhaps frustrate a lot of them.
It took´s me too, a lot of trial and errors, a lot of sweating to brings it to work. Your tutorials helped me going the way with Drupal and OpenLayers further. :)
Rui
Thanks!
Thanks for sharing this, I found this set of tutorials incredibly useful, I will admit that it’s a bit clunky and would be more elegant it could you could drive the icons dynamically (I’m sure that there will be a way in the future if not already) but the fact is this method works, and works very well.
Im fairly new to Drupal, and I only discovered your site this week but I really like the way you explain Drupal.
Cheers!
OpenLayers videos
Love the videos, very helpful for using less than perfectly documented modules.
I especially like the edited in chicken noises.
Seriously though, keep up the good work.
AlanH, (Los Angeles)
exposed filter instead of menu links
Hi Nigel,
have you ever tried to use an exposed filter for the content type choice instead of a menu block for filter navigation?
I like more the dropdown filter. But the exposed filter don`t filter the results.
By choosing a content type from the dropdown filter all markers disappear.
Any idea what`s wrong?
kind regards
Franky (DE)
This is a good question, in others words I haven't got a clue
but I'm not to sure how well exposed filters and contextual filters will play together. It may be worth disabling your contextual filters to try this out. When I get the chance I'll see if this is supported in the view's Openlayer overlay.
My implementation is still quite basic for what can be done such as ajax forms and filtering on more than one contextual filter.
Ok, verified exposed filters do work
though the default exposed filters will point you to the content type instead of the map address. I cloned the block overlay in my view and adjusted that to enable the exposed filter.
Things to watch out for are, for your added flter you will need to rewrite the link addess the same way I did for the menu and change the format to text instead of link or else that will overide your rewrite output settings.
All the best.
openlayers taxonomy module
Have someone testet the "openlayers taxonomy module"?
What is the difference to this tutorial?
A few of us tried to get it working a while ago without success
and the module has not been updated since 2011, but you are welcome to try it out to see if you have better luck.
But to answer your question the openlayers taxonomy module seems similar and creates the openlayers overslays automatically whereas you have to create then manually in my tutorial. Though saying that there is a better solution using Openlayers dynamic styles which removes the need for the additional Openlayers overlays and traditional Openlayers styles.
filter out all one, two or three star restaurants
Thank you for your nice and easy tutorial, Nigel.
It works fine with the content type filter.
But how can you filter out all one, two or three star restaurants?
I am not able to get the "Restaurant Price Taxonomy"-Filter working in the view.
If i try to implement the filter criteria "field_restaurant_price" the results are always zero.
No content will be shown in the map.
How would you solve filtering to the "Restaurant Price Taxonomy"?
Kind regards
Lars
This should work by repeating the process with your vocabulary .
For example if I wanted to wanted the filter by the Star Ratings terms, I would created / clone new Openlayers overlay views and select the vocabulay from the contextual filters and then enable those overlays in the Openlayer's Map layers section. In the views menu you will also need to select your vocabulary in the filter section.
So this will act the same way as the restaurant type and group your Openlayers styles (images) by their taxonomy term id.
No sure what your comment "content type filter" means because I'im filtering via taxonomy term contextual filters. There are probably a number of way of interpreting this question, hopefully I selected the right one if not let me know.
All the best.
Pages
Add new comment