/**
* MapExtension for Wordpress
* Version 0.7
* Date 10.1.2007
* Copyright Exinit GmbH & Co KG
* Author Felix Gebhard
*/
/******************************************************************
Helper function part:
*/
/*
Executes a function given when document is loaded
*/
function addOnDocumentLoaded(functionname) {
if (window.addEventListener)
window.addEventListener("load", functionname, false);
else if (window.attachEvent) window.attachEvent("onload", functionname);
else window.onload = functionname;
}
/******************************************************************
Google MAP Part:
*/
var myPane;
var map;
var baseIcon;
var baseTempIcon;
var endicon;
var starticon;
var testIcon;
var porticon;
var moreporticon;
var mapoldbounds;
var draglat;
var draglng;
var currentMarker;
var amarkerListener = new Array();
var infoWindowTimer;
var displayHelp = true;
var route = new Array();
var startPoints = new Array();
var portPoints = new Array();
var tempStartPoints = new Array();
var tempPorts;
var routingBounds;
var startingBounds;
var startmarker;
var polyline;
var markerArray;
var tempBounds;
var mouseMoveListener;
var oldCenter;
var oldZoom;
var defaultZoom = 5;
var defaultLat = 57;
var defaultLng = 20;
/* MaxView: */
var sw_lat = -90;
var sw_lng = -180;
var ne_lat = 90;
var ne_lng = 180;
var availableBounds;
/* Port Options: */
var portOptions = new Array();
var mywaitOverlay;
function infoOverlay() {
GOverlay.call(this);
}
infoOverlay.prototype = {
initialize : function(map) {
this.myPane = map.getPane(G_MAP_FLOAT_PANE);
},
setMarker : function (aMarker) {
this.myMarker = aMarker;
},
setContent : function (aContent) {
this.myContent = aContent;
},
redraw : function() {
if (!this.drawn) {
this.myinfo = document.createElement('div');
this.myinfo.id = 'infobox';
var myinfoboxwidth = 400; /* same as in styles.css for infobox! */
var myinfoboxheight = 200; /* same as in styles.css for infobox! */
myPoint = map.fromLatLngToDivPixel(this.myMarker.getPoint());
myMapCenterPoint = map.fromLatLngToDivPixel(map.getCenter());
var leftCorrecture = myinfoboxwidth+myPoint.x-myMapCenterPoint.x+getMapCenterX()-map.getSize().width;
if ((leftCorrecture>0) && (editMode)) {
this.myinfo.style.left = myPoint.x+20-leftCorrecture-myMapCenterPoint.x+getMapCenterX()+'px';
}
else {
this.myinfo.style.left = myPoint.x+20-myMapCenterPoint.x+getMapCenterX()+'px';
}
var topCorrecture = myinfoboxheight+myPoint.y-myMapCenterPoint.y+getMapCenterY()-map.getSize().height;
if ((topCorrecture>0) && (editMode)) {
this.myinfo.style.top = myPoint.y+20-topCorrecture-myMapCenterPoint.y+getMapCenterY()+'px';
}
else {
this.myinfo.style.top = myPoint.y+20-myMapCenterPoint.y+getMapCenterY()+'px';
}
this.myinfo.innerHTML = this.myContent;
$('mapcontainer').appendChild(this.myinfo);
if (this.myinfo.addEventListener) {
this.myinfo.addEventListener('mouseover', function () {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
}, false);
}
else {
this.myinfo.attachEvent('onmouseover', function () {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
});
}
if (this.myinfo.addEventListener) {
this.myinfo.addEventListener('mouseout', function () {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
infoWindowTimer = setTimeout(function() {
map.removeOverlay(myinfoOverlay);
},1000);
}, false);
}
else {
this.myinfo.attachEvent('onmouseout', function () {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
infoWindowTimer = setTimeout(function() {
map.removeOverlay(myinfoOverlay);
},1000);
});
}
this.drawn = true;
}
},
remove : function() {
$('mapcontainer').removeChild(this.myinfo);
this.drawn = false;
}
}
function waitOverlay() {
GOverlay.call(this);
}
waitOverlay.prototype = {
initialize : function(map) {
this.myPane = map.getPane(G_MAP_FLOAT_PANE);
},
redraw : function() {
if (!this.drawn) {
GEvent.clearListeners(map, "click");
map.disableDragging();
map.disableInfoWindow();
this.mywaitbox = document.createElement('div');
this.mywaitbox.id = 'waitbox';
if (editMode) this.myContent = "
";
else this.myContent = "
";
this.mywaitbox.style.top = getMapCenterY()-17+'px';
this.mywaitbox.style.left = getMapCenterX()-17+'px';
this.mywaitbox.innerHTML = this.myContent;
$('map').appendChild(this.mywaitbox);
this.drawn = true;
}
},
remove : function() {
$('map').removeChild(this.mywaitbox);
this.drawn = false;
map.enableDragging();
map.enableInfoWindow();
if (editMode) {
GEvent.addListener(map, "click", function(marker, point) {
if (marker) {
} else {
if (availableBounds.contains(point)) {
map.removeOverlay(polyline);
map.removeOverlay(startmarker);
var routlength = route.length;
route[routlength] = new Array();
route[routlength].lat = point.lat();
route[routlength].lng = point.lng();
$("lat_input").value = retransformCoordinatesLat(point.lat());
$("lng_input").value = retransformCoordinatesLng(point.lng());
buildRoute(false, false, true);
showPortPoints();
}
else alert($('alert_coords_notbaltic').value);
}
});
}
}
}
GMap2.prototype.centerAndZoomOnBounds = function(bounds) {
oldZoom = map.getZoom();
oldCenter = map.getCenter();
var center = bounds.getCenter();
var newZoom = this.getBoundsZoomLevel(bounds)-1;
this.setCenter(center, newZoom);
}
function retransformCoordinates(unpreparedValue) {
//alert(unpreparedValue);
var degrees = parseInt(unpreparedValue);
var minutes = parseInt((unpreparedValue-degrees)*60);
var seconds = Math.round((unpreparedValue-degrees-((minutes-0)/60))*3600);
return degrees+'\xb0 '+minutes+'\x27 '+seconds+'\x27\x27';
}
function retransformCoordinatesLat(unpreparedValue) {
//alert(unpreparedValue);
NS='N';
if (unpreparedValue < 0) {
unpreparedValue = unpreparedValue* -1;
NS='S';
}
var degrees = parseInt(unpreparedValue);
var minutes = parseInt((unpreparedValue-degrees)*60);
var seconds = Math.round((unpreparedValue-degrees-((minutes-0)/60))*3600);
return degrees+'\xb0 '+minutes+'\x27 '+seconds+'\x27\x27 '+NS;
}
function retransformCoordinatesLng(unpreparedValue) {
//alert(unpreparedValue);
EW='E';
if (unpreparedValue < 0) {
unpreparedValue = unpreparedValue* -1;
EW='W';
}
var degrees = parseInt(unpreparedValue);
var minutes = parseInt((unpreparedValue-degrees)*60);
var seconds = Math.round((unpreparedValue-degrees-((minutes-0)/60))*3600);
return degrees+'\xb0 '+minutes+'\x27 '+seconds+'\x27\x27 '+EW;
}
function transformCoordinates(unpreparedValue) {
if (!unpreparedValue) return null;
// Check for 49°24'12''
var regEx = /^(\s*)([A-Za-z|-]?)(\s*)(\d+)(\s*)(\xb0{1})(\s*)(\d+)(\s*)(\x27{1})(\s*)(\d+)(\s*)(\x27{2})(\s*)([A-Za-z|-]?)(\s*)$/;
var result = unpreparedValue.match(regEx);
if (result!=null) {
//result[0] whole word
//result[1] first spaces...
var direction = result[2] //result[2] N E W S
//result[3] second spaces...
var degree = result[4] //result[4] degrees
//result[5] again spaces...
var degreeSymbol = result[6] //result[6] degreeSymbol if there is any...
//result[7] again spaces...
var minutes = result[8] //result[8] minutes
//result[9] again spaces...
var minuteSymbol = result[10] //result[10] minuteSymbol if there is any...
//result[11] again spaces...
var seconds = result[12] //result[12] seconds
//result[13] again spaces...
var secondSymbol = result[14] //result[14] secondSymbol if there is any...
//result[15] again spaces...
if (result[16]!='') direction = result[16] //result[16] N E W S , overwrites result[2] if set
//result[17] again spaces...
//result:
if (direction == 'S' || direction == 'W')
return (degree-0+((minutes-0+((seconds-0)/60))/60))*-1;
return degree-0+((minutes-0+((seconds-0)/60))/60);
}
// Check for 49°24'
var regEx = /^(\s*)([A-Za-z|-]?)(\s*)(\d+)(\s*)(\xb0{1})(\s*)(\d+)(\s*)(\x27{1})(\s*)([A-Za-z|-]?)(\s*)$/;
var result = unpreparedValue.match(regEx);
if (result!=null) {
//result[0] whole word
//result[1] first spaces...
var direction = result[2] //result[2] N E W S
//result[3] second spaces...
var degree = result[4] //result[4] degrees
//result[5] again spaces...
var degreeSymbol = result[6] //result[6] degreeSymbol if there is any...
//result[7] again spaces...
var minutes = result[8] //result[8] minutes
//result[9] again spaces...
var minuteSymbol = result[10] //result[10] minuteSymbol if there is any...
//result[11] again spaces...
if (result[12]!='') direction = result[12] //result[12] N E W S , overwrites result[2] if set
//result[13] again spaces...
//result:
if (direction == 'S' || direction == 'W')
return (degree-0+((minutes-0)/60))*-1;
return degree-0+((minutes-0)/60);
}
// Check for 49°24.213
var regEx = /^(\s*)([A-Za-z|-]?)(\s*)(\d+)(\s*)(\xb0{1})(\s*)(\d+\.*\d*)(\s*)([A-Za-z|-]?)(\s*)$/;
var result = unpreparedValue.match(regEx);
if (result!=null) {
//result[0] whole word
//result[1] first spaces...
var direction = result[2] //result[2] N E W S
//result[3] second spaces...
var degree = result[4] //result[4] degrees
//result[5] again spaces...
var degreeSymbol = result[6] //result[6] degreeSymbol if there is any...
//result[7] again spaces...
var minutes = result[8] //result[4] degrees
//result[9] again spaces...
if (result[10]!='') direction = result[10] //result[10] N E W S , overwrites result[2] if set
//result[11] again spaces...
//result:
if (direction == 'S' || direction == 'W')
return (degree-0+((minutes-0)/60))*-1;
return degree-0+((minutes-0)/60);
}
// Check for 49.213 and 49.213°
var regEx = /^(\s*)([A-Za-z|-]?)(\s*)(\d+\.*\d*)(\s*)(\xb0?)(\s*)([A-Za-z|-]?)(\s*)$/;
var result = unpreparedValue.match(regEx);
if (result!=null) {
//result[0] whole word
//result[1] first spaces...
var direction = result[2] //result[2] N E W S
//result[3] second spaces...
var degree = result[4] //result[4] degrees
//result[5] again spaces...
var degreeSymbol = result[6] //result[6] degreeSymbol if there is any...
//result[7] again spaces...
if (result[8]!='') direction = result[8] //result[8] N E W S , overwrites result[2] if set
//result[9] again spaces...
//result:
if (direction == 'S' || direction == 'W')
return (degree-0)*-1;
return degree-0;
}
alert('Syntax: 52\xb0 14\' 23\'\' ');
return null;
}
function initMapDisplay() {
if (GBrowserIsCompatible()) {
var minZoom = 1;
var maxZoom = 15;
if (editMode) {
$('map').style.width = '';
$('map').style.height = '700px';
$('editbox').style.width = '';
}
map = new GMap2($('map'));
map.addMapType(G_NORMAL_MAP);
map.addMapType(G_HYBRID_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GMapTypeControl());
map.enableDoubleClickZoom();
map.setCenter(new GLatLng(defaultLat, defaultLng), defaultZoom);
var ovM=new GOverviewMapControl(new GSize(120,120));
map.addControl(ovM);
sw_point = new GLatLng(sw_lat, sw_lng);
ne_point = new GLatLng(ne_lat, ne_lng);
availableBounds = new GLatLngBounds(sw_point, ne_point);
GEvent.addListener(map, "zoomend", function(oldLevel, newLevel) {
if (newLevelmaxZoom) {
map.setZoom(maxZoom);
}
});
baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(25, 40);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
baseTempIcon = new GIcon(baseIcon);
baseTempIcon.iconSize = new GSize(10, 10);
if (editMode) baseTempIcon.image = "/toernplaner/images/sailbaltic_icons.png";
else baseTempIcon.image = "/toernplaner/images/sailbaltic_icons.png";
testIcon = new GIcon(baseIcon);
if (editMode) {
testIcon.image = "/toernplaner/images/sailbaltic_icons.png";
testIcon.shadow = "/toernplaner/images/spacer.gif";
}
else {
testIcon.image = "/toernplaner/images/sailbaltic_icons.png";
testIcon.shadow = "/toernplaner/images/spacer.gif";
}
porticon = new GIcon(baseIcon);
porticon.iconSize = new GSize(20, 34);
if (editMode) porticon.image = "/toernplaner/images/port_marker.png";
else porticon.image = "/toernplaner/images/port_marker.png";
moreporticon = new GIcon(baseIcon); //20,34
moreporticon.iconSize = new GSize(20, 34);
if (editMode) moreporticon.image = "/toernplaner/images/area_marker.png";
else moreporticon.image = "/toernplaner/images/area_marker.png";
endicon = new GIcon(baseIcon);
if (editMode) endicon.image = "/toernplaner/images/sailbaltic_icons.png";
else endicon.image = "/toernplaner/images/sailbaltic_icons.png";
starticon = new GIcon(baseIcon);
if (editMode) starticon.image = "/toernplaner/images/sailbaltic_icons.png";
else starticon.image = "/toernplaner/images/sailbaltic_icons.png";
manyicon = new GIcon(baseIcon);
manyicon.iconSize = new GSize(30, 25);
if (editMode) manyicon.image = "/toernplaner/images/sailbaltic_icon2.png";
else manyicon.image = "/toernplaner/images/sailbaltic_icon2.png";
if (editMode == true) {
$("clearRoute").onclick = function () {
map.clearOverlays();
route = new Array();
}
$("clearLastPoint").onclick = function () {
map.clearOverlays();
if (route.length>0) route.pop();
buildRoute(false, false, true);
}
$("addPoint").onclick = function () {
addPointToRoute(transformCoordinates($("lat_input").value.replace(",", ".")), transformCoordinates($("lng_input").value.replace(",", ".")));
}
$("setPoint").onclick = function () {
var lat_input = transformCoordinates($("lat_input").value.replace(",", "."));
var lng_input = transformCoordinates($("lng_input").value.replace(",", "."));
if (lat_input==0 && lng_input==0) {
// alert($('alert_coords_00').value);
}
else {
if (availableBounds.contains(new GLatLng(lat_input, lng_input))) {
map.clearOverlays();
var routlength = route.length;
route[routlength-1].lat = lat_input;
route[routlength-1].lng = lng_input;
buildRoute(false, false, true);
}
// else alert($('alert_coords_notbaltic').value);
}
}
$("option_endasstart").onclick = function () {
map.clearOverlays();
buildRoute(false, false, true);
}
$("option_displayports").onclick = function () {
checkPortsDisplay();
}
if ($("place_select")) $("place_select").onchange = function () {
if ($("place_select").value=='noplace') {
$("lat_input").value = 0;
$("lng_input").value = 0;
}
else {
$("lat_input").value = retransformCoordinatesLat(places[$("place_select").value].lat);
$("lng_input").value = retransformCoordinatesLng(places[$("place_select").value].lng);
}
}
myPane = map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE);
GEvent.addListener(map, "click", function(marker, point) {
if (marker) {
} else {
if (availableBounds.contains(point)) {
addPointToRoute(point.lat(), point.lng());
}
else alert($('alert_coords_notbaltic').value);
}
});
GEvent.addListener(map, "mouseover", displayFreeMapHelp);
GEvent.addListener(map, "mouseout", hideFreeMapHelp);
}
}
}
function addStartEndPointToRoute(lat_input, lng_input, title) {
if (lat_input==0 && lng_input==0) {
// alert($('alert_coords_00').value);
}
else {
if (availableBounds.contains(new GLatLng(lat_input, lng_input))) {
$("option_endasstart").checked = true;
map.clearOverlays();
route[0] = new Array();
route[0].lat = lat_input;
route[0].lng = lng_input;
if (title) route[0].title = title;
$("lat_input").value = retransformCoordinatesLat(lat_input);
$("lng_input").value = retransformCoordinatesLng(lng_input);
buildRoute(false, false, true);
showPortPoints();
}
// else alert($('alert_coords_notbaltic').value);
}
}
function addPointToRoute(lat_input, lng_input, title) {
if (lat_input==0 && lng_input==0) {
// alert($('alert_coords_00').value);
}
else {
if (availableBounds.contains(new GLatLng(lat_input, lng_input))) {
map.clearOverlays();
var routlength = route.length;
route[routlength] = new Array();
route[routlength].lat = lat_input;
route[routlength].lng = lng_input;
if (title) route[routlength].title = title;
$("lat_input").value = retransformCoordinatesLat(lat_input);
$("lng_input").value = retransformCoordinatesLng(lng_input);
buildRoute(false, false, true);
showPortPoints();
}
}
}
function getMapCenterX() {
return parseInt(map.getSize().width)/2;
}
function getMapCenterY() {
return parseInt(map.getSize().height)/2;
}
function showStartPoints() {
myinfoOverlay = new infoOverlay();
map.clearOverlays();
startingBounds = new GLatLngBounds();
for (i = 0; i < startPoints.length; i++) {
var startgoptions = {
"icon" : starticon,
"draggable" : false
};
var manygoptions = {
"icon" : manyicon,
"draggable" : false
};
if (startPoints[i].postid==-1) {
var amarker = new GMarker(new GLatLng(startPoints [i].lat, startPoints [i].lng), manygoptions);
amarker.ne_lat_holder = startPoints[i].ne_lat;
amarker.ne_lng_holder = startPoints[i].ne_lng;
amarker.sw_lat_holder = startPoints[i].sw_lat;
amarker.sw_lng_holder = startPoints[i].sw_lng;
amarker.postlist = startPoints[i].postlist;
GEvent.addListener(amarker, "click", function(marker) {
map.setCenter(this.getPoint(),map.getZoom()+1);
});
GEvent.addListener(amarker, "mouseover", function(marker) {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
infowindow = 'Info
';
for (postindex = 0; postindex < this.postlist.length; postindex++) {
if (this.postlist[postindex].postid==-1) {
infowindow+= '...
';
}
else infowindow+= '- '+this.postlist[postindex].posttitle+'
';
}
infowindow+= '
';
infowindow+= ''+$('zoomin_translation').value+'
';
map.removeOverlay(myinfoOverlay);
myinfoOverlay.setMarker(this);
myinfoOverlay.setContent(infowindow);
map.addOverlay(myinfoOverlay);
infoWindowTimer = setTimeout(function() {
map.removeOverlay(myinfoOverlay);
},1000);
});
}
else {
var amarker = new GMarker(new GLatLng(startPoints [i].lat, startPoints [i].lng), startgoptions);
var postid = startPoints[i].postid;
var posttitle = startPoints[i].posttitle;
amarker.postid = postid;
amarker.posttitle = posttitle;
GEvent.addListener(amarker, "mouseover", function(marker) {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
infowindow = 'Info
';
map.removeOverlay(myinfoOverlay);
myinfoOverlay.setMarker(this);
myinfoOverlay.setContent(infowindow);
map.addOverlay(myinfoOverlay);
infoWindowTimer = setTimeout(function() {
map.removeOverlay(myinfoOverlay);
},1000);
});
}
startingBounds.extend(amarker.getPoint());
map.addOverlay(amarker);
}
}
function checkPortsDisplay() {
if ($("option_displayports").checked == true) {
getPorts(showPortPoints);
$('portOptions').style.display = 'block';
}
else {
if (map) {
if (map.portPointListener) GEvent.removeListener(map.portPointListener);
map.clearOverlays();
$('portOptions').style.display = 'none';
buildRoute(false, false, true);
}
}
}
function showPortPoints() {
if (map.portPointListener) GEvent.removeListener(map.portPointListener);
if ($("option_displayports").checked == true) {
myinfoOverlay = new infoOverlay();
var portgoptions = {
"icon" : porticon,
"draggable" : false
};
var moreportgoptions = {
"icon" : moreporticon,
"draggable" : false
};
for (i = 0; i < portPoints.length; i++) {
var amarker;
if (portPoints[i].icontype==0) amarker = new GMarker(new GLatLng(portPoints [i].lat, portPoints [i].lng), portgoptions);
if (portPoints[i].icontype>0) amarker = new GMarker(new GLatLng(portPoints [i].lat, portPoints [i].lng), moreportgoptions);
amarker.postid = -2;
amarker.posttitle = portPoints [i].label;
amarker.html = portPoints [i].html;
amarker.icontype = portPoints [i].icontype;
GEvent.addListener(amarker, "click", function(marker) {
if (infoWindowTimer!=null) clearTimeout(infoWindowTimer);
infowindow = 'Info
';
map.removeOverlay(myinfoOverlay);
myinfoOverlay.setMarker(this);
myinfoOverlay.setContent(infowindow);
map.addOverlay(myinfoOverlay);
infoWindowTimer = setTimeout(function() {
map.removeOverlay(myinfoOverlay);
},20000);
});
map.addOverlay(amarker);
}
map.portPointListener = GEvent.addListener(map, "moveend", function() {
buildRoute(false, false, true);
} );
}
}
function showTempRoute(postid) {
GEvent.removeListener(map.startPointListener);
GEvent.removeListener(map.startPointListener2);
tempBounds = map.getBounds();
getRoutingPoints(postid, buildRoute, false, true);
setTimeout(function() {
map.setCenter(oldCenter, oldZoom);
map.startPointListener = GEvent.addListener(map, "moveend", function() {
getStartPoints("", showStartPoints);
} );
map.startPointListener2 = GEvent.addListener(map, "zoomend", function() {
getStartPoints("", showStartPoints);
} );
showStartPoints();
},2000);
}
function buildRoute(clearNotOverlays, markerClickable, notcenterandzoom, mymarker) {
var GRoute = new Array();
var i;
var j = -1;
var routebuildingtimeout = 0;
if (editMode == true) GEvent.clearListeners(map, "mousemove");
else GEvent.clearListeners(map, "mousemove");
if (!clearNotOverlays) map.clearOverlays();
routingBounds = new GLatLngBounds();
if ((route.length>1) && (route [0].lat==route [route.length-1].lat) &&
(route [0].lng==route [route.length-1].lng)) {
if (editMode == true) {
route.pop();
$("option_endasstart").checked = true;
}
}
$("distances").innerHTML = '';
var completeDistance = 0;
for (i = 0; i < route.length; i++) {
j++;
GRoute[j] = new GLatLng(route [i].lat, route [i].lng);
if (route[i].title) GRoute[j].title = route[i].title;
var startName = $("transAnyPlace").value;
var endName = $("transAnyPlace").value;
if (j>0) {
var distance = GRoute[j-1].distanceFrom(GRoute[j]);
completeDistance += distance;
if (GRoute[j-1].title) startName = GRoute[j-1].title;
if (GRoute[j].title) endName = GRoute[j].title;
$("distances").innerHTML+=$("transDistance").value+' '+startName+' ('+retransformCoordinatesLat(route [i-1].lat)+'; '+retransformCoordinatesLng(route [i-1].lng)+') -> '+endName+' ('+retransformCoordinatesLat(route [i].lat)+'; '+retransformCoordinatesLng(route [i].lng)+') : '+(distance/1852).toFixed(1)+' sm
';
}
if (editMode == true) {
if ($("option_endasstart").checked == true) {
if (i==route.length-1) {
GRoute[j+1] = new GLatLng(route [0].lat, route [0].lng);
var distance = GRoute[j].distanceFrom(GRoute[j+1]);
completeDistance += distance;
if (GRoute[j].title) startName = GRoute[j].title;
if (GRoute[0].title) endName = GRoute[0].title;
// $("distances").innerHTML+=$("transDistance").value+' '+startName+' -> Start : '+' '+(distance/1852).toFixed(1)+' sm
';
$("distances").innerHTML+=$("transDistance").value+' '+startName+' ('+retransformCoordinatesLat(route [i].lat)+'; '+retransformCoordinatesLng(route [i].lng)+') -> '+endName+' ('+retransformCoordinatesLat(route [0].lat)+'; '+retransformCoordinatesLng(route [0].lng)+') : '+(distance/1852).toFixed(1)+' sm
';
}
}
}
var startgoptions = {
"icon" : starticon,
"draggable" : editMode
};
var endgoptions = {
"icon" : endicon,
"draggable" : editMode
};
var tempgoptions = {
"icon" : baseTempIcon,
"draggable" : editMode
};
var testOptions = {
"icon" : testIcon,
"draggable" : editMode
};
var amarker = null;
if (i==0) amarker = new GMarker(GRoute[j], startgoptions);
else if (i==route.length-1) amarker = new GMarker(GRoute[j], endgoptions);
else {
if (!clearNotOverlays) amarker = new GMarker(GRoute[j], testOptions);
else amarker = new GMarker(GRoute[j], tempgoptions);
}
amarker.post_id = route[i].postid;
routingBounds.extend(amarker.getPoint());
map.addOverlay(amarker);
if (editMode == true) {
GEvent.addListener(amarker, "mouseover", function() {
setClickRoutePointHelp();
});
GEvent.addListener(amarker, "mouseout", function() {
restoreHelp();
});
GEvent.addListener(amarker, "dragstart", function() {
// $("debugpane").innerHTML+= "id: "+i+" "+this.getPoint().lat();
draglat = this.getPoint().lat();
draglng = this.getPoint().lng();
if (editMode == true) {
mouseMoveListener = GEvent.addListener(map, "mousemove", function(myLatLng) {
$("lat_input").value = retransformCoordinatesLat(myLatLng.lat());
$("lng_input").value = retransformCoordinatesLng(myLatLng.lng());
});
setDragRoutePointHelp();
}
});
GEvent.addListener(amarker, "dragend", function() {
GEvent.removeListener(mouseMoveListener);
for (var is = 0; is < route.length; is++) {
if ((route[is].lat==draglat) && (route[is].lng==draglng)) {
route[is].lat = this.getPoint().lat();
route[is].lng = this.getPoint().lng();
$("lat_input").value = retransformCoordinatesLat(route[route.length-1].lat);
$("lng_input").value = retransformCoordinatesLng(route[route.length-1].lng);
}
}
setFreeMapHelp();
setTimeout( function() {
buildRoute(false, false, true, this);
}, 100);
});
}
else if (markerClickable) {
GEvent.addListener(markerArray[j], "click", function() {
window.location = '?p='+this.post_id;
});
}
}
if (completeDistance>0) $("distances").innerHTML ='
'+$('transCompleteDistance').value+' '+(completeDistance/1852).toFixed(1)+' sm
'+ $("distances").innerHTML;
$("distances").innerHTML =''+$('transDistanceTitle').value+''+$("distances").innerHTML;
if (editMode == true) {
var mapData = '';
for (var is = 0; is < route.length; is++) {
if (is>0) mapData = mapData + ',';
if (route[is].title) {
mapData = mapData + '{ lat: ' + route[is].lat+', lng: '+route[is].lng+', title: "'+route[is].title+'"}';
}
else mapData = mapData + '{ lat: ' + route[is].lat+', lng: '+route[is].lng+'}';
}
if ($("option_endasstart").checked == true) {
if (is>0) mapData = mapData + ',{ lat: ' + route[0].lat+', lng: '+route[0].lng+' } ';
}
/*mapData = route.toJSONString();*/
$("mapData").value = "["+mapData+"]";
}
if (!clearNotOverlays) polyline = new GPolyline(GRoute, "#FF0000", 5);
else polyline = new GPolyline(GRoute, "#3333FF", 3);
if ((route.length>0) && (!notcenterandzoom)) map.centerAndZoomOnBounds(routingBounds);
map.addOverlay(polyline);
if (($("option_displayports")) && ($("option_displayports").checked == true)) {
getPorts(showPortPoints);
}
}
function Nets_ZoomArea(lat, lng, zoom) {
map.setCenter(new GLatLng (lat, lng), zoom+map.getZoom());
}
/******************************************************************
AJAX Part:
*/
function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(E) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) {}
try { return new XMLHttpRequest(); } catch(E) {}
alert("XMLHttpRequest not supported");
return null;
}
function $(id) { return document.getElementById(id); }
function setMessage(msg, newMsg) {
if ($("extblog_messages")!==null) {
if (!newMsg) $("extblog_messages").innerHTML += msg;
else $("extblog_messages").innerHTML = msg;
}
}
function encodeFormData(data) {
var pairs = [];
var regexp = /%20/g;
for (var name in data) {
var value = data[name].toString();
var pair = encodeURIComponent(name).replace(regexp, "+") + '=' +
encodeURIComponent(value).replace(regexp, "+");
pairs.push(pair);
}
return pairs.join("&");
}
function postRequest(url, data, callfunction, errorfunction) {
var xhr = createXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState==4) { /* Request finished */
if (xhr.status==200) {
if (callfunction) callfunction(xhr);
/* else setMessage ("
Retrieved from server: "+xhr.responseText); */
} else {
if (errorfunction) errorfunction(xhr);
else alert("Message returned, but with error status.");
}
}
}
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(encodeFormData(data));
}
function getAllStartPoints(post_id, subcallfunction) {
getStartPointsOfArea(90,180,-90,-180, function() {
startPoints = tempStartPoints;
if (subcallfunction) subcallfunction();
map.centerAndZoomOnBounds(startingBounds);
});
}
function getStartPoints(post_id, subcallfunction) {
getStartPointsOfArea(map.getBounds().getNorthEast().lat(), map.getBounds().getNorthEast().lng(), map.getBounds().getSouthWest().lat(), map.getBounds().getSouthWest().lng(), function() {
startPoints = tempStartPoints;
if (subcallfunction) subcallfunction();
});
}
function getPorts(subcallfunction) {
if (map.getBounds()==mapoldbounds) {
if (subcallfunction) subcallfunction();
}
else getPortsOfArea(map.getBounds().getNorthEast().lat(), map.getBounds().getNorthEast().lng(), map.getBounds().getSouthWest().lat(), map.getBounds().getSouthWest().lng(), map.getZoom() ,function() {
mapoldbounds = map.getBounds();
if (subcallfunction) subcallfunction();
});
}
function getStartPointsOfArea(ne_lat, ne_lng, sw_lat, sw_lng, subcallfunction) {
var requestdata = new Array();
requestdata["action"] = "getStartPoints";
requestdata["ne_lat"] = ne_lat;
requestdata["ne_lng"] = ne_lng;
requestdata["sw_lat"] = sw_lat;
requestdata["sw_lng"] = sw_lng;
mywaitOverlay = new waitOverlay();
map.removeOverlay(mywaitOverlay);
map.addOverlay(mywaitOverlay);
postRequest(pathModifier+"ajaxcall.php",
requestdata,
function(xhr) {
/* alert (xhr.responseText); */
tempStartPoints = eval ("("+xhr.responseText+")");
if (subcallfunction) subcallfunction();
/* var names = "";
for (var i=0; i< startPoints.length; i++) names += "->"+startPoints[i].lat+":"+startPoints[i].lng + "\n";
alert (names+" - "+xhr.responseText); */
map.removeOverlay(mywaitOverlay);
}
);
}
function aPort() {
this.lat = null;
this.lng = null;
this.icontype = null;
this.label = null;
}
function getPortsOfArea(ne_lat, ne_lng, sw_lat, sw_lng, zoom, subcallfunction) {
var requestdata = new Array();
requestdata["action"] = "getPorts";
requestdata["ne_lat"] = ne_lat;
requestdata["ne_lng"] = ne_lng;
requestdata["sw_lat"] = sw_lat;
requestdata["sw_lng"] = sw_lng;
requestdata["zoom"] = zoom;
requestdata["baseLang"] = baseLang;
requestdata["portOptions"] = implodeActivePortOptions();
//&Nets_CheckedElementsPort
if (mywaitOverlay) map.removeOverlay(mywaitOverlay);
mywaitOverlay = new waitOverlay();
map.addOverlay(mywaitOverlay);
postRequest(pathModifier+"ajaxcall.php",
requestdata,
function(xhr) {
var tempPortsXML = xhr.responseXML;
//alert (xhr.responseText);
/* alert(tempPortsXML.getElementsByTagName('marker')[0].getAttribute('label')); */
var names = "";
portPoints = new Array();
for (var i=0; i< tempPortsXML.getElementsByTagName('marker').length; i++) {
portPoints[i] = new aPort();
portPoints[i].lat = tempPortsXML.getElementsByTagName('marker')[i].getAttribute('lat');
portPoints[i].lng = tempPortsXML.getElementsByTagName('marker')[i].getAttribute('lng');
portPoints[i].icontype = tempPortsXML.getElementsByTagName('marker')[i].getAttribute('icontype');
portPoints[i].label = tempPortsXML.getElementsByTagName('marker')[i].getAttribute('label');
portPoints[i].html = tempPortsXML.getElementsByTagName('marker')[i].getAttribute('html');
}
if (subcallfunction) subcallfunction();
map.removeOverlay(mywaitOverlay);
}
);
}
function getRoutingPoints(post_id, subcallfunction, arg, arg2) {
var requestdata = new Array();
requestdata["action"] = "getRoutingPoints";
requestdata["post_id"] = post_id;
if (post_id>0) {
postRequest(pathModifier+"ajaxcall.php",
requestdata,
function(xhr) {
route = eval ("("+xhr.responseText+")");
if (!route[0].lng) route = new Array();
if ((subcallfunction) ) subcallfunction(arg, arg2);
}
);
}
else subcallfunction(arg);
}
/******************************
* Online Help functions
*/
var oldHelp = '';
var displayHelp = true;
function displayFreeMapHelp() {
if ($("displayonlinehelp").checked) displayHelp = true;
else displayHelp = false;
if (displayHelp) {
$("allmapbox").appendChild(toolTipDiv);
if ($("toolTipWindow").style.display) $("toolTipWindow").style.display = 'inline ;';
setFreeMapHelp();
dojo.lfx.html.fadeIn($("toolTipWindow"), 300).play();
setTimeout( function() {
if ($("toolTipWindow")) dojo.html.setOpacity($("toolTipWindow"), 0.8);
}, 400);
}
else {
if ($("toolTipWindow")) {
if ($("toolTipWindow").style.display) $("toolTipWindow").style.display = 'none ;';
$("displayonlinehelp").checked = false;
$("allmapbox").removeChild(toolTipDiv);
}
}
}
function setFreeMapHelp() {
toolTipDiv.innerHTML = 'Onlinehelp
';
toolTipDiv.innerHTML+= $("freeMapHelp").value;
toolTipDiv.innerHTML+= '[ x ]';
oldHelp = toolTipDiv.innerHTML ;
}
function hideFreeMapHelp() {
if ($("toolTipWindow")) {
if ($("toolTipWindow").style.display) $("toolTipWindow").style.display = 'none ;';
$("allmapbox").removeChild(toolTipDiv);
}
}
function setDragRoutePointHelp() {
oldHelp = toolTipDiv.innerHTML ;
toolTipDiv.innerHTML = 'Onlinehelp
';
toolTipDiv.innerHTML+= $("dragRoutePointHelp").value;
toolTipDiv.innerHTML+= '[ x ]';
/* 'You now adjust the position of one route point! When you release your mousebutton the new position will be used!'; */
}
function setClickRoutePointHelp() {
oldHelp = toolTipDiv.innerHTML ;
toolTipDiv.innerHTML = 'Onlinehelp
';
toolTipDiv.innerHTML+= $("clickRoutePointHelp").value;
toolTipDiv.innerHTML+= '[ x ]';
/* 'You can click onto this marker and hold the button to move this route point!'; */
}
function restoreHelp() {
toolTipDiv.innerHTML = oldHelp;
}
function doPortOption(optionbox) {
var actionDone = false;
for (var is = 0; is < portOptions.length; is++) {
if (portOptions[is]==optionbox.value) {
portOptions.splice(is);
actionDone = true;
break;
}
}
if (!actionDone) {
portOptions[portOptions.length] = optionbox.value;
}
if ($("option_displayports").checked == true) {
// map.clearOverlays();
buildRoute(false, false, true);
checkPortsDisplay();
// map.removeOverlay(mywaitOverlay);
}
}
function implodeActivePortOptions() {
var res = '';
for (var is = 0; is < portOptions.length; is++) {
res+=portOptions[is];
if (is+1