Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ryan Dee
UNL_TourMap
Commits
34ab3971
Commit
34ab3971
authored
Jun 17, 2014
by
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/UNL/TourMap/GoogleMap.php
View file @
34ab3971
...
...
@@ -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
www/js/map.js
View file @
34ab3971
...
...
@@ -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
,
...
...
www/templates/html/UNL/TourMap/GoogleMap.tpl.php
View file @
34ab3971
...
...
@@ -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'
];
?>
;
...
...
www/templates/staticgooglemapsv2/UNL/TourMap/GoogleMap.tpl.php
View file @
34ab3971
<?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'
])
:
'
960x62
0'
;
$map_options
[
'size'
]
=
(
isset
(
$context
->
options
[
'size'
]))
?
urlencode
(
$context
->
options
[
'size'
])
:
'
640x48
0'
;
$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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment