function CaLrToursInterface(map) { this.map = map; // map interface object this.isOn; this.icon; this.urlIcon = 'http://www.cykloserver.cz/img/cyklo-ico-cil.gif'; this.groupCount; this.groupIndex; this.groupIds; this.groupMarkers; this.infoBox; this.httpRequest; this.pUpdateRequest; this.txtErrorMessage; this.preloadedMode; this.cbSelectItem; this.cbUnselectItem; this.cbClickItem; this._create = function() { this.initInfoBox(); this.attachEvents(); } this.initialize = function() { this.isOn = false; this.preloadedMode = 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: 30, graphicHeight: 24, graphicXOffset: -15, graphicYOffset: -23, cursor: 'pointer' }; this.cbSelectItem = null; this.cbUnselectItem = null; this.cbClickItem = null; this.attachEvents(); } this.flipLayer = function() { if (!this.isOn) { this.show(); } else { this.hide(); } } this.show = function() { if (!this.isOn) { this.isOn = true; if (!this.preloadedMode) { 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/vlrprepare.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]), '', 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) { var url = "http://www.cykloserver.cz/tipy-na-vylety/detail/?d=" + marker.utilItemObjIndex; window.parent.location = url; } 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.showTourPath(marker.utilItemObjIndex); if (this.cbSelectItem) this.cbSelectItem(marker.utilItemObjIndex); } this.unselectItem = function(marker) { //this.infoBox.hide(); this.hidePath(); if (this.cbUnselectItem) { var id = -1; if (this.lastShowId) id = this.lastShowId; this.cbUnselectItem(id); } } this.hidePath = function() { if (this.layerTour) { this.map.map.removeLayer(this.layerTour); this.layerTour.destroy(); this.layerTour = null; } } this.showTourPath = function(id) { this.lastShowId = id; var bnds = this.map.map.getExtent(); var topleft = new OpenLayers.LonLat(bnds.left, bnds.top); var bottomright = new OpenLayers.LonLat(bnds.right, bnds.bottom); var pxtopleft = this.map.map.getPixelFromLonLat(topleft); var pxbottomright = this.map.map.getPixelFromLonLat(bottomright); var urlwidth = Math.abs(pxbottomright.x - pxtopleft.x); var urlheight = Math.abs(pxbottomright.y - pxtopleft.y); var transtopleft = this.map.tranformToOLM(topleft); var transbottomright = this.map.tranformToOLM(bottomright); var url = "http://www.cykloserver.cz/cykloatlas/trasavylet.php?vport=" + urlwidth + ";" + urlheight + "&bbox=" + transtopleft.lon + ";" + transbottomright.lat + ";" + transbottomright.lon + ";" + transtopleft.lat + "&d=" + id; this.hidePath(); this.layerTour = new OpenLayers.Layer.Image( 'layertour', url, this.map.map.getExtent(), new OpenLayers.Size(urlwidth, urlheight), {alwaysInRange: true, 'type':'png', 'isBaseLayer':false, resolutions:OLM.resolutions, zoomOffset:OLM.zoomOffset} ); this.map.map.addLayer(this.layerTour); this.layerTour.div.style.zIndex = '555'; this.layerTour.presetZIndex = '555'; } 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) { if (!this.preloadedMode) { this.update(); } } } this.hide = function() { if (this.isOn) { this.clearLayer(); this.hidePath(); //this.infoBox.hide(); 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(); }