// Overwrite marker layer's drawMarker OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': true, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false }, initialize: function (options) { this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions ); OpenLayers.Control.prototype.initialize.apply( this, arguments ); }, CLASS_NAME: "OpenLayers.Control.Click" }); OpenLayers.Layer.Markers = OpenLayers.Class(OpenLayers.Layer.Markers, { drawMarker: function (marker) { var px = this.map.getLayerPxFromLonLat(marker.lonlat); if (px == null) { marker.display(false); } else { var markerImg = marker.draw(px); var iconUrl = markerImg.childNodes[0].src; var iconWidth = parseInt(markerImg.style.width); var iconHeight = parseInt(markerImg.style.height); var iconZIndex = markerImg.childNodes[0].style.zIndex; if (marker.text && marker.text.length != 0) { var textMarker = document.createElement('DIV'); textMarker.innerText = marker.text; textMarker.style.width = iconWidth; textMarker.style.height = iconHeight; textMarker.style.color = marker.color; textMarker.style.paddingTop = marker.paddingTop; textMarker.style.fontFamily = marker.fontFamily; textMarker.style.fontSize = marker.fontSize; textMarker.style.fontStyle = marker.fontStyle; textMarker.style.zIndex = iconZIndex + 1; textMarker.style.left = (iconWidth - marker.text.length * marker.fontSize) / 2 + 2; textMarker.style.position = 'absolute'; textMarker.style.overflow = 'hidden'; textMarker.style.cursor = 'normal'; markerImg.appendChild(textMarker); } if (!marker.drawn) { this.div.appendChild(markerImg); marker.drawn = true; } } } }); OpenLayers.Marker.GeoMarker = OpenLayers.Class(OpenLayers.Marker, { id: null, uniqueId: null, extra: null, text: '', paddingTop: 0, fontSize: 10, color: 'black', fontFamily: 'verdana', fontStyle: 'normal', popup: null, hoverText: null, popupX: null, popupY: null, popupVisible: null, popupWidth: null, popupHeight: null, popupHasCloseButton: null, popupAutoPan: null, popupDelay: null, popupHideTimer: null, /** * Constructor: OpenLayers.Marker * Paraemeters: * icon - {} the icon for this marker * lonlat - {} the position of this marker */ initialize: function (id, lonlat, icon) { this.id = id; this.lonlat = lonlat; var newIcon = (icon) ? icon : OpenLayers.Marker.defaultIcon(); if (this.icon == null) { this.icon = newIcon; } else { this.icon.url = newIcon.url; this.icon.size = newIcon.size; this.icon.offset = newIcon.offset; this.icon.calculateOffset = newIcon.calculateOffset; } this.events = new OpenLayers.Events(this, this.icon.imageDiv, null); }, display: function (display) { this.icon.display(display); }, initializePopup: function (map) { if (this.icon.size == null) { this.popup = new Popup(this.popupJson, null).element; } else { this.popup = new Popup(this.popupJson, this.icon).element; } this.popup.lonlat = this.lonlat; this.popup.isMarkerHoverPopup = true; this.popupVisible = this.popupJson.visibility; map.addPopup(this.popup); if (!this.popupVisible) { this.popup.hide(); } if (!this.popupVisible) { this.popup.events.register('mouseover', this, function (evt) { clearTimeout(this.hideTimer); }); this.popup.events.register('mouseout', this, function (evt) { this.hidePopup(map); }); this.popup.hide(); } }, showPopup: function () { if (!this.popupVisible) this.showTimer = setTimeout(Function.createDelegate(this, function () { if (this.popup && this.popup.div) { if (!this.popup.map) this.popup.map = this.map; this.popup.show(); if (typeof (OnPopupShowing) != 'undefined' && OnPopupShowing != null) { OnPopupShowing.call(this.popup, { isLeft: this.popup.left, isTop: this.popup.top }); } } }), this.popupDelay); }, hidePopup: function () { if (!this.popupVisible) { if (this.showTimer) { window.clearTimeout(this.showTimer); } this.hideTimer = setTimeout(Function.createDelegate(this, function () { if (this.popup && this.popup.div) { if (!this.popup.map) this.popup.map = this.map; this.popup.hide(); } }), 500); } }, movePopup: function (px) { if (this.popup && this.popup.div) { if (!this.popup.map) this.popup.map = this.map; this.popup.lonlat = this.map.getLonLatFromLayerPx(px); this.popup.updatePosition(); } }, CLASS_NAME: "OpenLayers.Marker.GeoMarker" }); OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control.LayerSwitcher, { onLayerChanged: function (newLayer) { }, onInputClick: function (e) { if (!this.inputElem.disabled) { if (this.inputElem.type == "radio") { this.inputElem.checked = true; this.layer.map.setBaseLayer(this.layer); if (this.layerSwitcher.onLayerChanged != "") { this.layerSwitcher.onLayerChanged(this.layer.map.baseLayer.name); } } else { this.inputElem.checked = !this.inputElem.checked; this.layerSwitcher.updateMap(); } } OpenLayers.Event.stop(e); } }); OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control.MousePosition, { showType: 'lonlat', numdigits: 5, formatOutput: function (lonLat) { var digits = parseInt(this.numdigits); var newHtml = ''; if (this.showType == 'dms') { newHtml = this.prefix + this.getDms(lonLat.lon.toFixed(digits)) + ', ' + this.getDms(lonLat.lat.toFixed(digits)) + this.suffix; } else if (this.showType == 'dmslatlon') { newHtml = this.prefix + this.getDms(lonLat.lat.toFixed(digits)) + ', ' + this.getDms(lonLat.lon.toFixed(digits)) + this.suffix; } else if (this.showType == 'lonlat') { newHtml = this.prefix + lonLat.lon.toFixed(digits) + this.separator + lonLat.lat.toFixed(digits) + this.suffix; } else if (this.showType == 'latlon') { newHtml = this.prefix + lonLat.lat.toFixed(digits) + this.separator + lonLat.lon.toFixed(digits) + this.suffix; } return newHtml; }, getDms: function (value) { var absDdValue = Math.abs(value); var degrees; if (value >= 0) { degrees = Math.floor(value); } else { degrees = Math.ceil(value); } var tmpMinute = this.calculateDmsFactor(absDdValue); var tmpSecond = this.calculateDmsFactor(tmpMinute); return degrees + "° " + parseInt(tmpMinute) + "' " + parseInt(tmpSecond) + "''"; }, calculateDmsFactor: function (value) { var decimals = 10000; return Math.round(((value - Math.floor(value)) * 60 * decimals)) / decimals; } }); OpenLayers.Control.Logo = OpenLayers.Class(OpenLayers.Control.Attribution, { innerHTML: null, initialize: function (url) { var arVersion = navigator.appVersion.split("MSIE"); var version = parseFloat(arVersion[1]); if (version == 6) { this.innerHTML = '
' } else { this.innerHTML = ''; } }, updateAttribution: function () { if (this.map && this.innerHTML) { this.div.style.right = "10px"; this.div.style.bottom = "10px"; this.div.innerHTML = this.innerHTML; } }, CLASS_NAME: "OpenLayers.Control.Logo" }); OpenLayers.Map = OpenLayers.Class(OpenLayers.Map, { minZoomLevel: 0, setCenter: function (lonlat, zoom, dragging, forceZoomChange) { if (zoom == null) { zoom = this.getZoom(); } if (this.restrictedExtent) { var restrictedZoom = this.getZoomForExtent(this.restrictedExtent); if (zoom < restrictedZoom) { zoom = restrictedZoom; } } if (zoom < this.minZoomLevel) { zoom = this.minZoomLevel; } this.moveTo(lonlat, zoom, { 'dragging': dragging, 'forceZoomChange': forceZoomChange, 'caller': 'setCenter' }); }, destroyShallow: function () { if (!this.unloadDestroy) { return false; } OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); this.unloadDestroy = null; if (this.updateSizeDestroy) { OpenLayers.Event.stopObserving(window, 'resize', this.updateSizeDestroy); } else { this.events.unregister("resize", this, this.updateSize); } this.paddingForPopups = null; if (this.eventListeners) { this.events.un(this.eventListeners); this.eventListeners = null; } this.events.destroy(); this.events = null; } }); OpenLayers.Layer.Markers.DragableMarkers = OpenLayers.Class(OpenLayers.Layer.Markers, { CLASS_NAME: "OpenLayers.Layer.Markers.DragMarkers", isDragging: false, selectedMarker: null, crossMarker: null, bouncingTimer: null, bouncingMarker: null, initialize: function (name, options) { OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); this.events.addEventType("dragstart"); this.events.addEventType("dragging"); this.events.addEventType("dragend"); }, wireDragEvents: function () { if (this.dragMode == 'none') { return; } var size = new OpenLayers.Size(16, 16); var offset = new OpenLayers.Pixel(-(size.w / 2), -(size.h / 2)); var icon = new OpenLayers.Icon(this.rootPath + 'theme/default/img/cross.gif', size, offset); this.crossMarker = new OpenLayers.Marker(new OpenLayers.LonLat(0, 0), icon); this.crossMarker.isShadow = true; this.addMarkerCore(this.crossMarker); this.crossMarker.display(false); this.events.includeXY = true; this.map.events.register('mousemove', this, function (e) { if (this.isDragging && this.selectedMarker != null) { var newXY = e.xy; var targetXY = this.map.getLayerPxFromViewPortPx(newXY); var markerXY = new OpenLayers.Pixel(targetXY.x, targetXY.y - 15); this.selectedMarker.moveTo(markerXY); this.crossMarker.moveTo(targetXY); this.crossMarker.display(true); if (this.selectedMarker.popup) { this.selectedMarker.hidePopup(); } this.events.triggerEvent("dragging", { evt: e, marker: this.selectedMarker }); } }); this.map.events.register('mouseup', this, function (evt) { this.isDragging = false; if (this.selectedMarker != null) { this.bouncingMarker = this.selectedMarker; var hoverPopup = this.selectedMarker.popup; this.selectedMarker = null; var bouncingHandler = function (e) { var marker = this.marker; var layer = this.layer; var currentXY = layer.map.getLayerPxFromLonLat(marker.lonlat); var targetXY = this.targetXY; var timer = this.timer; if (currentXY.y < targetXY.y) { currentXY.y += 1; marker.moveTo(currentXY); } else { marker.moveTo(targetXY); this.layer.bouncingMarker = null; window.clearInterval(layer.bouncingTimer); layer.bouncingTimer = null; if (this.layer.draggedEvent) { var markerId = marker.id; var lon = marker.lonlat.lon; var lat = marker.lonlat.lat; this.layer.map.isMarkerDragging = false; __doPostBack(this.layer.map.uniqueId, 'MARKERDRAGGED^' + layer.id + '^' + markerId + '^' + lon + '^' + lat); } layer.events.triggerEvent("dragend", { targetXY: targetXY, marker: this.marker }); } } var targetXY = this.map.getLayerPxFromLonLat(this.crossMarker.lonlat); this.bouncingMarker.movePopup(targetXY); this.bouncingTimer = window.setInterval(OpenLayers.Function.bind(bouncingHandler, { marker: this.bouncingMarker, layer: this, targetXY: targetXY }), 5); this.crossMarker.display(false); } }); }, addMarker: function (marker) { this.addMarkerCore(marker); if (this.dragMode == 'drag') { marker.events.register('mousedown', { layer: this, selectedMarker: marker }, function (e) { this.layer.map.isMarkerDragging = true; this.layer.removeBouncingAnimation(this.layer); this.layer.isDragging = true; this.layer.selectedMarker = this.selectedMarker; this.layer.selectedMarker.map = this.layer.map; this.layer.crossMarker.map = this.layer.map; this.layer.crossMarker.moveTo(this.layer.getViewPortPxFromLonLat(this.selectedMarker.lonlat)); this.layer.events.triggerEvent("dragstart", { evt: e, marker: this.layer.selectedMarker }); OpenLayers.Event.stop(e); }); } }, addMarkerCore: function (marker) { OpenLayers.Layer.Markers.prototype.addMarker.apply(this, arguments); }, removeBouncingAnimation: function (layer) { if (layer.bouncingTimer) { window.clearTimeout(layer.bouncingTimer); } if (layer.bouncingMarker) { layer.bouncingMarker = null; } } }); // extent tile request OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.Image, { renderTile: function () { if (this.imgDiv == null) { this.initImgDiv(); } this.imgDiv.viewRequestID = this.layer.map.viewRequestID; if (this.layer.url instanceof Array) { this.imgDiv.urls = this.layer.url.slice(); } this.url = this.layer.getURL(this.bounds); if (this.url) { this.url += '&ZOOM=' + this.layer.map.getZoom(); } OpenLayers.Util.modifyDOMElement(this.frame, null, this.position, this.size); var imageSize = this.layer.getImageSize(); if (this.layerAlphaHack) { OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, null, null, imageSize, this.url); } else { OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, imageSize); this.imgDiv.src = this.url; } return true; } }); OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.RegularPolygon, { isMoved: false, down: function (evt) { this.moved = false; this.fixedRadius = !!(this.radius); var maploc = this.map.getLonLatFromPixel(evt.xy); this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); if (!this.fixedRadius || this.irregular) { this.radius = this.map.getResolution(); } if (this.persist) { this.clear(); } this.feature = new OpenLayers.Feature.Vector(); this.createGeometry(); this.layer.addFeatures([this.feature], { silent: true }); this.layer.drawFeature(this.feature, this.style); }, move: function (evt) { this.moved = true; var maploc = this.map.getLonLatFromPixel(evt.xy); var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); if (this.irregular) { var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2; this.radius = Math.max(this.map.getResolution() / 2, ry); } else if (this.fixedRadius) { this.origin = point; } else { this.calculateAngle(point, evt); this.radius = Math.max(this.map.getResolution() / 2, point.distanceTo(this.origin)); } this.modifyGeometry(); if (this.irregular) { var dx = point.x - this.origin.x; var dy = point.y - this.origin.y; var ratio; if (dy == 0) { ratio = dx / (this.radius * Math.sqrt(2)); } else { ratio = dx / dy; } this.feature.geometry.resize(1, this.origin, ratio); this.feature.geometry.move(dx / 2, dy / 2); } this.layer.drawFeature(this.feature, this.style); }, up: function (evt) { // remove feature is the mouse doesn't move at all. if (!this.moved) { this.layer.eraseFeatures([this.feature]); } this.finalize(); } }); OpenLayers.Popup.prototype.offsetX = 0; OpenLayers.Popup.prototype.offsetY = 0; OpenLayers.Popup.prototype.moveTo = function (px) { if ((px != null) && (this.div != null)) { this.div.style.left = (px.x + this.offsetX) + "px"; this.div.style.top = (px.y + this.offsetY) + "px"; } }; OpenLayers.Popup.Anchored = OpenLayers.Class(OpenLayers.Popup.Anchored, { top: null, left: null, calculateNewPx: function (px) { var newPx = px.offset(this.anchor.offset); var size = this.size || this.contentSize; var top = (this.relativePosition.charAt(0) == 't'); newPx.y += (top) ? -size.h : this.anchor.size.h; var left = (this.relativePosition.charAt(1) == 'l'); newPx.x += (left) ? -size.w : this.anchor.size.w; this.top = top; this.left = left; return newPx; } }); OpenLayers.Layer.VirtualEarth = OpenLayers.Class(OpenLayers.Layer.VirtualEarth, { onMapResize: function () { if (this.map.baseLayer != null) { var newSize = this.map.getCurrentSize(); this.mapObject.Resize(newSize.w, newSize.h); } }, getMapObjectLonLatFromMapObjectPixel: function (moPixel) { var latlon; if (typeof VEPixel != 'underfined') { latlon = this.mapObject.PixelToLatLong(moPixel); } else { latlon = this.mapObject.PixelToLatLong(moPixel.x, moPixel.y); } return (new _xy1).Decode(latlon); } }); OpenLayers.Icon = OpenLayers.Class(OpenLayers.Icon, { initialize: function (url, size, offset, calculateOffset) { this.url = url; this.size = (size) ? size : new OpenLayers.Size(20, 20); this.offset = offset ? offset : new OpenLayers.Pixel(-(this.size.w / 2), -(this.size.h / 2)); this.calculateOffset = calculateOffset; var id = OpenLayers.Util.createUniqueID("OL_Icon_"); // Change Default Size of Icon this.size = size; this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); } }); OpenLayers.Control.AnimationPan = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'delay': 200 }, initialize: function () { this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions); OpenLayers.Control.prototype.initialize.apply(this, arguments); this.handler = new OpenLayers.Handler.Click(this, { 'click': this.onClick }, this.handlerOptions); }, onClientClick: function (context) { }, onClick: function (evt) { if (this.onClientClick != "") { var context = { 'animationPan': this, 'evt': evt }; this.onClientClick(context); } else { this.map.panTo(this.map.getLonLatFromPixel(evt.xy)); } } }); OpenLayers.Layer.AdornmentLayer = OpenLayers.Class(OpenLayers.Layer.WMS, { moveTo: function (bounds, zoomChanged, dragging) { if (!this.grid.length) { OpenLayers.Layer.WMS.prototype.moveTo.apply(this, arguments); OpenLayers.Util.modifyDOMElement(this.grid[0][0].frame, null, new OpenLayers.Pixel(0, 0), null, "fixed", null, null, null); } else { var tile = this.grid[0][0]; var src = this.getURL(bounds); tile.imgDiv.src = src + "&extra=" + Math.random(); } } });