//object class to view google map //WDomain - actual domain //Address - address to show //outputArea - html container where we will show out map // function GoogleMapProto(WDomain, OutputArea) { this.myVer = 2; switch (WDomain) { case 'wtr.taxi': this.myKey = 'ABQIAAAA1eEnuPuMm5tkOPY8mg9kfBSLmxWtDqbtZyU4lxaMFqQehIvB_hRVWi2hwdRZUbqRGpVDzSOlvs5NHA'; break; case 'taxi.waytorussia.net': this.myKey = 'ABQIAAAA1eEnuPuMm5tkOPY8mg9kfBQnjJpPpIyYPtdbS5F6Y5qhd4mSaRRIIWei1yF5JqEnZO2PGXlZ2YUvLQ'; break; case 'test-plaza.ru': this.myKey = 'ABQIAAAA1eEnuPuMm5tkOPY8mg9kfBRB9IvPf2IT7pcHXX7ySfrhrjzb6BSAkpUTuXdw69f4T7TxLypEg4jghw'; break; case 'www.waytorussia.net': case 'waytorussia.net': this.myKey = 'ABQIAAAA1eEnuPuMm5tkOPY8mg9kfBSJPM67syAaVqu1U-s85PlwVd-5pRSmYWgULIDKtQcRqhQOUbktb94XHA'; break; default: alert('Unknown domain!'); return false; } this.myLng = 'en'; this.area = OutputArea; this.Area = 'Russia, Moscow, '; this.map = null; // Google map object this.DIR = null; // for route search this.init = function () { this.pA = [0, 0, null]; this.pB = [0, 0, null]; if (this.map != null) { this.map.clearOverlays(); this.bounds = new GLatLngBounds(); } // document.getElementById('routeDescr').innerHTML = ''; } this.arrivalPointNotFound = 'Sorry, we didn`t find the point of your arrival, so you can place your marker on the map manually or just leave the address as it is, and the taxi provider will contact you with a non-obligatory quote.'; this.destinationPointNotFound = 'Sorry, we didn`t find the point of your destination, so you can place your marker on the map manually or just leave the address as it is, and the taxi provider will contact you with a non-obligatory quote.'; this.init(); //script tag var scriptTag = '<' + 'script src="http://maps.google.com/maps?file=api&v=' + this.myVer + '&key=' + this.myKey + '&hl=' + this.myLng + '">'+'<'+'/script>'; document.write(scriptTag); //show points A and B, and make zoom this.showAB = function() { // alert(this.pA[0] + ' ' + this.pA[1]); if (this.map != null) { var z = this; GID(this.area).style.display = 'block'; var found = 0; if (this.pA[0] && this.pA[2] == null) { this.pA[2] = new GMarker(new GLatLng(this.pA[0], this.pA[1]), { clickable : true, draggable : true, title : 'point A', icon : G_DEFAULT_ICON}); GEvent.addDomListener(this.pA[2], "dragend", function () { z.markerDragEnd(this); }); this.map.addOverlay(this.pA[2]); } if (this.pA[0]) { found = 1; this.bounds.extend(new GLatLng(this.pA[0], this.pA[1])); } if (this.pB[0] && this.pB[2] == null) { this.pB[2] = new GMarker(new GLatLng(this.pB[0], this.pB[1]), { clickable : true, draggable : true, title : 'point B', icon : G_DEFAULT_ICON}); GEvent.addDomListener(this.pB[2], "dragend", function () { z.markerDragEnd(this); }); this.map.addOverlay(this.pB[2]); } if (this.pB[0]) { found = 1; this.bounds.extend(new GLatLng(this.pB[0], this.pB[1])); } if (this.pA[2] != null && this.pB[2] != null && this.pA[0] == this.pB[0] && this.pA[1] == this.pB[1]) { this.map.setCenter(new GLatLng(55.755786, 37.617633), 13, G_NORMAL_MAP); found = 0; alert('Point A and Point B have the equal coordinates!'); } if (found) { this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds)); this.map.setCenter(this.bounds.getCenter()); } } } this.mapClick = function(overlay, point) { var found = 0; if (this.pA[2] == null) { this.pA = [point.lat(), point.lng(), null]; found = 1; } if (this.pB[2] == null) { this.pB = [point.lat(), point.lng(), null]; found = 1; } if (found) this.showAB(); } //обработка перемещения точек А и Б this.markerDragEnd = function(m) { er = m.getLatLng(); switch (m.getTitle()) { case 'point A': this.pA[0] = er.lat(); this.pA[1] = er.lng(); break; case 'point B': this.pB[0] = er.lat(); this.pB[1] = er.lng(); break; } } this.showMap = function (Addr1, glat1, glng1, Addr2, glat2, glng2) { this.createMap(); this.progressPoint = 0; this.init(); if (glat1 == '0' && glng1 == '0') { var geocoder = new GClientGeocoder(); var z = this; geocoder.getLatLng(this.Area + Addr1, function(anb) { if (anb == null) alert(z.arrivalPointNotFound); else z.pA = [anb.lat(), anb.lng(), null]; z.showAB(); if (z.progressPoint ++) z.findRoute(); }); } else { this.pA = [glat1, glng1, null]; this.showAB(); this.progressPoint ++ } if (glat2 == '0' && glng2 == '0') { var geocoder = new GClientGeocoder(); var z = this; geocoder.getLatLng(this.Area + Addr2, function(anb) { if (anb == null) alert(z.destinationPointNotFound); else z.pB = [anb.lat(), anb.lng(), null]; z.showAB(); if (z.progressPoint ++) z.findRoute(); }); } else { this.pB = [glat2, glng2, null]; this.showAB(); this.findRoute(); } } this.translateMap = function (Addr1, glat1, glng1, Addr2, glat2, glng2, func) { this.progressPoint = 0; if (glat1 == '0' && glng1 == '0') { var geocoder = new GClientGeocoder(); var z = this; geocoder.getLatLng(this.Area + Addr1, function(anb) { if (anb == null) alert(z.arrivalPointNotFound); else { z.pA = [anb.lat(), anb.lng(), null]; } if (z.progressPoint++) eval(func + "();"); }); } else { this.pA = [glat1, glng1, null]; this.progressPoint++; } if (glat2 == '0' && glng2 == '0') { var geocoder = new GClientGeocoder(); var z = this; geocoder.getLatLng(this.Area + Addr2, function(anb) { if (anb == null) alert(z.destinationPointNotFound); else { z.pB = [anb.lat(), anb.lng(), null]; } if (z.progressPoint++) eval(func + "();"); }); } else { this.pB = [glat2, glng2, null]; if (this.progressPoint++) eval(func + "();"); } } this.createMap = function() { if (this.map == null) { if (GBrowserIsCompatible()) { this.map = new GMap2(document.getElementById(this.area), { size: new GSize(380, 350) } ); this.map.addControl(new GSmallMapControl()); // this.map.enableScrollWheelZoom(); this.map.removeMapType(G_HYBRID_MAP); G_NORMAL_MAP.getName = function () { return 'Normal';} G_NORMAL_MAP.getAlt = function () { return 'Show map with street names';} G_SATELLITE_MAP.getName = function () { return 'Satellite';} G_SATELLITE_MAP.getAlt = function () { return 'Show map from satellite';} this.map.setMapType(G_NORMAL_MAP); this.map.addControl(new GMapTypeControl()); var z = this; //events GEvent.addListener(this.map, 'click', function(overlay, point) { z.mapClick(overlay, point); }); // GEvent.addDomListener(this.map, "click", // function (marker) { z.markerClick(marker); }); } else { alert('It is not supported browser.'); return null; } } this.map.clearOverlays(); this.map.setCenter(new GLatLng(55.755786, 37.617633), 10, G_NORMAL_MAP); } this.findRoute = function() { if (this.pA[0] == 0 || this.pB[0] == 0) { alert('Open map and setup from where and to where you want to go.'); } else { if (this.pA[0] == this.pB[0] && this.pA[1] == this.pB[1]) return 0; var waypoints = [new GLatLng(this.pA[0], this.pA[1]), new GLatLng(this.pB[0], this.pB[1])]; if (this.DIR == null) { this.DIR = new GDirections(this.map, GID('routeDescr')); GEvent.addDomListener(this.DIR, "error", function () { alert('Can`t solve this route!'); }); } else this.DIR.clear(); GID('routeDescr').innerHTML = ''; this.DIR.loadFromWaypoints(waypoints); } } }