<?
/******************************************************************************
# Copyright notice
#
# This file is part of Wiki-Map project [http://wiki-map.sourceforge.net/]
# Wiki-Map is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# The GNU General Public License can be found at
# http://www.gnu.org/copyleft/gpl.html.
# A copy is found in the textfile GPL and important notices to the
# license from the team is found in the textfile LICENSE distributed
# with these scripts.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# This copyright notice MUST APPEAR in all copies and derivatives of the script!
#*********************************************************************************/
#*********************************************************************************/
$x = (isset($_COOKIE[x]))?$_COOKIE[x]:36.40;
$y = (isset($_COOKIE[y]))?$_COOKIE[y]:29.58;
$z = (isset($_COOKIE[z]))?$_COOKIE[z]:2;
$x = (isset($_GET[x]))?$_GET[x]:$x;
$y = (isset($_GET[y]))?$_GET[y]:$y;
$z = (isset($_GET[z]))?$_GET[z]:$z;
$_COOKIE[x] = $x;
$_COOKIE[y] = $y;
$_COOKIE[z] = $z;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<META NAME="Keywords" CONTENT="Map, wikimap, wikipedia, measurement, Google Map">
<META NAME="Description" CONTENT="WikiMap route disance measurement. Based on Google Map API to build a knowledge repository like Wikipedia to share your location and other geo-information. ">
<META NAME="Author" CONTENT="hide@address.com">
<title>WikiMap: Route distance measurement</title>
<link rel="stylesheet" type="text/css" href="wikimap.css">
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAApL1hGE-KNQcfWmK-4HpMHRSAsL_rpfnb7R6YjdHmXm9ZuwilPhTw9DUGZeCNDTsWftNOHtjvtQkLCQ"
type="text/javascript"></script>
<script src="wikistd.js" type="text/javascript"></script>
<script src="icondef.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var parray = new Array();
var darray = new Array();
var larray = new Array();
var marray = new Array();
var dist = 0;
var ipoint = 0;
var zmap = new Object;
function writePts(){
}
function load() {
<? if (isset($_GET[a])){echo "alert('$_GET[a]');";}?>
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
zmap = map;
<? echo "map.setCenter(new GLatLng($y, $x), $z);\n";?>
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
map.addControl(new GScaleControl());
map.addControl(new GOverviewMapControl());
map.addControl(new MeasureControl());
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var zlevel = map.getZoom();
document.calc.rem.value = 'Click on starting point';
// set cookies
GDownloadUrl("points.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
show_icon(map,point,markers[i].getAttribute("type"),markers[i].getAttribute("desc"));
}
});
}
GEvent.addListener(map, "moveend", function() {
var p = map.getCenter();
setCookie('x',p.x);
setCookie('y',p.y);
setCookie('z',map.getZoom());
});
GEvent.addListener(map, "click", function(overlay, point) {
setCookie('y',point.lat());
setCookie('x',point.lng());
setCookie('z',map.getZoom());
if (overlay) {
// map.removeOverlay(overlay);
window.status = '';
} else {
window.status = 'Click on start point';
if (ipoint > 1) {map.removeOverlay(lastpeg);}
if (ipoint > 0) {
parray[ipoint] = point;
larray[ipoint] = new GPolyline([pOld,point],"#33ff88",10);
map.addOverlay(larray[ipoint]);
//map.addOverlay(new GPolyline([pOld,point],"#33ff88",10));
dist = dist + point.distanceFrom(pOld);
darray[ipoint] = point.distanceFrom(pOld);
kmdist = Math.round(dist)/1000;
document.calc.rem.value = 'Distance: '+kmdist+' Km';
}
lastpeg = new GMarker(point);
marray[ipoint]= lastpeg;
map.addOverlay(lastpeg);
ipoint = ipoint+1;
pOld = point;
//svisibility('info','visible');
}
});
}
//--------- Add control to modify the route ------------------------------
function MeasureControl() {
}
MeasureControl.prototype = new GControl();
MeasureControl.prototype.initialize = function(map) {
var container = document.createElement("div");
var ClrLapDiv = document.createElement("div");
this.setButtonStyle_(ClrLapDiv);
container.appendChild(ClrLapDiv);
ClrLapDiv.appendChild(document.createTextNode("Clear Last Lap"));
GEvent.addDomListener(ClrLapDiv, "click", function() {
//------------------------- Clear ---------------
if (ipoint <=2) {
map.removeOverlay(larray[1]);
map.removeOverlay(lastpeg);
map.removeOverlay(marray[0]);
dist = 0;
ipoint = 0;
} else {
dist = dist - darray[ipoint-1];
// lastpeg = new GMarker(parray[ipoint-1]);
map.removeOverlay(lastpeg);
pOld = parray[ipoint-2];
lastpeg = new GMarker(pOld);
map.addOverlay(lastpeg);
map.removeOverlay(larray[ipoint-1]);
ipoint = ipoint - 1;
}
kmdist = Math.round(dist)/1000;
document.calc.rem.value = 'Distance: '+kmdist+' Km';
});
//---------------- clr route ------------------------------------------------------
var ClrRouteDiv = document.createElement("div");
this.setButtonStyle_(ClrRouteDiv);
container.appendChild(ClrRouteDiv);
ClrRouteDiv.appendChild(document.createTextNode("Clear Route"));
GEvent.addDomListener(ClrRouteDiv, "click", function() {
for (i=1; i<ipoint; i++){
map.removeOverlay(larray[i]);
}
map.removeOverlay(lastpeg);
lastpeg = marray[0];
map.removeOverlay(lastpeg);
dist = 0;
ipoint = 0;
kmdist = Math.round(dist)/1000;
document.calc.rem.value = 'Distance: '+kmdist+' Km';
});
map.getContainer().appendChild(container);
return container;
}
// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
MeasureControl.prototype.getDefaultPosition = function() {
return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(415, 7));
}
// Sets the proper CSS for the given button element.
MeasureControl.prototype.setButtonStyle_ = function(button) {
button.style.textDecoration = "none";
button.style.color = "#0000cc";
button.style.backgroundColor = "#FFFFFF";
button.style.font = "small Arial";
button.style.border = "2px solid black";
button.style.padding = "2px";
button.style.marginBottom = "3px";
button.style.textAlign = "center";
button.style.width = "9em";
button.style.cursor = "pointer";
}
//---------------- End route control -----------------------------------------
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map">
</div>
<div id="dist"><b align=center>Route Distance:</b><br>
<FORM name='calc' method=POST action='saveroute.php'>
<TEXTAREA rows=1 cols=20 name='rem'> Click on the starting point</TEXTAREA><BR>
</FORM>
</div>
<? include "wikifoot.php"; ?>
</body>
</html>