Skip to content

Instantly share code, notes, and snippets.

@steffenr
Last active January 3, 2016 12:19
Show Gist options
  • Save steffenr/8462375 to your computer and use it in GitHub Desktop.
Save steffenr/8462375 to your computer and use it in GitHub Desktop.
Use hook_leaflet_views_alter_points_data_alter to add category based icon to your markers shown with leaflet_views.
<?php
/**
* Implements hook_leaflet_views_alter_points_data_alter().
*/
function fewo_map_leaflet_views_alter_points_data_alter($result, &$points) {
// Get node object of result.
$wrapped_node = entity_metadata_wrapper('node', $result->nid);
// Check if we have a category attached to node.
$category = $wrapped_node->field_sight_category->value();
if (!empty($category)) {
// Check if we have a custom category icon for taxonomy term.
$category_icon = $wrapped_node->field_sight_category->field_sight_icon->value();
if (!empty($category_icon)) {
// Create url for usage as marker icon.
$icon_url = file_create_url($category_icon['uri']);
// Set icon as marker icon for point.
$points[0]['icon']['iconUrl'] = $icon_url;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment