Commit 34ab3971 authored by Kevin Abel's avatar Kevin Abel
Browse files

Move Google Map styles from JS into PHP to share with other templates

This allows the styles to be used for static map rendering.
parent 1fd4df87
......@@ -54,6 +54,21 @@ class UNL_TourMap_GoogleMap
* @var DomDocument()
*/
public $tile_resource;
/**
* JSON uptimized array of Googe Map Styles
* @see https://developers.google.com/maps/documentation/javascript/reference#MapTypeStyle
* @see http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html
*
* @var array
*/
public $styles = array(
array('featureType' => 'poi', 'elementType' => 'labels', 'stylers' => array(array('visibility' => 'off'))),
array('featureType' => 'landscape', 'elementType' => 'labels', 'stylers' => array(array('visibility' => 'off'))),
array('featureType' => 'poi', 'elementType' => 'geometry', 'stylers' => array(array('lightness' => 70))),
array('featureType' => 'landscape.man_made', 'elementType' => 'geometry', 'stylers' => array(array('gamma' => 0.4))),
array('featureType' => 'road.highway', 'stylers' => array(array('lightness' => 70))),
);
public $options = array();
......@@ -114,4 +129,30 @@ class UNL_TourMap_GoogleMap
{
return 'Nebraska Union';
}
public function getEncodedStyles($forUrl = false)
{
if ($forUrl) {
$params = array();
foreach ($this->styles as $style) {
$param = 'feature:' . $style['featureType'];
if (isset($style['elementType'])) {
$param .= '|element:' . $style['elementType'];
}
foreach ($style['stylers'] as $styler) {
foreach ($styler as $key => $value) {
$param .= '|' . $key . ':' . $value;
}
}
$params[] = urlencode($param);
}
return 'style=' . implode('&style=', $params);
}
return json_encode($this->styles);
}
}
\ No newline at end of file
......@@ -105,12 +105,7 @@
zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL, position: google.maps.ControlPosition.TOP_LEFT },
panControl : false,
scrollwheel : false,
styles: [
{ "featureType": "poi", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "landscape", "elementType": "labels", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "landscape.man_made", "elementType": "geometry", "stylers": [ { "gamma": 0.4 } ] },
{ "featureType": "road.highway", "stylers": [ { "lightness": 77 } ] }
]
styles: UNLTourMap.styles
},
i = 0,
......
......@@ -67,6 +67,7 @@ WDN.loadCSS('<?php echo UNL_TourMap::getURL(); ?>css/map.css');
UNLTourMap.mapMaxZoom = <?php echo (int)$context->mapMaxZoom; ?>;
UNLTourMap.centerLat = <?php echo (float)$context->center->lat; ?>;
UNLTourMap.centerLng = <?php echo (float)$context->center->lng; ?>;
UNLTourMap.styles = <?php echo $context->getRawObject()->getEncodedStyles() ?>;
<?php if (isset($context->tile_resource)): ?>
UNLTourMap.minx = <?php echo (float)$context->options['minx']; ?>;
UNLTourMap.miny = <?php echo (float)$context->options['miny']; ?>;
......
<?php
/* @var $context UNL_TourMap_GoogleMap */
$map_options = array();
$map_options['center'] = $context->center->lat.','.$context->center->lng;
$map_options['zoom'] = $context->zoom;
$map_options['size'] = (isset($context->options['size']))? urlencode($context->options['size']):'960x620';
$map_options['size'] = (isset($context->options['size']))? urlencode($context->options['size']):'640x480';
$map_options['maptype'] = $context->type;
$map_options['sensor'] = 'false';
$map_options['markers'] = 'color:red%7C'.$context->center->lat.','.$context->center->lng;
$map_options['markers'] = urlencode('icon:' . $controller->getURL() . 'images/markers/google/building.png|' . $context->center->lat.','.$context->center->lng);
$url = UNL_TourMap::addURLParams('http://maps.google.com/maps/api/staticmap', $map_options);
$url .= '&' . $context->getRawObject()->getEncodedStyles(true);
?>
<a href="<?php echo $controller->getURL(); ?>" title="Go to the full featured UNL campus maps"><img alt="UNL Campus Map" src="<?php echo htmlentities($url, ENT_QUOTES); ?>" /></a>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment