I'm looking for an approach to extend Leaflet Views so that I can customise map icons for content based on a field criteria. My current use case is listing a number of venues on a map and using a different icon for each venue based on a taxonomy term field.

Approaches I'm currently looking at:
- Custom formatter for the geofield field in the content type.
- Rewriting the geodata field in the Views UI interface (Not sure if this will work given the Leaflet Views Plugin)

Any other ideas for an approach?

I'm going to take a closer look at the code in the leaflet_views_plugin_style class to start with and update this issue with what I find. Any input would be appreciated.

Comments

gollyg’s picture

Overriding the render method of that class, and adding the following code, will allow you to place custom markers:

$points[0]['icon']['iconUrl'] = 'sites/default/files/arrow.png';

Obviously, needs to be wrapped in conditional logic based upon a variable in the $result variable.

masher’s picture

The IP Geolocation Views and Maps module gives you different icon types. You can designate any one field as a location differentiator.

http://drupal.org/project/ip_geoloc

cossovich’s picture

StatusFileSize
new4.12 KB

Thanks @gollyg.

I ran into some problems extending the leaflet_views_plugin_style class but I did get a proof of concept working after hacking on the leaflet_views module. Attached is a patch with the hack (I don't recommend using this patch; it's hard-coded to custom fields and includes multiple crimes against Drupal), I've only included it here to demonstrate what I'm trying to achieve.

@masher, I'm going to look at the IP Geolocation Views and Maps views plugins to see their approach.

gollyg’s picture

That seems to me the correct approach, but applied to a plugin that extends this plugin. Could you get view to recognise your plugin?

cossovich’s picture

@gollyg PHP ran out of memory when I enabled (or disabled) the module with my views style plugin. I'm going to move forward with the hack and do some more research into how I might extend the Leaflet views plugin.

revagomes’s picture

Status: Active » Needs review
StatusFileSize
new7.64 KB

I think this is a good way to achieve this goal. Feel free to improve if needed.

osopolar’s picture

What about using tokens? See #1918170: Use tokens in icon url.

gcb’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

Looks like this is duplicating functionality offered by #1812748, #1882806 and some others. Thanks for the work, look for one of these solutions to be rolled into a release upcoming soon.

antims’s picture

How to use replace pattren in leaflet views for icon field ?