gmap_macro_builder.module

Tracking 7.x-2.x branch
  1. drupal
    1. 5 contributions/gmap/gmap_macro_builder.module
    2. 6 contributions/gmap/gmap_macro_builder.module
    3. 7 contributions/gmap/gmap_macro_builder.module

GMap Macro Builder

A dynamic interface to assist in the creation of gmap macro tags.

Functions & methods

NameDescription
gmap_macro_builder_formMacro builder form.
gmap_macro_builder_helpImplemenation of hook_help().
gmap_macro_builder_menuImplementation of hook_menu().
gmap_macro_builder_permissionImplementation of hook_perm().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * GMap Macro Builder
  5. *
  6. * A dynamic interface to assist in the creation of gmap macro tags.
  7. */
  8. /**
  9. * Implemenation of hook_help().
  10. */
  11. function gmap_macro_builder_help($path, $arg) {
  12. switch ($path) {
  13. case 'map/macro':
  14. return t('You can use this interface to create a map macro suitable for pasting into a node or any other place that accepts a GMap macro.');
  15. }
  16. }
  17. /**
  18. * Implementation of hook_perm().
  19. */
  20. function gmap_macro_builder_permission() {
  21. return array(
  22. 'create gmap macro' => array(
  23. 'title' => t('Create gmap macro'),
  24. 'description' => t('Allows user to create a gmap macro for insertion into content.'),
  25. )
  26. );
  27. }
  28. /**
  29. * Implementation of hook_menu().
  30. */
  31. function gmap_macro_builder_menu() {
  32. $items['map/macro'] = array(
  33. 'type' => MENU_NORMAL_ITEM,
  34. 'title' => 'Build a GMap macro',
  35. 'access arguments' => array('create gmap macro'),
  36. 'page callback' => 'drupal_get_form',
  37. 'page arguments' => array('gmap_macro_builder_form'),
  38. );
  39. return $items;
  40. }
  41. /**
  42. * Macro builder form.
  43. * @param &$form_state
  44. * The $form_state array.
  45. * @param $settings
  46. * Additional settings to apply to the macro map.
  47. * @param $hide
  48. * Fields to hide from the map. (See code for details.)
  49. * Suggestions for better ways of doing this welcome!
  50. */
  51. function gmap_macro_builder_form($form, &$form_state, $settings = array(), $hide = array()) {
  52. $path = drupal_get_path('module', 'gmap');
  53. $form['macroform'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Gmap macro creation'),
  56. '#theme' => 'gmap_macro',
  57. );
  58. $form['macroform']['mapdiv'] = array(
  59. '#type' => 'gmap',
  60. '#map' => 'macro_map',
  61. '#settings' => array_merge(array(
  62. 'points' => array(),
  63. 'pointsOverlays' => array(),
  64. 'behavior' => array(
  65. 'dynmarkers' => TRUE,
  66. ),
  67. ), $settings),
  68. );
  69. $defaults = array_merge(gmap_defaults(), $settings);
  70. $form['macroform']['overlayedit'] = array(
  71. '#type' => 'gmap_overlay_edit',
  72. '#map' => 'macro_map',
  73. );
  74. $form['macroform']['mapid'] = array(
  75. '#type' => 'textfield',
  76. '#title' => t('Map id attribute'),
  77. '#description' => t('If you need to access this map from a script, you can assign a map ID here.'),
  78. '#default_value' => '',
  79. );
  80. gmap_widget_setup($form['macroform']['mapid'], 'mapid', 'macro_map');
  81. // @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui.
  82. $baselayers = array();
  83. gmap_module_invoke('baselayers', $baselayers);
  84. $options = array();
  85. foreach ($baselayers as $name => $layers) {
  86. $options[$name] = array();
  87. foreach ($layers as $k => $v) {
  88. // @@@TODO: Only show the enabled ones?
  89. $options[$name][$k] = $v['title'];
  90. }
  91. }
  92. $form['macroform']['maptype'] = array(
  93. '#type' => 'select',
  94. '#title' => t('Map type'),
  95. '#default_value' => $defaults['maptype'],
  96. '#options' => $options,
  97. );
  98. gmap_widget_setup($form['macroform']['maptype'], 'maptype', 'macro_map');
  99. // @@@TODO: We need to allow choosing an alternate set of baselayers...
  100. $form['macroform']['controltype'] = array(
  101. '#type' => 'select',
  102. '#title' => t('Controls'),
  103. '#options' => drupal_map_assoc(array('None', 'Small', 'Large', 'Android')),
  104. '#required' => FALSE,
  105. '#default_value' => $defaults['controltype'],
  106. );
  107. gmap_widget_setup($form['macroform']['controltype'], 'controltype', 'macro_map');
  108. $form['macroform']['address'] = array(
  109. '#type' => 'gmap_address',
  110. '#map' => 'macro_map',
  111. '#title' => t('Address'),
  112. '#default_value' => '',
  113. );
  114. $form['macroform']['latlong'] = array(
  115. '#type' => 'gmap_latlon',
  116. '#map' => 'macro_map',
  117. '#title' => t('The Latitude and Longitude of the centre of the map'),
  118. '#default_value' => $defaults['latlong'],
  119. '#size' => 50,
  120. );
  121. $form['macroform']['width'] = array(
  122. '#type' => 'textfield',
  123. '#title' => t('Map width'),
  124. '#default_value' => $defaults['width'],
  125. '#size' => 25,
  126. '#maxlength' => 25,
  127. '#description' => t('The map width, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
  128. );
  129. gmap_widget_setup($form['macroform']['width'], 'width', 'macro_map');
  130. $form['macroform']['height'] = array(
  131. '#type' => 'textfield',
  132. '#title' => t('Map height'),
  133. '#default_value' => $defaults['height'],
  134. '#size' => 25,
  135. '#maxlength' => 25,
  136. '#description' => t('The map height, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
  137. );
  138. gmap_widget_setup($form['macroform']['height'], 'height', 'macro_map');
  139. $form['macroform']['alignment'] = array(
  140. '#type' => 'select',
  141. '#title' => t('Alignment'),
  142. '#options' => drupal_map_assoc(array('None', 'Right', 'Left', 'Center')),
  143. '#attached' => array(
  144. 'js' => array(
  145. "$path/js/align.js" => array('weight' => 2),
  146. ),
  147. ),
  148. );
  149. gmap_widget_setup($form['macroform']['alignment'], 'align', 'macro_map');
  150. $form['macroform']['zoom'] = array(
  151. '#type' => 'select',
  152. '#title' => t('The current magnification of the map'),
  153. '#default_value' => $defaults['zoom'],
  154. '#options' => drupal_map_assoc(range(0, 17)),
  155. );
  156. gmap_widget_setup($form['macroform']['zoom'], 'zoom', 'macro_map');
  157. $form['macroform']['macro'] = array(
  158. '#type' => 'gmap_macrotext',
  159. '#map' => 'macro_map',
  160. '#default_value' => '',
  161. '#title' => t('Macro text'),
  162. );
  163. foreach ($hide as $field => $mode) {
  164. if (isset($form['macroform'][$field])) {
  165. if ($mode == 1) {
  166. $form['macroform'][$field]['#type'] = 'hidden';
  167. $form['macroform'][$field]['#value'] = $form['macroform'][$field]['#default_value'];
  168. }
  169. elseif ($mode == 2) {
  170. $form['macroform'][$field]['#prefix'] = '<div style="display: none;">';
  171. $form['macroform'][$field]['#suffix'] = '</div>';
  172. }
  173. }
  174. }
  175. return $form;
  176. }