Mapstraction Action
This is the development page for the
{{mapstraction}} action.
<?php
/**
* Prints a map using the Mapstraction scripts on a page.
*
* Note that you have to register your (sub)domain with google to get a key to use the maps from google.
* Also support for openstreetmaps currently uses the google scripts.
* See http://www.google.com/apis/maps/signup.html for details.
*
* based on http://wikkawiki.org/GoogleMap
*
* @package actions
* @author {@link http://www.wikkawiki.org/NilsLindenberg Nils Lindenberg} (initial version)
* @author {@link http://www.wikkawiki.org/SamuelDR SamuelDR} (bugfix)
* @author {@link http://www.wikkawiki.org/FrankChestnut FrankChestnut} (various parameters and api v2)
* @author {@link http://www.wikkawiki.org/MasinAlDujaili MasinAlDujaili} (adaption for Mapstraction)
*
* @todo: - Load markers from...
* - phpdoc document params
*/
function parseMarker
($marker)
{
$result =
explode(' :: ',
$marker);
$result[2] =
html_entity_decode($result[2]);
$result[3] =
html_entity_decode($result[3]);
return $result;
}
//the keys you need for google, multimap
$googlekey =
'';
$microsoftkey =
'';
$map24key =
'';
$multimapkey =
'';
$mapquestkey =
'';
// defaults
$name =
'mapstraction';
$latitude =
'37.441944';
$longitude =
'-122.141944';
$width =
'300';
$height =
'300';
$maptype =
'1';
$zoom =
'4';
$api =
'openlayers';
$overview =
false;
$markers =
'';
// E_ALL fix
if (isset($vars) &&
is_array($vars)) {
if (isset($vars['name']) && !
empty($vars['name'])) {
$name =
$vars['name'];
}
if (isset($vars['latitude']) && !
empty($vars['latitude'])) {
$latitude =
$vars['latitude'];
}
if (isset($vars['longitude']) && !
empty($vars['longitude'])) {
$longitude =
$vars['longitude'];
}
if (isset($vars['width']) && !
empty($vars['width'])) {
$width =
$vars['width'];
}
if (isset($vars['height']) && !
empty($vars['height'])) {
$height =
$vars['height'];
}
if (isset($vars['zoom']) && !
empty($vars['zoom'])) {
$zoom =
$vars['zoom'];
}
if (isset($vars['api']) && !
empty($vars['api'])) {
$api =
$vars['api'];
}
if (isset($vars['maptype']) && !
empty($vars['maptype'])) {
$maptype =
$vars['maptype'];
}
if (isset($vars['overview']) && !
empty($vars['overview'])) {
// 0 & '0' are considered empty so there is no need for further checks
$overview =
true;
}
if (isset($vars['marker']) && !
empty($vars['marker'])) {
$marker =
explode(';;',
$vars['marker']);
foreach($marker as $current_marker)
{
$markers[] = parseMarker
($current_marker);
}
}
}
echo '<div id="'.
$name.
'" style="width:'.
$width.
'; height:'.
$height.
';"></div>';
switch($api)
{
case 'openstreetmap':
case 'google':
if(!
$googlekey) $api =
'openlayers';
break;
case 'map24':
if(!
$map24key) $api =
'openlayers';
break;
case 'microsoft':
if(!
$microsoftkey) $api =
'openlayers';
break;
case 'multimap':
if(!
$multimapkey) $api =
'openlayers';
break;
case 'mapquest':
if(!
$mapquestkey) $api =
'openlayers';
break;
}
switch($api)
{
case 'google':
case 'openstreetmap':
echo '<script src="http://maps.google.com/maps?file=api&v=2&key='.
$googlekey.
'" type="text/javascript"></script>';
break;
case 'yahoo':
echo '<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=MapstractionDemo"></script>';
break;
case 'microsoft':
echo '<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"></script>';
break;
case 'map24':
echo '<script type="text/javascript" language="javascript" src="http://api.maptp.map24.com/ajax?appkey=FJXe1b9e7b896f8cf70534ee0c69ecbfX16"></script>';
break;
case 'multimap':
echo '<script type="text/javascript" src="http://developer.multimap.com/API/maps/1.2/OA070606486554191"></script>';
break;
case 'mapquest':
echo '<script src="http://btilelog.access.mapquest.com/tilelog/transaction?transaction=script&key=mjtd%7Clu6t210anh%2Crn%3Do5-labwu&ipr=true&itk=true&v=5.1" type="text/javascript"></script>'.
"\n"
.
'<!-- The JSAPI Source files (only needed for geocoding & routing with MapQuest) -->'.
"\n"
.
'<script src="mapquest-js/mqcommon.js" type="text/javascript"></script>'.
"\n"
.
'<script src="mapquest-js/mqutils.js" type="text/javascript"></script>'.
"\n"
.
'<script src="mapquest-js/mqobjects.js" type="text/javascript"></script>'.
"\n"
.
'<script src="mapquest-js/mqexec.js" type="text/javascript"></script>'.
"\n";
break;
case 'freeearth':
echo '<script type="text/javascript" src="http://freeearth.poly9.com/api.js"></script>';
break;
case 'openlayers':
echo '<script src="http://openlayers.org/api/OpenLayers.js"></script>';
break;
}
echo '<script src="'.
$this->
GetConfigValue('mapstraction_path').
'/mapstraction.js" type="text/javascript"></script>';
?>
<script type=
"text/javascript">
//<![CDATA[
<?php
echo 'var mapstraction = new Mapstraction("mapstraction","'.
$api.
'");';
echo 'var myPoint = new LatLonPoint('.
$latitude.
','.
$longitude.
');';
echo 'mapstraction.setCenterAndZoom(myPoint,'.
$zoom.
');';
switch($api)
{
case 'yahoo':
case 'google':
case 'openstreetmap':
case 'multimap':
case 'mapquest':
echo 'mapstraction.addMapTypeControls();'.
"\n";
break;
default:
break;
}
if($api!=
'openstreetmap') echo 'mapstraction.setMapType('.
$maptype.
');';
?>
mapstraction.addControls
({
pan:
true,
zoom:
'large',
map_type:
true
});
// create markers positioned at a lat/lon
<?php
$x =
count($markers);
while($x--
)
{
echo 'markerPoint'.
$x.
' = new LatLonPoint('.
$markers[$x][0].
','.
$markers[$x][1].
');'.
"\n";
echo 'myMarker'.
$x.
' = new Marker(markerPoint'.
$x.
');'.
"\n";
echo 'myMarker'.
$x.
'.setLabel("'.
$markers[$x][2].
'");'.
"\n";
echo 'myMarker'.
$x.
'.setInfoBubble("<strong>'.
$markers[$x][2].
'</strong><br />'.
$markers[$x][3].
'");'.
"\n";
echo 'mapstraction.addMarker(myMarker'.
$x.
');'.
"\n\n";
}
echo 'myMarker0.openBubble();'.
"\n\n";
?>
ufoo =
function() { mapstraction.removeMarker
(my_marker
);
}
//]]>
</script>
CategoryDevelopmentActions