2 require_once ('leaflet.formatters.inc');
5 * Implements hook_theme().
7 function leaflet_theme($existing, $type, $theme, $path) {
9 'leaflet_map' => array(
10 'arguments' => array('map_id' => NULL
, 'height' => '400px'),
11 'template' => 'leaflet_map',
17 * Implements hook_library().
19 function leaflet_library() {
20 $libraries['leaflet'] = array(
22 'website' => 'http://leaflet.cloudmade.com',
27 'data' => 'L_ROOT_URL = "' .
base_path() .
libraries_get_path('leaflet') .
'/dist/";',
28 'group' => JS_LIBRARY
,
33 'data' => libraries_get_path('leaflet') .
'/dist/leaflet.js',
34 'group' => JS_LIBRARY
,
39 libraries_get_path('leaflet') .
'/dist/leaflet.css' => array(
43 libraries_get_path('leaflet') .
'/dist/leaflet.ie.css' => array(
52 $libraries['leaflet-drupal'] = array(
53 'title' => 'Leaflet initialization',
54 'website' => 'http://drupal.org/project/leaflet',
55 'version' => '7.x-1.x',
57 drupal_get_path('module', 'leaflet') .
'/leaflet.drupal.js' => array(),
59 'dependencies' => array(
60 array('leaflet', 'leaflet'),
68 * Load all Leaflet required client files and return markup for a map.
71 * @param array $features
72 * @param string $height
74 * @return string map markup
76 function leaflet_render_map($map, $features = array(), $height = '400px') {
77 $map_id = drupal_html_id('leaflet_map');
78 drupal_add_library('leaflet', 'leaflet-drupal');
80 // Allow map definitions to provide a default icon
81 if (isset($map['icon']['iconUrl'])) {
82 foreach ($features as
&$feature) {
83 if (!isset($feature['icon'])) {
84 $feature['icon'] = $map['icon'];
92 'features' => $features,
95 drupal_add_js(array('leaflet' => array($settings)), 'setting');
97 return theme('leaflet_map', array('map_id' => $map_id, 'height' => $height));
101 * Get all avaialble Leaflet map definitions.
105 function leaflet_map_get_info($map = NULL
) {
106 static
$drupal_static_fast;
107 if (!isset($drupal_static_fast)) {
108 $drupal_static_fast['leaflet_map_info'] = &drupal_static(__FUNCTION__
);
110 $map_info = &$drupal_static_fast['leaflet_map_info'];
112 if (empty($map_info)) {
113 if ($cache = cache_get("leaflet_map_info")) {
114 $map_info = $cache->data
;
117 $map_info = module_invoke_all('leaflet_map_info');
119 // Let other modules alter the map info.
120 drupal_alter('leaflet_map_info', $map_info);
122 cache_set("leaflet_map_info", $map_info);
129 elseif (isset($map_info[$map])) {
130 return $map_info[$map];
135 * Implements hook_leaflet_map_info() to return a default map.
139 function leaflet_leaflet_map_info() {
143 'label' => 'OSM Mapnik',
144 'description' => t('Leaflet default map.'),
151 'scrollWheelZoom' => TRUE
,
152 'doubleClickZoom' => TRUE
,
153 'zoomControl' => TRUE
,
154 'attributionControl' => TRUE
,
155 'trackResize' => TRUE
,
156 'fadeAnimation' => TRUE
,
157 'zoomAnimation' => TRUE
,
158 'closePopupOnClick' => TRUE
,
162 'urlTemplate' => 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
164 'attribution' => 'OSM Mapnik'