var mapaVOkoli = function (id) { this.ukazAdresu = function (bod) { this.mapa.setCenter (bod, this.priblizeni); } this.vytvorZnacku = function (index, informace) { var pismeno = String.fromCharCode ("A".charCodeAt(0) + index); var ikonaSPismenem = new GIcon (this.zakladniIkona); ikonaSPismenem.image = "http://www.portalymest.cz/images/ikonyMapa/marker" + pismeno + ".png"; var znackaMoznosti = {icon:ikonaSPismenem}; var znacka = new GMarker (new GLatLng(informace['lat'], informace['lng']), znackaMoznosti); var htmlZnacky = informace['htmlObrazky'] + "
"; var oknoMoznosti = {maxWidth:460}; GEvent.addListener (znacka, "click", function() { znacka.openInfoWindowHtml (htmlZnacky, oknoMoznosti); }); GEvent.addDomListener (document.getElementById ("pismeno" + pismeno), "click", function() { znacka.openInfoWindowHtml (htmlZnacky, oknoMoznosti); }); return znacka; } this.nactiOblast = function (zaznamy) { this.pocetCilu = zaznamy.length; if (zaznamy.length > 0) { var znacka; for (var i = 0; i < zaznamy.length; i++) { if (zaznamy[i] != '!neexistuje') { znacka = this.vytvorZnacku (i, zaznamy[i]); this.mapa.addOverlay (znacka); this.oblast.extend (znacka.getLatLng ()); this.cile[i] = znacka.getLatLng (); } } this.oblast.extend (this.stred); } } this.zobrazOblast = function () { if (!this.oblast.isEmpty ()) { this.mapa.setZoom (this.mapa.getBoundsZoomLevel (this.oblast)); this.mapa.setCenter (this.oblast.getCenter()); } } this.poziceNaKruhu = function (stred, uhel, polomer) { with (Math) { var d = polomer / 6372795; var lat1 = (PI / 180) * stred.lat (); var lng1 = (PI / 180) * stred.lng (); var tc = (PI / 180) * uhel; var y = asin (sin (lat1) * cos (d) + cos (lat1) * sin (d) * cos (tc)); var dlng = atan2 (sin (tc) * sin (d) * cos (lat1), cos (d) - sin (lat1) * sin (y)); var x = ((lng1 - dlng + PI) % (2 * PI)) - PI ; return new GLatLng (parseFloat (y * (180 / PI)), parseFloat (x * (180 / PI))); } } this.vzdalenostDvouBodu = function (bod1, bod2) { return bod1.distanceFrom (bod2, 6372795); } this.nakresliKruh = function (stred, polomer) { this.body = []; var bod; for (var i = 0; i < 72; i++) { bod = this.poziceNaKruhu (stred, i * 360 / 72, polomer); this.body.push (bod); this.oblast.extend (bod); } this.body.push (this.poziceNaKruhu (stred, 0, polomer)); this.mnohouhelnik = new GPolygon (this.body, '#d3222a', 1, 0.5, '#d3222a', 0.1); this.mapa.addOverlay (this.mnohouhelnik); } this.obnovKruhZPolomeru = function (cisloZnacky) { this.mapa.removeOverlay (this.mnohouhelnik); switch (cisloZnacky) { case 1: this.polomer = this.vzdalenostDvouBodu (this.stred, this.polomerZnacka1.getPoint ()); break; case 2: this.polomer = this.vzdalenostDvouBodu (this.stred, this.polomerZnacka2.getPoint ()); break; case 3: this.polomer = this.vzdalenostDvouBodu (this.stred, this.polomerZnacka3.getPoint ()); break; case 4: this.polomer = this.vzdalenostDvouBodu (this.stred, this.polomerZnacka4.getPoint ()); break; } this.nakresliKruh (this.stred, this.polomer); document.getElementById ('vzdalenost').value = Math.round (100 * this.polomer / 1000) / 100; switch (cisloZnacky) { case 1: this.polomerZnacka2.setLatLng (this.body[1 * 72 / 4]); this.polomerZnacka3.setLatLng (this.body[2 * 72 / 4]); this.polomerZnacka4.setLatLng (this.body[3 * 72 / 4]); break; case 2: this.polomerZnacka1.setLatLng (this.body[0 * 72 / 4]); this.polomerZnacka3.setLatLng (this.body[2 * 72 / 4]); this.polomerZnacka4.setLatLng (this.body[3 * 72 / 4]); break; case 3: this.polomerZnacka1.setLatLng (this.body[0 * 72 / 4]); this.polomerZnacka2.setLatLng (this.body[1 * 72 / 4]); this.polomerZnacka4.setLatLng (this.body[3 * 72 / 4]); break; case 4: this.polomerZnacka1.setLatLng (this.body[0 * 72 / 4]); this.polomerZnacka2.setLatLng (this.body[1 * 72 / 4]); this.polomerZnacka3.setLatLng (this.body[2 * 72 / 4]); break; } } this.obnovKruhZeStredu = function () { this.mapa.removeOverlay (this.mnohouhelnik); this.stred = this.stredKruhuZnacka.getPoint (); this.nakresliKruh (this.stred, this.polomer); this.polomerZnacka1.setLatLng (this.body[0 * 72 / 4]); this.polomerZnacka2.setLatLng (this.body[1 * 72 / 4]); this.polomerZnacka3.setLatLng (this.body[2 * 72 / 4]); this.polomerZnacka4.setLatLng (this.body[3 * 72 / 4]); } this.odesliFormular = function () { this.stred = this.stredKruhuZnacka.getPoint (); document.getElementById ('lat').value = this.stred.lat (); document.getElementById ('lng').value = this.stred.lng (); document.getElementById ('vzdalenost').value = Math.round (100 * this.vzdalenostDvouBodu (this.stred, this.polomerZnacka1.getPoint ()) / 1000) / 100; zaneprazdneno.zobraz (); document.formularVOkruhu.submit (); } this.odesliFormularStred = function () { this.stred = this.stredKruhuZnacka.getPoint (); document.getElementById ('lat').value = this.stred.lat (); document.getElementById ('lng').value = this.stred.lng (); zaneprazdneno.zobraz (); document.formularVOkruhu.submit (); } this.zobrazCestu = function () { //POZOR, neresi se jazyky a prevadi se tecka na carku a tisice nefunguji var vzdalenostVzduchem = parseFloat (this.vzdalenostDvouBodu (this.stred, this.cile[0])); if (vzdalenostVzduchem > 1000) vzdalenostVzduchem = (vzdalenostVzduchem / 1000).toFixed (2).toString ().replace('.', ',') + ' KM'; else vzdalenostVzduchem = parseInt (vzdalenostVzduchem).toString ().replace('.', ',') + ' M'; document.getElementById ('vzduchId' + this.aktualniCil).innerHTML = vzdalenostVzduchem; var status = this.cesty.getStatus (); if (status.code == 200) { var vzdalenostPoCeste = parseFloat (this.cesty.getDistance ().meters); if (vzdalenostPoCeste > 1000) vzdalenostPoCeste = (vzdalenostPoCeste / 1000).toFixed (2).toString ().replace('.', ',') + ' KM'; else vzdalenostPoCeste = parseInt (vzdalenostPoCeste).toString ().replace('.', ',') + ' M'; var sekundy = this.cesty.getDuration ().seconds; var hodiny = parseInt (sekundy / 3600); var minuty = parseInt (sekundy / 60) - (hodiny * 60); document.getElementById ('cestaId' + this.aktualniCil).innerHTML = vzdalenostPoCeste + ' / ' + doplnNulu (hodiny) + ':' + doplnNulu (minuty) + ' H'; var bodyDrahy = new Array (); var draha = this.cesty.getPolyline (); // var prirustek = Math.ceil (draha.getVertexCount () / 100); // alert (rychlost + ' ms - ' + draha.getVertexCount () + ' /++' + prirustek); // for (var n = 0; n < draha.getVertexCount () - 1; n = n + prirustek) { // bodyDrahy.push (draha.getVertex (n)); // } // var novaDraha = new GPolyline (bodyDrahy, '#0000ff', 2, 0.3); // this.mapa.addOverlay (novaDraha); this.mapa.addOverlay (draha); this.cile.shift (); var objekt = this; setTimeout (function () { objekt.nactiCestu (); }, 1000); } else if (status.code == 620) { var objekt = this; setTimeout (function () { objekt.nactiCestu (); }, 5000); } } this.nactiCestu = function () { if (!this.cile.length) return; var zBodu = this.stred.lat () + ' ' + this.stred.lng (); var doBodu = this.cile[0].lat () + ' ' + this.cile[0].lng (); this.aktualniCil = this.pocetCilu - this.cile.length; var retezec = 'from: ' + zBodu + ' to: ' + doBodu; this.cesty.load (retezec, { getPolyline : true, getSteps : true }); } this.inicializujCesty = function () { this.cesty = new GDirections(); var objekt = this; GEvent.addListener (this.cesty, "load", function () { objekt.zobrazCestu (); }); this.nactiCestu (); } this.inicializujKruh = function (stred, polomer) { this.stred = stred; this.polomer = polomer; var znackaMoznosti = { icon : this.polomerIkonaVer, draggable : true, bouncy : true }; this.polomerZnacka1 = new GMarker (this.poziceNaKruhu (this.stred, 0, this.polomer), znackaMoznosti); this.polomerZnacka3 = new GMarker (this.poziceNaKruhu (this.stred, 180, this.polomer), znackaMoznosti); this.mapa.addOverlay (this.polomerZnacka1); this.mapa.addOverlay (this.polomerZnacka3); var znackaMoznosti = { icon : this.polomerIkonaHor, draggable : true, bouncy : true }; this.polomerZnacka2 = new GMarker (this.poziceNaKruhu (this.stred, 90, this.polomer), znackaMoznosti); this.polomerZnacka4 = new GMarker (this.poziceNaKruhu (this.stred, 270, this.polomer), znackaMoznosti); this.mapa.addOverlay (this.polomerZnacka2); this.mapa.addOverlay (this.polomerZnacka4); var znackaMoznosti = { icon : this.stredKruhuIkona, draggable : true, bouncy : true }; this.stredKruhuZnacka = new GMarker (this.stred, znackaMoznosti); this.mapa.addOverlay (this.stredKruhuZnacka); var objekt = this; GEvent.addListener (this.polomerZnacka1, "dragend", function () { objekt.odesliFormular (); }); GEvent.addListener (this.polomerZnacka1, "drag", function () { objekt.obnovKruhZPolomeru (1); }); GEvent.addListener (this.polomerZnacka2, "dragend", function () { objekt.odesliFormular (); }); GEvent.addListener (this.polomerZnacka2, "drag", function () { objekt.obnovKruhZPolomeru (2); }); GEvent.addListener (this.polomerZnacka3, "dragend", function () { objekt.odesliFormular (); }); GEvent.addListener (this.polomerZnacka3, "drag", function () { objekt.obnovKruhZPolomeru (3); }); GEvent.addListener (this.polomerZnacka4, "dragend", function () { objekt.odesliFormular (); }); GEvent.addListener (this.polomerZnacka4, "drag", function () { objekt.obnovKruhZPolomeru (4); }); GEvent.addListener (this.stredKruhuZnacka, "dragend", function () { objekt.odesliFormular (); }); GEvent.addListener (this.stredKruhuZnacka, "drag", function () { objekt.obnovKruhZeStredu (); }); this.nakresliKruh (this.stred, this.polomer); } this.inicializujStred = function (stred) { this.stred = stred; var znackaMoznosti = { icon : this.stredKruhuIkona, draggable : true, bouncy : true }; this.stredKruhuZnacka = new GMarker (this.stred, znackaMoznosti); this.mapa.addOverlay (this.stredKruhuZnacka); var objekt = this; GEvent.addListener (this.stredKruhuZnacka, "dragend", function () { objekt.odesliFormularStred (); }); } if (GBrowserIsCompatible ()) { //nacteni prvotnich souradnic var pocatecniPozice = new GLatLng (49.866316729538674, 15.457763671875); this.priblizeni = 6; this.cile = new Array (); this.mapa = new GMap2 (document.getElementById (id)); this.mapa.setCenter (pocatecniPozice, this.priblizeni); this.mapa.addControl (new GLargeMapControl ()); this.mapa.addMapType (G_PHYSICAL_MAP); this.mapa.addControl (new GHierarchicalMapTypeControl ()); this.mapa.addControl (new GOverviewMapControl ()); this.mapa.addControl (new GScaleControl ()); this.oblast = new GLatLngBounds (); this.zakladniIkona = new GIcon (G_DEFAULT_ICON); this.zakladniIkona.shadow = "http://www.portalymest.cz/images/ikonyMapa/shadow50.png"; this.zakladniIkona.iconSize = new GSize (20, 34); this.zakladniIkona.shadowSize = new GSize (37, 34); this.zakladniIkona.iconAnchor = new GPoint (9, 34); this.zakladniIkona.infoWindowAnchor = new GPoint (9, 2); this.stredKruhuIkona = new GIcon (G_DEFAULT_ICON); this.stredKruhuIkona.shadow = "http://www.portalymest.cz/images/ikonyMapa/arrowshadow.png"; this.stredKruhuIkona.image = "http://www.portalymest.cz/images/ikonyMapa/arrow.png"; this.stredKruhuIkona.iconSize = new GSize (39, 34); this.stredKruhuIkona.shadowSize = new GSize (39, 34); this.stredKruhuIkona.iconAnchor = new GPoint (11, 34); this.stredKruhuIkona.infoWindowAnchor = new GPoint (11, 2); // this.stredKruhuIkona = new GIcon (G_DEFAULT_ICON); // this.stredKruhuIkona.image = "http://www.google.com/mapfiles/centerArrow.png"; // this.stredKruhuIkona.iconSize = new GSize (20, 20); // this.stredKruhuIkona.shadowSize = new GSize (0, 0); // this.stredKruhuIkona.iconAnchor = new GPoint (10, 10); // this.stredKruhuIkona.draggable = true; // this.stredKruhuIkona.bouncy = false; this.polomerIkonaHor = new GIcon (G_DEFAULT_ICON); this.polomerIkonaHor.image = "http://www.portalymest.cz/images/ikonyMapa/resizeArrowHor.png"; this.polomerIkonaHor.iconSize = new GSize (25, 20); this.polomerIkonaHor.shadowSize = new GSize (0, 0); this.polomerIkonaHor.iconAnchor = new GPoint (12, 10); this.polomerIkonaVer = new GIcon (G_DEFAULT_ICON); this.polomerIkonaVer.image = "http://www.portalymest.cz/images/ikonyMapa/resizeArrowVer.png"; this.polomerIkonaVer.iconSize = new GSize (20, 25); this.polomerIkonaVer.shadowSize = new GSize (0, 0); this.polomerIkonaVer.iconAnchor = new GPoint (10, 12); } };