function CaLrTurInterface(map) { this.map = map; // map interface object this.isOn; this.icon; this.urlIcon = 'http://www.cykloserver.cz/img/ca_tur.gif'; this.urlIconSel = 'http://www.cykloserver.cz/img/ca_tur_sel.gif'; this.groupCount; this.groupIndex; this.groupIds; this.groupMarkers; this.infoBox; this.httpRequest; this.pUpdateRequest; 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.icon = { externalGraphic: this.urlIcon, graphicWidth: 20, graphicHeight: 26, graphicXOffset: -2, graphicYOffset: -25, 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() { 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/turolrprepare.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, externalGraphicHl: this.urlIconSel, externalGraphicOrig: 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.highlight = function() { this.style.externalGraphic = this.attributes.style.externalGraphicHl; this.redraw(); } marker.unhighlight = function() { this.style.externalGraphic = this.attributes.style.externalGraphicOrig; this.redraw(); } marker.clickMarker = function() { this.cCaInt.clickItem(this.utilItemObjIndex); } marker.onMouseOver = function(ev) { this.cCaInt.selectItem(this); this.highlight(); } marker.onMouseOut = function(ev) { this.cCaInt.unselectItem(this); this.unhighlight(); } marker.onMouseClick = function(ev) { this.clickMarker(); } return marker; } this.clickItem = function(id) { var url = "http://www.cykloserver.cz/cykloatlas/redturo.php?id=" + id; window.open(url, "_blank"); } this.selectItem = function(marker) { var img = 'http://www.cykloserver.cz/cykloatlas/imgturo.php?id=' + marker.utilItemObjIndex; var p = marker.geometry.clone(); var latLng = this.map.getLatLngFromLonLat(new OpenLayers.LonLat(p.x, p.y)); this.infoBox.showAt(latLng, marker.title, img); } this.unselectItem = function(marker) { this.infoBox.hide(); } this.initInfoBox = function() { function PlaceItemDesc() { this.label = ''; this.img = ''; } PlaceItemDesc.prototype.reset = function(pos, label, img) { this.label = label; this.img = img; 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, img) { this.reset(pos, label, img); 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.isOn = false; } } this.attachEvents = function() { this.map.map.events.register('moveend', this, this.onMapMoveEnd); } this._create(); this.initialize(); }