function CaLrCVInterface(map) { this.map = map; // map interface object this.isOn; this.icon; this.urlIcon = 'http://www.cykloserver.cz/img/cv.gif'; this.groupCount; this.groupIndex; this.groupIds; this.groupMarkers; this.infoBox; this.httpRequest; this.pUpdateRequest; this.pShowDetailRequest; this.popup; this.txtErrorMessage; this._create = function() { this.initInfoBox(); this.attachEvents(); } this.initialize = function() { this.isOn = false; this.groupCount = 10; this.groupIndex = 0; this.groupIds = new Array(); this.groupMarkers = new Array(); for (var ti = 0; ti < this.groupCount; ti++) { this.groupIds[ti] = new Array(); this.groupMarkers[ti] = new Array(); } this.httpRequest = null; this.pUpdateRequest = jQuery.proxy(this.updateRequest, this); this.pShowDetailRequest = jQuery.proxy(this.showDetailRequest, this); this.icon = { externalGraphic: this.urlIcon, graphicWidth: 28, graphicHeight: 38, graphicXOffset: -14, graphicYOffset: -37, cursor: 'pointer' }; this.attachEvents(); } this.flipLayer = function() { if (!this.isOn) { this.show(); } else { this.hide(); } } this.show = function() { if (!this.isOn) { this.isOn = true; this.update(); } } this.update = function() { if (!this.updateCallback) this.updateCallback = jQuery.proxy(this.updateFunction, this); if (this.updateTimer) { clearTimeout(this.updateTimer); } this.updateTimer = setTimeout(this.updateCallback, 200); } this.updateFunction = function() { var ids = ""; for (var ti = 0; ti < this.groupCount; ti++) { if (ti != this.groupIndex) { var ts = this.groupIds[ti].join(';'); if ((ids.length > 0) && (ts.length > 0)) ids+= ';'; if (ts.length > 0) ids+= ts; } } //alert(ids); var bbox = this.map.getBoundsObj(); var url = 'http://www.cykloserver.cz/cykloatlas/cvlrprepare.php'; var params = 'bbminx=' + bbox.left + '&bbminy=' + bbox.bottom + '&bbmaxx=' + bbox.right + '&bbmaxy=' + bbox.top + '&ids=' + ids; //alert(params); if (window.ActiveXObject) { this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } else { this.httpRequest = new XMLHttpRequest(); } this.httpRequest.open("POST", url, true); this.httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); this.httpRequest.setRequestHeader("Content-length", params.length); this.httpRequest.setRequestHeader("Connection", "close"); this.httpRequest.onreadystatechange = this.pUpdateRequest; this.httpRequest.send(params); } this.updateRequest = function() { if (this.httpRequest.readyState == 4) { if (this.httpRequest.status == 200) { var turolrfileparts = this.httpRequest.responseText.split("|"); if (turolrfileparts.length != 2) { alert(this.txtErrorMessage); } else { var ids = turolrfileparts[1].split("-"); var ids = ids[1]; this.insertIds(ids); } } } } this.clearLayer = function() { this.groupIndex = 0; for (var ti = 0; ti < this.groupCount; ti++) { for (var ti2 = 0; ti2 < this.groupMarkers[ti].length; ti2++) { if (this.groupMarkers[ti][ti2] != null) { this.map.removeMarker(this.groupMarkers[ti][ti2]); this.groupMarkers[ti][ti2].destroy(); this.groupMarkers[ti][ti2] = null; } } this.groupIds[ti] = new Array(); this.groupMarkers[ti] = new Array(); } } this.insertIds = function(ids) { if (ids.length) { ids = ids.split('/'); var idstmp = new Array(); var markerstmp = new Array(); for (var ti = 0; ti < ids.length; ti++) { var p = ids[ti].split(":"); idstmp.push(p[0]); var marker = this.createMarker(new OLM.LatLng(p[2], p[1]), p[3], idstmp.length, p[0]); this.map.addMarker(marker); markerstmp.push(marker); } for (var ti = 0; ti < this.groupMarkers[this.groupIndex].length; ti++) { this.map.removeMarker(this.groupMarkers[this.groupIndex][ti]); this.groupMarkers[this.groupIndex][ti].destroy(); } this.groupIds[this.groupIndex] = idstmp; this.groupMarkers[this.groupIndex] = markerstmp; this.groupIndex = (this.groupIndex + 1) % this.groupCount; } } this.createMarker = function(pos, name, id, objid) { var icon = { externalGraphic: this.icon.externalGraphic, graphicWidth: this.icon.graphicWidth, graphicHeight: this.icon.graphicHeight, graphicXOffset: this.icon.graphicXOffset, graphicYOffset: this.icon.graphicYOffset, cursor: this.icon.cursor }; var marker = OLM.Markers.createMarker(pos, this.map, icon); marker.title = name; marker.cCaInt = this; marker.utilItemIndex = id; marker.utilItemObjIndex = objid; marker.clickMarker = function() { this.cCaInt.clickItem(this); } marker.onMouseOver = function(ev) { this.cCaInt.selectItem(this); } marker.onMouseOut = function(ev) { this.cCaInt.unselectItem(this); } marker.onMouseClick = function(ev) { this.clickMarker(); } return marker; } this.clickItem = function(marker) { this.showDetail(marker.utilItemObjIndex); } this.selectItem = function(marker) { var p = marker.geometry.clone(); var latLng = this.map.getLatLngFromLonLat(new OpenLayers.LonLat(p.x, p.y)); this.infoBox.showAt(latLng, marker.title); } this.unselectItem = function(marker) { this.infoBox.hide(); } this.showDetail = function(id) { url = "loadcvinfo.php?id=" + id; if (window.ActiveXObject) { this.httpRequestCVinfo = new ActiveXObject("Microsoft.XMLHTTP"); } else { this.httpRequestCVinfo = new XMLHttpRequest(); } this.httpRequestCVinfo.open("GET", url, true); this.httpRequestCVinfo.onreadystatechange = this.pShowDetailRequest; this.httpRequestCVinfo.send(null); } this.showDetailRequest = function() { if (this.httpRequestCVinfo.readyState == 4) { if (this.httpRequestCVinfo.status == 200) { var doc; if (doc = this.httpRequestCVinfo.responseXML) { if (doc.getElementsByTagName("found")[0].firstChild.data != "1") { } else { var p_kontakt = ""; p_kontakt+= "

"; p_kontakt+= "" + this.itemDecode(doc.getElementsByTagName("nazev")[0].firstChild.data)+"
"; p_kontakt+= this.itemDecode(doc.getElementsByTagName("adresa")[0].firstChild.data)+"
"; p_kontakt+= this.itemDecode(doc.getElementsByTagName("tel1")[0].firstChild.data)+"
"; if (doc.getElementsByTagName("tel2")[0].childNodes.length) p_kontakt+= this.itemDecode(doc.getElementsByTagName("tel2")[0].firstChild.data) + "
"; if (doc.getElementsByTagName("email")[0].childNodes.length) p_kontakt+= "" + this.itemDecode(doc.getElementsByTagName("email")[0].firstChild.data) + "
"; if (doc.getElementsByTagName("www")[0].childNodes.length) p_kontakt+= "" + this.itemDecode(doc.getElementsByTagName("www")[0].firstChild.data) + "
"; p_kontakt+= "GPS: " + this.convertDtoDMS(this.itemDecode(doc.getElementsByTagName("gpslat")[0].firstChild.data)) + "N, " + this.convertDtoDMS(this.itemDecode(doc.getElementsByTagName("gpslng")[0].firstChild.data)) + "E
"; p_kontakt+= "

"; var p_sluzby = "Služby
"; var sluzby_items = ""; var sluzby_items_a = this.itemDecode(doc.getElementsByTagName("vlastnosti")[0].firstChild.data).split('|'); if (sluzby_items_a.length) { var afters = false; for (var ti = 0; ti < sluzby_items_a.length; ti++) { if (afters == true) { //sluzby_items+= "
Nadstandardní služby
"; afters = false; } //sluzby_items+= " - " + sluzby_items_a[ti] + "
"; sluzby_items+= "
- " + sluzby_items_a[ti] + "
"; if (sluzby_items_a[ti] == "Smlouva o certifikaci") afters = true; } } p_sluzby+= sluzby_items; var p_fotky = "
Fotografie
"; p_fotky+= ""; p_fotky+= ""; p_fotky+= ""; p_fotky+= ""; this.hideDetail(); var ll = this.map.fromLatLng(new OLM.LatLng(this.itemDecode(doc.getElementsByTagName("gpslat")[0].firstChild.data), this.itemDecode(doc.getElementsByTagName("gpslng")[0].firstChild.data))); this.popup = new OpenLayers.Popup.FramedCloud( 'popupCV', ll, null, '
' + p_kontakt + p_sluzby + p_fotky + '
', { 'size': new OpenLayers.Size(28, 31), 'offset': new OpenLayers.Pixel(-14, -31) }, true ); this.popup.calculateRelativePosition = function(px) {return 'tr';} this.popup.registerImageListeners = function() {return true;} this.map.map.addPopup(this.popup); } } else alert(this.txtErrorMessage); } } } this.hideDetail = function() { if (this.popup) { this.map.map.removePopup(this.popup); } } this.initInfoBox = function() { function PlaceItemDesc() { this.label = ''; } PlaceItemDesc.prototype.reset = function(pos, label) { this.label = label; this.pos = pos; } PlaceItemDesc.prototype.show = function() { this.div.style.display = "block"; } PlaceItemDesc.prototype.hide = function() { this.div.style.display = "none"; } PlaceItemDesc.prototype.initialize = function(map) { var div = document.createElement("div"); div.style.position = "absolute"; div.style.display = "none"; map.elMap.appendChild(div); this.map = map; this.div = div; } PlaceItemDesc.prototype.remove = function() { this.div.parentNode.removeChild(this.div); } PlaceItemDesc.prototype.copy = function() { return new PlaceItemDesc(); } PlaceItemDesc.prototype.showAt = function(pos, label) { this.reset(pos, label); this.redraw(true); this.show(); } PlaceItemDesc.prototype.redraw = function(force) { if (!force) return; var posxy = this.map.map.getPixelFromLonLat(this.map.fromLatLng(this.pos)); var name = this.label.replace(/&/g, "&").replace(/>/g, ">").replace(/" + name + ""; } this.infoBox = new PlaceItemDesc(); this.infoBox.initialize(this.map); } this.onMapMoveEnd = function() { if (this.isOn) { this.update(); } } this.hide = function() { if (this.isOn) { this.clearLayer(); this.infoBox.hide(); this.hideDetail(); this.isOn = false; } } this.itemDecode = function(str) { return str.replace(/#LT#/g, '<').replace(/#GT#/g, '>'); } this.convertDtoDMS = function(a) { var res = Math.floor(a); res+= "°"; var b = (a - Math.floor(a)) * 60; res+= (Math.floor(b) < 10)?("0" + Math.floor(b)):(Math.floor(b)); res+= "'"; var c = (b - Math.floor(b)) * 60; res+= (Math.floor(c) < 10)?("0" + Math.floor(c)):(Math.floor(c)); res+= '"'; return res; } this.attachEvents = function() { this.map.map.events.register('moveend', this, this.onMapMoveEnd); } this._create(); this.initialize(); }