function ToursInterface(map) { this.map = map; // map interface object this.elEdit = null; this.tour = null; this.reqLoadTourCompleteP = null; this.reqLoadTourErrorP = null; this.reqLoadTourSuccessP = null; this.line = null; this.infoBox = null; this.markerStart = null; this.markerFinish = null; this.markerPoints = null; this.markerPois = null; this.urlStartIcon = 'https://mapy.idnes.cz/img/cyklo-ico-start.gif'; this.urlStartIconSel = 'https://mapy.idnes.cz/img/cyklo-ico-start-a.gif'; this.urlFinishIcon = 'https://mapy.idnes.cz/img/cyklo-ico-cil.gif'; this.urlFinishIconSel = 'https://mapy.idnes.cz/img/cyklo-ico-cil-a.gif'; this.urlPointIcon = 'https://mapy.idnes.cz/img/cyklo-ico-bod.gif'; this.urlPointIconSel = 'https://mapy.idnes.cz/img/cyklo-ico-bod-a.gif'; this.urlPoiIcon = 'https://mapy.idnes.cz/img/cyklo-ico-poi.gif'; this.urlPoiIconSel = 'https://mapy.idnes.cz/img/cyklo-ico-poi-a.gif'; this.lineStartIcon = null; this.lineFinishIcon = null; this.linePointIcon = null; this.poiIcon = null; this.nextTourOverrideValues = {}; this.showPath = 1; this._create = function() { this.elEdit = document.getElementById('btn-editovat'); this.reqLoadTourCompleteP = jQuery.proxy(this.reqLoadTourComplete, this); this.reqLoadTourErrorP = jQuery.proxy(this.reqLoadTourError, this); this.reqLoadTourSuccessP = jQuery.proxy(this.reqLoadTourSuccess, this); this.lineStartIcon = { externalGraphic: this.urlStartIcon, externalGraphicSel: this.urlStartIconSel, graphicWidth: 30, graphicHeight: 24, graphicXOffset: -14, graphicYOffset: -24, cursor: 'pointer' }; this.lineFinishIcon = { externalGraphic: this.urlFinishIcon, externalGraphicSel: this.urlFinishIconSel, graphicWidth: 30, graphicHeight: 24, graphicXOffset: -14, graphicYOffset: -24, cursor: 'pointer' }; this.linePointIcon = { externalGraphic: this.urlPointIcon, externalGraphicSel: this.urlPointIconSel, graphicWidth: 10, graphicHeight: 14, graphicXOffset: -5, graphicYOffset: -14, cursor: 'pointer' }; this.poiIcon = { externalGraphic: this.urlPoiIcon, externalGraphicSel: this.urlPoiIconSel, graphicWidth: 30, graphicHeight: 24, graphicXOffset: -14, graphicYOffset: -24, cursor: 'pointer' }; this.initInfoBox(); this.attachEvents(); } this.reqLoadTourComplete = function() { } this.reqLoadTourError = function() { alert('Výlet nebylo možné načíst.'); } this.reqLoadTourSuccess = function(data) { if (data['error']) { alert('Výlet nebylo možné načíst [' + data['error'] + '].'); } else { this.tour = { id: data['id'], bbox: data['bbox'], line: data['line'], pois: data['pois'], color: data['color'], opacity: data['opacity'], width: data['width'] }; } this.createTour(); } this.createTour = function() { this.map.showExtent(this.tour.bbox['lngmin'], this.tour.bbox['latmin'], this.tour.bbox['lngmax'], this.tour.bbox['latmax']); if (this.nextTourOverrideValues.zoom) this.map.setZoom(this.nextTourOverrideValues.zoom); if ((this.nextTourOverrideValues.lat) && (this.nextTourOverrideValues.lon)) this.map.panTo(new OLM.LatLng(this.nextTourOverrideValues.lat, this.nextTourOverrideValues.lon)); this.line = new Array(); this.markerPoints = new Array(); if (this.showPath) for (var ti = 0; ti < this.tour.line.length; ti++) { var pos = new OLM.LatLng(this.tour.line[ti].lat, this.tour.line[ti].lng); this.line.push(pos); if (this.tour.line[ti].cmt) { var marker = OLM.Markers.createMarker(pos, this.map, this.linePointIcon); this.appendInfoToMarker(marker, this.tour.line[ti].cmt, ''); this.markerPoints.push(marker); this.map.addMarker(marker); } } this.markerPois = new Array(); if (this.tour.pois.length) for (var ti = 0; ti < this.tour.pois.length; ti++) { var pos = new OLM.LatLng(parseFloat(this.tour.pois[ti].lat), parseFloat(this.tour.pois[ti].lng)); var marker = OLM.Markers.createMarker(pos, this.map, this.poiIcon); this.appendInfoToMarker(marker, this.tour.pois[ti].nam, this.tour.pois[ti].des); this.markerPois.push(marker); this.map.addMarker(marker); } if (this.showPath) { var label = ''; if (this.tour.line[0].cmt) label = this.tour.line[0].cmt; this.markerStart = OLM.Markers.createMarker(this.line[0], this.map, this.lineStartIcon); this.appendInfoToMarker(this.markerStart, 'Výchozí bod', label); this.map.addMarker(this.markerStart); label = ''; if (this.tour.line[this.tour.line.length - 1].cmt) label = this.tour.line[this.tour.line.length - 1].cmt; this.markerFinish = OLM.Markers.createMarker(this.line[this.line.length - 1], this.map, this.lineFinishIcon); this.appendInfoToMarker(this.markerFinish, 'Cíl trasy', label); this.map.addMarker(this.markerFinish); var lineW = this.tour.width; if (this.nextTourOverrideValues.width) lineW = this.nextTourOverrideValues.width; var lineO = this.tour.opacity; if (this.nextTourOverrideValues.opacity) lineO = this.nextTourOverrideValues.opacity; this.map.activateSimplePath( this.line, { color: this.tour.color, width: lineW, opacity: lineO } ); } this.nextTourOverrideValues = {}; } this.closeTour = function() { if (this.line) { this.map.deactivateSimplePath(); this.line = null; } if (this.markerStart) { this.map.removeMarker(this.markerStart); this.markerStart = null; } if (this.markerFinish) { this.map.removeMarker(this.markerFinish); this.markerFinish = null; } if (this.markerPoints) { while (this.markerPoints.length) { this.map.removeMarker(this.markerPoints.pop()); } this.markerPoints = null; } if (this.markerPois) { while (this.markerPois.length) { this.map.removeMarker(this.markerPois.pop()); } this.markerPois = null; } if (this.tour) { this.tour = null; } } this.loadTour = function(id) { this.closeTour(); var url = 'https://mapy.idnes.cz/gettour.php?id=' + id; jQuery.ajax(url, {cache:false, complete:this.reqLoadTourCompleteP, dataType:'JSON', error:this.reqLoadTourErrorP, success:this.reqLoadTourSuccessP, type:'GET'}); } this.appendInfoToMarker = function(marker, name, desc) { marker.cTours = this; marker.textName = name; marker.textDesc = desc; marker.onMouseOver = function(ev) { var p = ev.geometry.clone(); var latLng = this.cTours.map.getLatLngFromLonLat(new OpenLayers.LonLat(p.x, p.y)); this.cTours.infoBox.showAt(latLng, this.textName, this.textDesc); } marker.onMouseOut = function(ev) { this.cTours.infoBox.hide(); } } this.initInfoBox = function() { function PlaceItemDesc() { this.label = ''; this.desc = ''; this.t_ico = 'normal'; } PlaceItemDesc.prototype.reset = function(pos, label, desc) { this.label = label; this.desc = desc; 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, desc) { this.reset(pos, label, desc); 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(//g, ">").replace(/ 300) { if (this.t_ico == 'normal') { pos+= 'right: 20px; '; } else { pos+= 'right: 15px; '; } } else { if (this.t_ico == 'normal') { pos+= 'left: 20px; '; } else { pos+= 'left: 15px; '; } } if (posxy.y > 250) { if (this.t_ico == 'normal') { pos+= 'bottom: 1px; '; } else { pos+= 'bottom: 1px; '; } } else { if (this.t_ico == 'normal') { pos+= 'top: -25px; '; } else { pos+= 'top: -22px; '; } } if (description.length) { this.div.innerHTML = "
Název: " + name + "
Popis:
" + description + "
"; } else { this.div.innerHTML = "
Název: " + name + "
"; } } this.infoBox = new PlaceItemDesc(); this.infoBox.initialize(this.map); } this.nextTourOverride = function(name, value) { this.nextTourOverrideValues[name] = value; } this.onClickEdit = function() { if (this.tour) { window.open('https://www.cykloserver.cz/cykloatlas/?d=' + this.tour.id, '_self'); } } this.attachEvents = function() { if (this.elEdit) { $(this.elEdit).bind('click', jQuery.proxy(this.onClickEdit, this)); } } this.setShowPath = function(sp) { this.showPath = sp; } this._create(); }