function MinimapInterface(map) { this.map = map; // map interface object this.elNavigator = null; this.elBox = null; this.elArea = null; this.elMinimize = null; this.isMouseDown = false; this.offsetLeft = 0; this.lngmin = 11.95; this.lngmax = 22.82; this.lngsize = this.lngmax - this.lngmin; this.latmin = 47.58; this.latmax = 51.24; this.latsize = this.latmax - this.latmin; this.w = 274; this.h = 143; this.lngwratio = this.lngsize / this.w; this.lathratio = this.latsize / this.h; this.wlngratio = this.w / this.lngsize; this.hlatratio = this.h / this.latsize; this._create = function() { this.elNavigator = document.getElementById('map_navigator'); this.elBox = this.map.map.getViewport(); this.elArea = document.getElementById('area'); this.elMinimize = document.getElementById('map_navigator_minimize'); if (this.elNavigator) this.elNavigator.style.cursor = 'pointer'; if (this.elArea) { this.elArea.style.cursor = 'pointer'; } this.attachEvents(); this.onUpdateMinimap(); if (this.elMinimize) { if (this.isCookie("ca_minimap")) { if (this.getCookie("ca_minimap") == '1') { this.elNavigator.style.display = "block"; this.elMinimize.style.backgroundImage = "url('https://www.cykloserver.cz/img/ca_navigator_minimize.gif')"; isonminimap = true; } else { this.elNavigator.style.display = "none"; this.elMinimize.style.backgroundImage = "url('https://www.cykloserver.cz/img/ca_navigator_maximize.gif')"; isonminimap = false; } } } } this.isCookie = function(key) { if (document.cookie.indexOf(key + '=') == 0) return true; if (document.cookie.indexOf('; ' + key + '=') > 0) return true; return false; } this.setCookie = function(key, value) { value = encodeURIComponent(value); value+= '; path=/'; var date = new Date(); date.setTime(date.getTime() + 90 * 24 * 60 * 60 * 1000); value+='; expires=' + date.toGMTString(); document.cookie = key + '=' + value; } this.getCookie = function(key) { var i = document.cookie.indexOf('; ' + key + '='); if (i == -1) { i = document.cookie.indexOf(key + '='); if (i == -1) { return false; } else { i+= key.length + 1; } } else { i+= key.length + 3; } var ie = document.cookie.indexOf(';', i); if (ie == -1) { return document.cookie.substring(i); } else { return document.cookie.substring(i, ie); } } this.onClickNavigator = function(e) { if (typeof(e) != 'undefined') { var dh = this.elBox; var dv = this.elNavigator; var l = this.elNavigator.offsetLeft; var t = this.elNavigator.offsetTop; var x = e.clientX - l - 5 - this.offsetLeft; var y = e.clientY - t - 5; } else { var e = window.event; if (e.srcElement.id == "area") { var x = parseFloat(this.elArea.style.left) + e.offsetX; var y = parseFloat(this.elArea.style.top) + e.offsetY; } else { var x = e.offsetX; var y = e.offsetY; } } posx = x * this.lngwratio + this.lngmin; posy = (this.h - y) * this.lathratio + this.latmin; this.map.setCenter(new OLM.LatLng(posy, posx)); return false; } this.onUpdateMinimap = function() { var bbox = this.map.getBounds(); var l = (bbox[0] - this.lngmin) * this.wlngratio; var t = -1 * (bbox[3] - this.latmax) * this.hlatratio; var w = (bbox[2] - bbox[0]) * this.wlngratio; var h = (bbox[3] - bbox[1]) * this.hlatratio; if (this.elArea) { this.elArea.style.left = (Math.floor(l)) + "px"; this.elArea.style.top = (Math.floor(t)) + "px"; this.elArea.style.width = Math.floor(w) + "px"; this.elArea.style.height = Math.floor(h) + "px"; } } this.onMouseDownNavigator = function(e) { this.isMouseDown = true; this.onClickNavigator(e); } this.onMouseUpNavigator = function() { this.isMouseDown = false; } this.onMouseOutNavigator = function() { this.isMouseDown = false; } this.onMouseMoveNavigator = function(e) { if (this.isMouseDown) this.onClickNavigator(e); } this.onMouseClickMinimize = function() { if (this.elNavigator) { if (this.elNavigator.style.display != "none") { this.setCookie("ca_minimap", 0); this.elNavigator.style.display = "none"; this.elMinimize.style.backgroundImage = "url('https://www.cykloserver.cz/img/ca_navigator_maximize.gif')"; } else { this.setCookie("ca_minimap", 1); this.elNavigator.style.display = "block"; this.elMinimize.style.backgroundImage = "url('https://www.cykloserver.cz/img/ca_navigator_minimize.gif')"; } } return false; } this.attachEvents = function() { if (this.elNavigator) { $(this.elNavigator).bind('click', jQuery.proxy(this.onClickNavigator, this)); $(this.elNavigator).bind('mousemove', jQuery.proxy(this.onMouseMoveNavigator, this)); $(this.elNavigator).bind('mousedown', jQuery.proxy(this.onMouseDownNavigator, this)); $(this.elNavigator).bind('mouseup', jQuery.proxy(this.onMouseUpNavigator, this)); $(this.elNavigator).bind('mouseout', jQuery.proxy(this.onMouseOutNavigator, this)); } if (this.elMinimize) { $(this.elMinimize).bind('click', jQuery.proxy(this.onMouseClickMinimize, this)); } this.map.map.events.register('move', this, this.onUpdateMinimap); } this._create(); }