///////////////////////////////////////////////////////////////////////////////////////
// to do
// small window done
// directions show-hide done
// context menu
// styles in windows done
// back to original map done
// paths
// tooltips (4, 5,6) done
// multiple search
///////////////////////////////////////////////////////////////////////////////////////
var mapshort=1;
var ln1=41.10729;
var ln2=25.76456;
var i = 0;
var rep=0;
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var htmlsen = [];
var to_htmlsen = [];
var from_htmlsen = [];
var side_bar_html = "";
var gmarkers = [];
var gmarkersVisible = [];
var gpolylines = [];
var numLines =0;
var map = null;
var ov = null;
var ovcontrol = null;
var gdir=null;
var contextmenu = null;
var cluster = null;
////////////////////////////////////////////////////////////////////////
// === Array for decoding the failure codes ===
var reasons=[];
/* reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed.";
reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";
*/
function startMap()
{
map = null;
ov = null;
ovcontrol = null;
gdir=null;
contextmenu = null;
}
/////////////////////////////////////////////////////////////////////
function initMap()
{
//alert(G_GEO_SUCCESS);
// Display the map, with some controls and set the initial location
var mpObj = document.getElementById("map");
// alert(mpObj);
//try{
if (mpObj==null)
{
setTimeout("initMap();", 100);
return;
}
// alert(map);
map = new GMap2(mpObj);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
//map.addControl(GSmallZoomControl3D());
setControls();
initDirections();
createMarkers();
createPolylines();
addOverview();
addContextMenu();
addClusterMarker();
addHTMLControl();
//}catch(err){alert(err);};
}
function resizeMap()
{
var valChange=0;
if (mapshort==1)
{
parent.document.getElementById("left").style.display="none";
// parent.document.getElementById("footer").style.marginLeft="243px";
parent.document.getElementById('top').style.marginLeft='243px';
parent.document.getElementById("mapdiv").style.width="940px";
parent.document.getElementById("FRAME2").style.width="940px";
$("map").style.width="918px";
parent.document.getElementById("mapdiv").style.height="660px";
parent.document.getElementById("FRAME2").style.height="658px";
$("map").style.height="638px";
// map.setCenter(new GLatLng(ln1,ln2), 9);
if ($('directions').style.display!="none")
{
$("map").style.width="708px";
$("directions").style.height="610px";
$("legend").style.marginLeft="710px";
}
}
if (mapshort==0)
{
parent.document.getElementById("left").style.display="block";
// parent.document.getElementById("footer").style.marginLeft="0px";
parent.document.getElementById('top').style.marginLeft='0px';
parent.document.getElementById("mapdiv").style.width="680px";
parent.document.getElementById("FRAME2").style.width="678px";
if ($('directions').style.display!="none")
{
$("map").style.width="448px";
$("directions").style.height="610px";
$("legend").style.marginLeft="450px";
}
else
{
$("map").style.width="658px";
}
parent.document.getElementById("mapdiv").style.height="660px";
parent.document.getElementById("FRAME2").style.height="658px";
$("map").style.height="638px";
mapshort=1;
valChange=1;
}
if (mapshort==1 && valChange==0)
{
mapshort=0;
}
if (ovcontrol !=null)
{
map.removeControl(ovcontrol);
map.addControl(ovcontrol);
}
}
/////////////////////////////////////////////////////////////////////////////
function setControls()
{
$('directions').style.display="none";
$("mapfoot").style.display="none";
$("map").style.width="658px";
map.setCenter(new GLatLng(ln1,ln2), 9);
map.setMapType(G_HYBRID_MAP );
map.setZoom(9);
if (gdir)
{
gdir.clear();
}
map.closeInfoWindow();
}
//////////////////////////////////////////////////////////////////////////////
function initDirections()
{
gdir=new GDirections(map, document.getElementById("directions"));
// === catch Directions errors ===
GEvent.addListener(gdir, "error", function() {
var code = gdir.getStatus().code;
var reason="Code "+code;
if (reasons[code]) {
reason = reasons[code]
}
alert("Δυστυχώς δε βρέθηκε διαδρομή, παρακαλώ προσπαθήστε με διαφορετικά ή κοντινά σημεία, "+reason);
resetControls();
});
}
/////////////////////////////////////////////////////////////////////////////
function resetControls()
{
$("legend").style.display="none";
$('directions').style.display="none";
document.getElementById("mapfoot").style.display="none";
if (mapshort==1)
{
$("map").style.width="658px";
}
else
{
// alert(mapshort);
$("map").style.width="918px";
}
if (map.getZoom()<9)
{
map.setCenter(new GLatLng(ln1,ln2), 9);
}
if (gdir)
{
gdir.clear();
}
if (ovcontrol !=null)
{
map.removeControl(ovcontrol);
map.addControl(ovcontrol);
}
}
//////////////////////////////////////////////////////////////////////////////
function createMarkers()
{
//alert('createmarkers '+gmarkers.length);
new Ajax.Request('data.php',
{ method:'get',
onFailure: function()
{
alert('Something went wrong...')
},
onSuccess: function(transport)
{
var response = transport.responseText || "no response text";
var xmlDoc = GXml.parse(transport.responseText);
// obtain the array of markers and loop through it
var xmlDoc = GXml.parse(transport.responseText);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
//alert(markers.length);
for (i = 0; i < markers.length; i++)
{
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var style = parseFloat(markers[i].getAttribute("style"));
var cat = parseFloat(markers[i].getAttribute("category"));
var catStr = ""+cat;
if (cat<10) catStr = "0"+catStr;
catStr =catStr +".PNG";
//alert(catStr);
var point = new GLatLng(lat,lng);
// if (i==1) alert(markers[i].getElementsByTagName("image")[0].childNodes[0].nodeValue);
var link = markers[i].getElementsByTagName("link")[0].childNodes[0].nodeValue;
var image = markers[i].getElementsByTagName("image")[0].childNodes[0].nodeValue;
var label = markers[i].getElementsByTagName("label")[0].childNodes[0].nodeValue;
var labelen = markers[i].getElementsByTagName("labelen")[0].childNodes[0].nodeValue;
var htmlText = markers[i].getElementsByTagName("html")[0].childNodes[0].nodeValue;
var htmlTexten = markers[i].getElementsByTagName("htmlen")[0].childNodes[0].nodeValue;
// var imageIcon = markers[i].getElementsByTagName("icon")[0].childNodes[0].nodeValue;
// alert('');
// if (i==1) alert(' :'+htmlText);
var icon = getIcon(catStr);//new GIcon();
if (cat==15) htmlText = htmlText+'
'+'Η Θέση του ξενώνα για τους χρήστες GPS είναι N '+lat+' E '+lng+'';
if (cat==15) htmlTexten = htmlTexten+'
'+'Η Θέση του ξενώνα για τους χρήστες GPS είναι N '+lat+' E '+lng+'';
var html = getHTML(style, label,link, image,htmlText) ;
var htmlen = getHTML(style, labelen,link, image,htmlTexten) ;
htmls[i]=html;
// directions
// directions
// The info window version with the "to here" form open
to_htmls[i] = html + '
';
// The info window version with the "from here" form open
from_htmls[i] = html + '';
// The inactive version of the direction info
html = html + '';
///////////////ENGLISH
// The info window version with the "to here" form open
to_htmlsen[i] = htmlen + '';
// The info window version with the "from here" form open
from_htmlsen[i] = htmlen + '';
// The inactive version of the direction info
htmlen = htmlen + '';
if (style==3 && rep==1) {rep=2;alert(html);}
// create the marker
// if (i%10==0) alert(i+' '+html);
//if (i>1) continue;
//alert(i+' '+html);
var marker = createMarker(point,label,icon, html,cat);
map.addOverlay(marker);
marker.hide();
}// end of markers
}// end of function
});
//alert(xenones);
}
///////////////////////////////////////////////////////////////////////////
function createPolylines()
{
new Ajax.Request('data.php',
{ method:'get',
onFailure: function()
{
alert('Something went wrong...')
},
onSuccess: function(transport)
{
var response = transport.responseText || "no response text";
var xmlDoc = GXml.parse(transport.responseText);
// obtain the array of markers and loop through it
var xmlDoc = GXml.parse(transport.responseText);
// ========= Now process the polylines ===========
var lines = xmlDoc.documentElement.getElementsByTagName("line");
// read each line
numLines=lines.length;
//alert("FOUND "+numLines);
for (var a = 0; a < numLines; a++)
{
// get any line attributes
var colour = lines[a].getAttribute("colour");
var width = parseFloat(lines[a].getAttribute("width"));
var txt = lines[a].getAttribute("html");
var title = lines[a].getAttribute("name");
var video = lines[a].getAttribute("video");
// read each point on that line
var points = lines[a].getElementsByTagName("point");
var pts = [];
for (var i = 0; i < points.length; i++)
{
pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
parseFloat(points[i].getAttribute("lng")));
}
var polyline = new GPolyline(pts,colour,width,1);
// alert(pts.length+polyline);
map.addOverlay(polyline);
polyline.hide();
//
gpolylines.push(polyline);
var tx =getHTMLLine(7, title,"default", video,txt);
addPolylineListener(polyline, tx);
}
// alert(gpolylines.length+' '+numLines);
}// end of function
});
// alert(gpolylines.length+' '+numLines);
}
////////////////////////////////////////////////////////////
function addPolylineListener(pol, html)
{
GEvent.addListener(pol, "click", function(para) {
// alert(pol.getLength()+" "+html);
map.openInfoWindowHtml(para,html);
}
);
}
//////////////////////////////////////////////////////////////////////////////
function createMarker(point,name,icon, html, cat)
{
var marker = new GMarker(point, {icon:icon,title:name, zIndexProcess:importanceOrder});
marker.mycategory = cat;
marker.myname = name;
marker.importance=0;
function importanceOrder (marker,b) {
// return -GOverlay.getZIndex(marker.getPoint().lat());
return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
}
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
// alert(name);
// save the info we need to use later for the side_bar
gmarkers.push(marker);
htmls[i] = html;
return marker;
}
/////////////////////////////////////////////////////////////////////
function addClusterMarker()
{
if (gmarkers.length==0)
{
setTimeout("addClusterMarker();", 100);
return;
}
cluster=new ClusterMarker(map,
{
clusterMarkerTitle:'Click to see info about %count locations' ,
intersectPadding:-1,
borderPadding:-1,
clusterMarkerClick:myClusterClick,
markers:gmarkersVisible
});
cluster.removeMarkers();
// alert(gmarkersVisible.length);
cluster.addMarkers(gmarkersVisible);
/////////////////////////////////////////
try{
cluster.refresh(true); //throws error
// cluster.fitMapToMarkers(); //throws error
}catch(err){}
function myClusterClick(args)
{
cluster.defaultClickAction=function()
{
map.setCenter(args.clusterMarker.getLatLng(), map.getBoundsZoomLevel(args.clusterMarker.clusterGroupBounds))
delete cluster.defaultClickAction;
}
var h = 50+args.clusteredMarkers.length*25;
var html=''+args.clusteredMarkers.length+' Τοποθεσίες: ';
// args.clusterMarker.openInfoWindowHtml(html);
map.openInfoWindowHtml(args.clusterMarker.getLatLng(), html);
map.setCenter(args.clusterMarker.getLatLng(), map.getBoundsZoomLevel(args.clusterMarker.clusterGroupBounds))
map.setZoom(14);
}
// create a ClusterMarker
}
/////////////////////////////////////////////////////////////////////
function removeClusterMarker()
{
cluster.removeMarkers();
cluster.addMarkers(gmarkersVisible);
cluster.refresh(true);
// cluster.fitMapToMarkers();
}
/////////////////////////////////////////////////////////////////////
function addOverview()
{
try
{
// ======== Add a map overview ==========
// ======== save a reference to the control =========
ovcontrol = new GOverviewMapControl(new GSize(150,150));
map.addControl(ovcontrol);
}catch(err){alert(err);}
// ======== Cause the overview to be positioned AFTER IE sets its initial position ========
// setTimeout("positionOverview(508,254);",5000);
// ======== change the overview map type AFTER the overview finisges initializing =====
// setTimeout("setOverviewZoom()",100);
}
//////////////////////////////////////////////////////////////////////////
function setOverviewZoom()
{
//alert('ovcontrol='+ovcontrol);
if (ovcontrol)
{
ovmap = ovcontrol.getOverviewMap();
if (ovmap!=null)
{
//alert('ovmap='+ovmap);
// ovmap.setMapType(G_SATELLITE_MAP);
// alert('ovmap='+ovmap);
// ovmap.setZoom(10);
}
else
{
setTimeout("setOverviewZoom()",1000);
}
}
else
{
setTimeout("setOverviewZoom()",1000);
}
}
////////////////////////////////////////////////////////////////////////////
// ======== A function to adjust the positioning of the overview ========
function positionOverview(x,y) {
var omap=document.getElementById("map_overview");
alert(ovmap);
omap.style.left = x+"px";
omap.style.top = y+"px";
// == restyling ==
omap.firstChild.style.border = "1px solid gray";
omap.firstChild.firstChild.style.left="4px";
omap.firstChild.firstChild.style.top="4px";
omap.firstChild.firstChild.style.width="190px";
omap.firstChild.firstChild.style.height="190px";
}
///////////////////////////////////////////////////////////////////////
// ===== request the directions =====
function getDirections()
{
// $('mapprint').innerHTML='Εκτύπωση οδηγιών';
$('directions').innerHTML='
Αναζητούνται οδηγίες κατεύθυνσης, παρακαλώ περιμένετε...';
// ==== Set up the walk and avoid highways options ====
var opts = {};
if (document.getElementById("walk").checked) {
opts.travelMode = G_TRAVEL_MODE_WALKING;
}
if (document.getElementById("highways").checked) {
opts.avoidHighways = true;
}
opts.getSteps=true;
opts.locale="el";
// ==== set the start and end locations ====
var saddr = document.getElementById("saddr").value;
var daddr = document.getElementById("daddr").value;
var maddr = document.getElementById("maddr").value;
saddr = getCoordinates(saddr);
daddr = getCoordinates(daddr);
maddr = getCoordinates(maddr);
// alert(saddr);
// $("legend").style.width="200px";
$("directions").style.width="210px";
if (mapshort==1)
{
$("map").style.width="448px";
$("directions").style.height="610px";
}
else
{
$("map").style.width="708px";
$("directions").style.height="610px";
}
document.getElementById("legend").style.display="block";
$("directions").style.display="block";
if (ovcontrol !=null)
{
map.removeControl(ovcontrol);
map.addControl(ovcontrol);
}
map.closeInfoWindow();
if (maddr=='')
{
var route = "from: "+saddr+" to: "+daddr;
// alert(route);
gdir.load(route, opts);
}
else
{
// var route = 'from: 47.400000,-122.210000 to:47.470000,-122.330000 ' +
// ' to: 47.400000,-122.210000';
var route = 'from: '+saddr+' to:'+maddr +
' to: '+daddr;
// alert(route);
//gdir.load("from: "+saddr+" to: "+maddr+" to: "+daddr, opts);
gdir.load(route, opts);
}
//setTimeout("positionOverview(508,254);",5000);
GEvent.addListener(gdir,"load", function()
{
setTimeout('customPanel(map,"map",gdir,$("directions"))', 100);
});
}
///////////////////////////////////////////////////////////////////
// ============ custom direction panel ===============
function customPanel(map,mapname,dirn,div)
{
var html = "";
// ===== local functions =====
// === waypoint banner ===
function waypoint(point, type, address) {
var target = '"' + mapname+".showMapBlowup(new GLatLng("+point.toUrlValue(6)+"))" +'"';
html += '';
html += ' ';
html += ' ';
html += ' Πίσω στον Χάρτη';
html += ' <\/td>';
html += ' <\/tr>';
html += ' |
';
html += ' ';
html += ' Εκτύπωση οδηγιών';
html += ' <\/td>';
html += ' <\/tr>';
html += ' |
';
html += ' ';
html += address;
html += ' <\/td>';
html += ' <\/tr>';
html += '<\/table>';
}
// === route distance ===
function routeDistance(dist) {
html += '' + dist + '<\/div>';
}
// === step detail ===
function detail(point, num, description, dist) {
var target = '"' + mapname+".showMapBlowup(new GLatLng("+point.toUrlValue(6)+"))" +'"';
html += ' ';
html += ' ';
html += ' | ';
html += ' '+num+'. <\/a>';
html += ' <\/td>';
html += ' | ';
html += description;
html += ' ('+dist+')';
html += ' <\/td>';
html += ' <\/tr>';
html += '<\/table>';
}
// === Copyright tag ===
function copyright(text) {
html += ' ' + text + "<\/div>";
}
// === read through the GRoutes and GSteps ===
for (var i=0; i | |