function _colorized_gmap_form_map_stylers in Colorized google maps block 7
Helper function. Create form elements for map styles.
1 call to _colorized_gmap_form_map_stylers()
- colorized_gmap_form_alter in ./
colorized_gmap.module - Implements hook_form_alter().
File
- ./
colorized_gmap.admin.inc, line 118 - Administrative page for colorized gmap module.
Code
function _colorized_gmap_form_map_stylers(&$form, &$form_state, $entity = NULL) {
$styles = NULL;
if (isset($entity)) {
// Get map styles and rebuild indexes.
$i = 1;
foreach ($entity->style as $item) {
$styles[$i] = $item;
$i++;
}
}
// List of available map features.
$feature_types = array(
'water' => 'Water',
'landscape' => 'Landscape',
'landscape.man_made' => 'Landscape (man made)',
'landscape.natural' => 'Landscape (natural)',
'landscape.natural.landcover' => 'Landscape (natural landcover)',
'landscape.natural.terrain' => 'Landscape (natural terrain)',
'road' => 'Road',
'road.highway' => 'Road (highway)',
'road.highway.controlled_access' => 'Road highway (controlled access)',
'road.arterial' => 'Road (Arterial)',
'road.local' => 'Road (local)',
'poi' => 'Poi',
'poi.park' => 'Poi (park)',
'poi.business' => 'Poi (business)',
'poi.attraction' => 'Poi (attraction)',
'poi.medical' => 'Poi (medical)',
'poi.school' => 'Poi (school)',
'poi.sports_complex' => 'Poi (sports complex)',
'poi.government' => 'Poi (government)',
'poi.place_of_worship' => 'Poi (place of worship)',
'administrative' => 'Administrative',
'administrative.country' => 'Administrative (country)',
'administrative.land_parcel' => 'Administrative (land parcel)',
'administrative.locality' => 'Administrative (locality)',
'administrative.neighborhood' => 'Administrative (neighborhood)',
'administrative.province' => 'Administrative (province)',
'all' => 'All',
'transit' => 'Transit',
'transit.line' => 'Transit (line)',
'transit.station' => 'Transit station',
'transit.station.airport' => 'Transit station (airport)',
'transit.station.bus' => 'Transit station (bus)',
'transit.station.rail' => 'Transit station (rail)',
);
// List of available map elements.
$elements = array(
'all' => 'All',
'geometry' => 'Geometry',
'geometry.fill' => 'Geometry fill',
'geometry.stroke' => 'Geometry stroke',
'labels' => 'Labels',
'labels.icon' => 'Labels icon',
'labels.text' => 'Labels text',
'labels.text.fill' => 'Labels text fill',
'labels.text.stroke' => 'Labels text stroke',
);
$form['settings']['colorized_map_styles'] = array(
'#theme' => 'colorized_gmap_table_form',
'#type' => 'fieldset',
'#weight' => 2,
'#title' => t('Map styles'),
'#prefix' => '<div id="gmap-ajax-wrapper">',
'#suffix' => '</div>',
'#header' => array(
t('Feature type'),
t('Element type'),
t('Stylers'),
t('Remove'),
),
'settings' => array(
'#tree' => TRUE,
),
);
// Map example div.
$form['settings']['markup'] = array(
'#type' => 'markup',
'#markup' => '<div id="colorized-gmap-content"></div>',
);
if (!$form_state['rebuild'] && !empty($styles)) {
$form_state['styles_count'] = count($styles);
$form_state['styles_removed'] = array();
}
if (empty($form_state['styles_count'])) {
$form_state['styles_count'] = 1;
$form_state['styles_removed'] = array();
}
// Add more|remove row table functionality.
for ($i = 1; $i < $form_state['styles_count'] + 1; $i++) {
if (in_array($i, $form_state['styles_removed'])) {
continue;
}
$form['settings']['colorized_map_styles']['settings'][$i]['featureType'] = array(
'#type' => 'select',
'#options' => $feature_types,
'#default_value' => !empty($styles[$i]['featureType']) ? $styles[$i]['featureType'] : '',
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['elementType'] = array(
'#type' => 'select',
'#options' => $elements,
'#default_value' => !empty($styles[$i]['elementType']) ? $styles[$i]['elementType'] : '',
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['stylers'][0] = array(
'#tree' => TRUE,
'color' => array(
'#title' => t('Color'),
'#type' => 'textfield',
'#size' => 4,
'#default_value' => !empty($styles[$i]['stylers'][0]['color']) ? $styles[$i]['stylers'][0]['color'] : NULL,
'#attributes' => array(
'class' => array(
'edit_color_input',
),
),
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'event' => 'textfield_change',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['stylers'][1] = array(
'visibility' => array(
'#type' => 'select',
'#title' => t('Visibility'),
'#default_value' => !empty($styles[$i]['stylers'][1]['visibility']) ? $styles[$i]['stylers'][1]['visibility'] : NULL,
'#options' => array(
'on' => 'On',
'off' => 'Off',
'simplified' => 'simplified',
),
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['stylers'][2] = array(
'saturation' => array(
'#type' => 'textfield',
'#size' => 4,
'#title' => t('Saturation'),
'#default_value' => !empty($styles[$i]['stylers'][2]['saturation']) ? $styles[$i]['stylers'][2]['saturation'] : NULL,
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['stylers'][3] = array(
'lightness' => array(
'#type' => 'textfield',
'#size' => 4,
'#title' => t('Lightness'),
'#default_value' => !empty($styles[$i]['stylers'][3]['lightness']) ? $styles[$i]['stylers'][3]['lightness'] : NULL,
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['stylers'][4] = array(
'weight' => array(
'#type' => 'textfield',
'#size' => 1,
'#title' => t('Weight'),
'#default_value' => !empty($styles[$i]['stylers'][4]['weight']) ? $styles[$i]['stylers'][4]['weight'] : NULL,
'#ajax' => array(
'callback' => 'colorized_gmap_styles_update',
'wrapper' => 'colorized-gmap-content',
'progress' => array(
'type' => 'none',
),
),
),
);
$form['settings']['colorized_map_styles']['settings'][$i]['remove'] = array(
'#type' => 'checkbox',
);
}
// Buttons.
$form['settings']['ajax_buttons'] = array(
'#type' => 'fieldset',
'#weight' => 3,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['settings']['ajax_buttons']['add_more'] = array(
'#type' => 'submit',
'#value' => t('Add More'),
'#submit' => array(
'colorized_gmap_form_add_row',
),
'#ajax' => array(
'callback' => 'colorized_gmap_update',
'wrapper' => 'gmap-ajax-wrapper',
),
);
$form['settings']['ajax_buttons']['remove_row'] = array(
'#type' => 'submit',
'#value' => t('Remove Row'),
'#submit' => array(
'colorized_gmap_form_remove_row',
),
'#ajax' => array(
'callback' => 'colorized_gmap_update',
'wrapper' => 'gmap-ajax-wrapper',
),
);
}