// 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.prototype.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.Layer.Markers.prototype.redraw = function () { var redrawn = false; if (this.map) { this.inRange = this.calculateInRange(); var extent = this.getExtent(); if (extent && this.inRange && this.visibility) { var zoomChanged = true; this.moveTo(extent, zoomChanged, false); this.events.triggerEvent("moveend", { "zoomChanged": zoomChanged }); redrawn = true; } } if (this.map.getExtent()) { eval('var parser = parser' + this.map.clientId); var url = parser.getMarkerRequestUrl(this.id, this.gridSize); if (url) { CurrentMapClientId = this.map.clientId; var httpRequest = new OpenLayers.Request.GET({ url: url, callback: function (transport) { if (transport.status == 200) { var map = eval('parser' + CurrentMapClientId + '.map'); AddMarkersByAjax(map, transport.responseText); } } }); } } return redrawn; } OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control.LayerSwitcher, { onLayerChanged: function (newLayer) { }, onButtonClick: function (evt) { var button = evt.buttonElement; if (button === this.minimizeDiv) { this.minimizeControl(); } else if (button === this.maximizeDiv) { this.maximizeControl(); } else if (button._layerSwitcher === this.id) { if (button["for"]) { button = document.getElementById(button["for"]); } if (!button.disabled) { if (button.type == "radio") { button.checked = true; this.map.setBaseLayer(this.map.getLayer(button._layer)); if (this.layerSwitcher.onLayerChanged != "") { this.layerSwitcher.onLayerChanged(this.layer.map.baseLayer.name); } } else { button.checked = !button.checked; this.updateMap(); } } } } }); 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, showTimer: 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; if (icon && icon.url.indexOf('?') == 0) { icon.url = OpenLayers.ScriptResources.markerImage + icon.url; } 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 = setInterval(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) { clearInterval(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.prototype.onLayerChanged = function (newLayer) { }, OpenLayers.Control.MousePosition.prototype.showType = 'lonlat'; OpenLayers.Control.MousePosition.prototype.numdigits = 5; OpenLayers.Control.MousePosition.prototype.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; } OpenLayers.Control.MousePosition.prototype.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) + "''"; } OpenLayers.Control.MousePosition.prototype.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.minZoomLevel = 0; OpenLayers.Map.prototype.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' }); }; OpenLayers.Map.prototype.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; var moveEvent = 'mousemove'; var upEvent = 'mouseup'; if (isIos()) { moveEvent = 'touchmove'; upEvent = 'touchend'; }; this.map.events.register(moveEvent, 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(upEvent, 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 () { var marker = this.marker; if (marker.map.isPostingBack) { return; } 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; evt.cancelBubble = false; marker.map.isPostingBack = true; __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); if (this.bouncingMarker.movePopup) 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') { var etype = 'mousedown'; if (isIos()) etype = 'touchstart'; marker.events.register(etype, { 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.lonlat = marker.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; } } }); OpenLayers.Tile.Image.prototype.renderTile = function () { if (this.layer.url == null || this.layer.url == '') { return true; } if (this.layer.async) { // Asynchronous image requests call the asynchronous getURL method // on the layer to fetch an image that covers 'this.bounds'. var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1; this.layer.getURLasync(this.bounds, function (url) { if (id == this.asyncRequestId) { this.url = url; this.initImage(); } }, this); } else { // synchronous image requests get the url immediately. this.url = this.layer.getURL(this.bounds); if (this.url && !OpenLayers.String.contains(this.url, 'blank.gif') && !OpenLayers.String.contains(this.layer.CLASS_NAME, 'OSM') && !OpenLayers.String.contains(this.layer.CLASS_NAME, 'WMTS') && !OpenLayers.String.contains(this.layer.CLASS_NAME, 'XYZ')) { this.url += '&ZOOM=' + this.layer.map.getZoom(); } this.initImage(); } } OpenLayers.Layer.WMS.prototype.getFullRequestString = function (newParams, altUrl) { var mapProjection = this.map.getProjectionObject(); var projectionCode = this.projection && this.projection.equals(mapProjection) ? this.projection.getCode() : mapProjection.getCode(); var value = (projectionCode == "none") ? null : projectionCode; if (parseFloat(this.params.VERSION) >= 1.3) { this.params.CRS = value; } else { this.params.SRS = value; } if (typeof this.params.TRANSPARENT == "boolean") { newParams.TRANSPARENT = this.params.TRANSPARENT ? "TRUE" : "FALSE"; } var allParams = OpenLayers.Util.extend({}, this.params); allParams = OpenLayers.Util.extend(allParams, newParams); var orderedArray = new Array(allParams.length); var index = 0; for (var key in allParams) { orderedArray[index] = { name: key, value: allParams[key] }; index++; } orderedArray.sort(by('name')); var orderedParams = orderedParams || {}; for (var i in orderedArray) { orderedParams[orderedArray[i]['name']] = orderedArray[i]['value']; } var url = altUrl || this.url; var paramsString = OpenLayers.Util.getParameterString(orderedParams); if (OpenLayers.Util.isArray(url)) { url = this.selectUrl(paramsString, url); } requestrequestString = OpenLayers.Util.urlAppend(url, paramsString); return requestrequestString; } var by = function (name) { return function (o, p) { var a, b; if (typeof o === "object" && typeof p === "object" && o && p) { var index = 0; a = o[name].toLocaleLowerCase()[index]; b = p[name].toLocaleLowerCase()[index]; while (a === b) { index++; a = o[name][index]; b = p[name][index]; if (a !== b) { break; } } if (typeof a === typeof b) { return a < b ? -1 : 1; } return typeof a < typeof b ? -1 : 1; } else { throw ("error"); } } } OpenLayers.Handler.RegularPolygon.prototype.isMoved = false; OpenLayers.Handler.RegularPolygon.prototype.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); } OpenLayers.Handler.RegularPolygon.prototype.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); } OpenLayers.Handler.RegularPolygon.prototype.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.prototype.top = null; OpenLayers.Popup.Anchored.prototype.left = null; OpenLayers.Popup.Anchored.prototype.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.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) { OpenLayers.Layer.WMS.prototype.moveTo.apply(this, arguments); 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, "relative", null, null, null); } else { var tile = this.grid[0][0]; var src = this.getURL(bounds); tile.imgDiv.src = src + "&extra=" + Math.random(); } } }); OpenLayers.Layer.OSM.prototype.url = '${u}${z}/${x}/${y}.png'; OpenLayers.Layer.OSM.prototype.type = 'base'; OpenLayers.Layer.OSM.prototype.getTemplate = function (x, y, z) { var c = Math.pow(2, z); var servers; switch (this.type.toUpperCase()) { case "BASE": return 'http://tile.openstreetmap.org/'; case "CYCLE": var i = (c * y + x) % 3; servers = new Array('a', 'b', 'c'); return OpenLayers.String.format('http://${i}.tile.opencyclemap.org/cycle/', { 'i': servers[i] }); case "TRANS": var i = (c * y + x) % 3; servers = new Array('a', 'b', 'c'); return OpenLayers.String.format('http://${i}.tile2.opencyclemap.org/transport/', { 'i': servers[i] }); case "MAPQUEST": var i = (c * y + x) % 4; servers = new Array('1', '2', '3', '4'); return OpenLayers.String.format('http://otile${i}.mqcdn.com/tiles/1.0.0/osm/', { 'i': servers[i] }); default: return 'http://tile.openstreetmap.org/'; } } OpenLayers.Layer.OSM.prototype.getURL = function (bounds) { var url = OpenLayers.Layer.XYZ.prototype.getURL.call(this, bounds); var res = this.map.getResolution(); var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); var z = this.map.getZoom() + this.zoomOffset; if (!this.uris || this.uris.length == 0) { url = OpenLayers.String.format(this.url, { 'u': this.getTemplate(x, y, z), 'x': x, 'y': y, 'z': z }); } else if (this.uris.length >= 1) { var c = Math.pow(2, z); var i = (c * y + x) % this.uris.length; url = OpenLayers.String.format(this.url, { 'u': this.uris[i], 'x': x, 'y': y, 'z': z }); } return url; } OpenLayers.Layer.OSM.prototype.wrapDateLine = false; OpenLayers.Layer.Google.v3.setGMapVisibility = function (visible) { var cache = OpenLayers.Layer.Google.cache[this.map.id]; if (cache) { var type = this.type; var layers = this.map.layers; var layer; for (var i = layers.length - 1; i >= 0; --i) { layer = layers[i]; if (layer instanceof OpenLayers.Layer.Google && layer.visibility === true && layer.inRange === true) { type = layer.type; visible = true; break; } } var container = this.mapObject.getDiv(); if (visible === true) { this.mapObject.setMapTypeId(type); container.style.left = ""; if (cache.termsOfUse && cache.termsOfUse.style) { cache.termsOfUse.style.left = ""; cache.termsOfUse.style.display = "none"; cache.poweredBy.style.display = "none"; } cache.displayed = this.id; } else { delete cache.displayed; container.style.left = "-9999px"; if (cache.termsOfUse && cache.termsOfUse.style) { cache.termsOfUse.style.display = "none"; cache.termsOfUse.style.left = "-9999px"; cache.poweredBy.style.display = "none"; } } } } OpenLayers.Layer.Google.prototype.traffic = null; OpenLayers.Layer.Google.prototype.enableTraffic = false; OpenLayers.Layer.Google.prototype.showTraffic = function () { if (this.traffic == null) { if (this.mapObject) { if (this.version == 2) { var trafficOptions = { incidents: true }; this.traffic = new GTrafficOverlay(trafficOptions); this.mapObject.addOverlay(this.traffic); } else { this.traffic = new google.maps.TrafficLayer(); } } } if (this.version == 2) { this.traffic.show(); } else { this.traffic.setMap(this.mapObject); } } OpenLayers.Layer.Google.prototype.hideTraffic = function () { if (this.traffic != null) { if (this.version == 2) { this.traffic.hide(); } else { this.traffic.setMap(null); } } } OpenLayers.Control.GStreetView = OpenLayers.Class(OpenLayers.Control, { width: 600, height: 200, px: 0, py: 0, container: null, errorDiv: null, pegmanIcon: null, dragOverlay: null, pegman: null, rootPath: '', streetViewPanorama: null, streetViewLayer: null, svOverlay: null, internalProj: null, gProj: null, isInit: true, initialize: function (options) { options = options || {}; OpenLayers.Control.prototype.initialize.apply(this, [options]); this.width = options.w; this.height = options.h; this.px = options.point.x; this.py = options.point.y; this.rootPath = this.rootPath; var size = new OpenLayers.Size(23, 38); var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h); this.pegmanIcon = new OpenLayers.Icon(OpenLayers.Util.getImagesLocation() + 'streetView.gif', size, offset); this.internalProj = new OpenLayers.Projection("EPSG:4326"); this.streetViewLayer = new google.maps.StreetViewCoverageLayer(); }, destroy: function () { this.deactivate(); if (this.container && this.div.contains(this.container)) this.div.removeChild(this.container); if (this.errorDiv && this.div.contains(this.errorDiv)) this.div.removeChild(this.errorDiv); if (this.dragOverlay) this.map.removeLayer(this.dragOverlay); OpenLayers.Control.prototype.destroy.apply(this, arguments); }, update: function (point) { var theloc = new google.maps.LatLng(point.lat, point.lon); this.streetViewPanorama.setPosition(theloc); this.pegman.lonlat = point; if (!this.pegman.onScreen()) { this.dragOverlay.map.panTo(this.pegman.lonlat.transform(this.internalProj, this.gProj)); } this.dragOverlay.redraw(true); }, hide: function () { this.div.style.display = 'none'; this.dragOverlay.setVisibility(false); this.streetViewLayer.setMap(null); }, show: function () { this.div.style.display = 'block'; this.dragOverlay.setVisibility(true); if (this.map.baseLayer.mapObject) { this.streetViewLayer.setMap(this.map.baseLayer.mapObject); } }, draw: function () { this.gProj = this.map.getProjectionObject(); OpenLayers.Control.prototype.draw.apply(this, arguments); if (this.map.baseLayer.mapObject) { this.streetViewLayer.setMap(this.map.baseLayer.mapObject); } // create street view map DOM elements this.container = document.createElement('div'); this.container.className = this.displayClass + 'Element'; this.container.style.display = 'block'; this.mapDiv = document.createElement('div'); this.mapDiv.style.width = this.width + 'px'; this.mapDiv.style.height = this.height + 'px'; this.mapDiv.style.position = 'relative'; this.mapDiv.style.overflow = 'hidden'; this.mapDiv.id = OpenLayers.Util.createUniqueID('streetView'); this.container.appendChild(this.mapDiv); this.div.appendChild(this.container); this.div.className += " " + this.displayClass + 'Container'; this.dragOverlay = new OpenLayers.Layer.Markers.DragableMarkers('svMarkers', { isBaseLayer: false, displayInLayerSwitcher: false, dragMode: 'drag', projection: 'EPSG:900913', rootPath: this.rootPath }); this.map.addLayer(this.dragOverlay); this.dragOverlay.wireDragEvents(); var position = new OpenLayers.LonLat(this.px, this.py).transform(this.internalProj, this.gProj); this.pegman = new OpenLayers.Marker(position, this.pegmanIcon); this.dragOverlay.addMarker(this.pegman); this.drawSv(new OpenLayers.LonLat(this.px, this.py)); this.dragOverlay.events.register("dragend", this, function (e) { var point = new OpenLayers.Geometry.Point(e.marker.lonlat.lon, e.marker.lonlat.lat); var loc = OpenLayers.Projection.transform(point, this.gProj, this.internalProj); this.container.style.display = 'block'; var theloc = new google.maps.LatLng(loc.y, loc.x); this.streetViewPanorama.setPosition(theloc); }); this.stopEvents = new OpenLayers.Events(this, this.div, null, true, { includeXY: false }); this.stopEvents.on({ "touchstart": function (evt) { OpenLayers.Event.stop(evt); }, "touchmove": function (evt) { OpenLayers.Event.stop(evt); }, "touchend": function (evt) { OpenLayers.Event.stop(evt); }, "mousedown": function (evt) { OpenLayers.Event.stop(evt); }, "mousemove": function (evt) { OpenLayers.Event.stop(evt); }, "mouseup": function (evt) { OpenLayers.Event.stop(evt); } }); return this.div; }, drawSv: function (loc) { var gloc = new google.maps.LatLng(loc.lat, loc.lon); var svControl = this; this.streetViewPanorama = new google.maps.StreetViewPanorama(this.container); google.maps.event.addListener(this.streetViewPanorama, 'position_changed', function (e) { var position = { x: this.getPosition().lng(), y: this.getPosition().lat() }; svControl.updatePegman(position); }); this.streetViewPanorama.setPosition(gloc); this.streetViewPanorama.svControl = this; }, updatePegman: function (latlong) { var dragMarkers = this.map.getLayersByName('svMarkers'); if (dragMarkers.length > 0 && dragMarkers[0].markers.length > 0) { this.pegman.lonlat = new OpenLayers.LonLat(latlong.x, latlong.y).transform(this.internalProj, this.gProj); if (!this.pegman.onScreen() && this.map.getExtent()) { this.map.panTo(this.pegman.lonlat); } dragMarkers[0].redraw(true); } }, CLASS_NAME: "OpenLayers.Control.GStreetView" }); OpenLayers.ScriptResources = { print: 'print_GeoResource.axd', popup: 'popup_GeoResource.axd', session: 'session_GeoResource.axd', tile: 'tile_GeoResource.axd', singleTile: 'singletile_GeoResource.axd', adornment: 'adornment_GeoResource.axd', logo: 'logo_GeoResource.axd', markerLayer: 'markers_GeoResource.axd', markerImage: 'icon_GeoResource.axd' }; OpenLayers.Layer.WMTS.prototype.getURL = function (bounds) { bounds = this.adjustBounds(bounds); var url = ""; if (!this.tileFullExtent || this.tileFullExtent.intersectsBounds(bounds)) { var center = bounds.getCenterLonLat(); var info = this.getTileInfo(center); var matrixId = this.matrix.identifier; if (this.requestEncoding.toUpperCase() === "RESTFUL") { if (typeof this.url === "string" && this.url.indexOf("{") !== -1) { var template = this.url.replace(/\{/g, "${"); var context = { // spec does not make clear if capital S or not style: this.style, Style: this.style, TileMatrixSet: this.matrixSet, TileMatrix: this.matrix.identifier, TileRow: info.row, TileCol: info.col }; if (dimensions) { var dimension, i; for (i = dimensions.length - 1; i >= 0; --i) { dimension = dimensions[i]; context[dimension] = params[dimension.toUpperCase()]; } } url = OpenLayers.String.format(template, context); } else { // include 'version', 'layer' and 'style' in tile resource url var path = this.version + "/" + this.layer + "/" + this.style + "/"; // append other required path elements path = path + this.matrixSet + "/" + this.matrix.identifier + "/" + info.row + "/" + info.col + "." + this.formatSuffix; if ((Object.prototype.toString.call(this.url) === '[object Array]')) { // url = this.selectUrl(path, this.url); var product = 1; for (var i = 0, len = path.length; i < len; i++) { product *= path.charCodeAt(i) * this.URL_HASH_FACTOR; product -= Math.floor(product); } url = this.url[Math.floor(product * url.length)]; } else { url = this.url; } // if (!url.match(/\/$/)) { // url = url + "/"; // } url = url + path; } } else if (this.requestEncoding.toUpperCase() === "KVP") { var params = { SERVICE: "WMTS", REQUEST: "GetTile", VERSION: this.version, LAYER: this.layer, STYLE: this.style, TILEMATRIXSET: this.matrixSet, TILEMATRIX: this.matrix.identifier, TILEROW: info.row, TILECOL: info.col, FORMAT: this.format }; url = OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(this, [params]); } } return url; }; //fix adornment control move follow map. OpenLayers.Layer.FixedAdornmentLayer = OpenLayers.Class(OpenLayers.Layer, { content: null, params: null, pageName: null, clientId: null, initialize: function (name, url, mapClientId, params, options) { if (url !== undefined && url !== null) { this.content = url; } this.pageName = params.pageName; this.clientId = mapClientId; var newArguments = [name, options]; OpenLayers.Layer.prototype.initialize.apply(this, newArguments); }, moveTo: function (bounds, zoomChanged, dragging) { OpenLayers.Layer.prototype.moveTo.apply(this, arguments); var addr = this.content + '?PageName=' + this.pageName + '&ClientId=' + this.clientId + '&BBOX=' + bounds.toArray() + '&WIDTH=' + this.map.size.w + '&HEIGHT=' + this.map.size.h + '&'; this.attribution = ''; //find out the attribution control and update it. var attribution = this.map.getControlsByClass('OpenLayers.Control.Attribution')[0]; if (attribution !== undefined) { attribution.div.style.pointerEvents = "none"; attribution.updateAttribution(); } }, redraw: function () { OpenLayers.Layer.prototype.redraw.apply(this, arguments); //find out the attribution control and update it. var bounds = this.map.getExtent(); if (bounds != null) { var addr = this.content + '?PageName=' + this.pageName + '&ClientId=' + this.clientId + '&BBOX=' + bounds.toArray() + '&WIDTH=' + this.map.size.w + '&HEIGHT=' + this.map.size.h + '&' + 'time=' + Date.parse(new Date()); this.attribution = ''; var attribution = this.map.getControlsByClass('OpenLayers.Control.Attribution')[0]; if (attribution !== undefined) { attribution.div.style.pointerEvents = "none"; attribution.updateAttribution(); } } }, CLASS_NAME: "OpenLayers.Layer.FixedAdornmentLayer" }); OpenLayers.Projection.defaults["EPSG:900913"] = { units: "m", maxExtent: [-1000000000, -1000000000, 1000000000, 1000000000] }; OpenLayers.Control.Attribution.prototype.separator = ","; OpenLayers.Layer.Bing.prototype.attributionTemplate = '
' + '
' + '
${copyrights}' + '' + 'Terms of Use
'; OpenLayers.Layer.OSM.prototype.attribution = "
© OpenStreetMap contributors
"; // Todo: Overwrite the panzoombar to fix the bug that unable to set the zoom level after dragging. maybe we need to remove it in future. OpenLayers.Control.PanZoomBar.prototype.zoomBarDrag = function (evt) { if (this.mouseDragStart != null) { isDraggingPanZoomBar = true; var deltaY = this.mouseDragStart.y - evt.xy.y; var offsets = OpenLayers.Util.pagePosition(this.zoombarDiv); if ((evt.clientY - offsets[1]) > 0 && (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { var newTop = parseInt(this.slider.style.top) - deltaY; this.slider.style.top = newTop + "px"; this.mouseDragStart = evt.xy.clone(); } // set cumulative displacement this.deltaY = this.zoomStart.y - evt.xy.y; OpenLayers.Event.stop(evt); } }; OpenLayers.Layer.Grid.prototype.toDecimal2 = function (val) { var f = parseFloat(val); if (isNaN(f)) { return false; } var f = Math.round(val * 100) / 100; var s = f.toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } return s; } // Rollback this change. toDecimal2 will cause the precision issue. This change will cause one issue when zooming very deep zoom level(>17). // a. OpenLayer maybe requested the tile out of the Map Extent in for some tiles, the map will display empty tile; // b. The map will send many request(>100) when zooming deep level(>17), it will request more than 1000 tiles in zoom level 20. // https://thinkgeo.atlassian.net/browse/WEBF-19 OpenLayers.Layer.Grid.prototype.getTileBoundsForGridIndex = function (row, col) { var origin = this.getTileOrigin(); var tileLayout = this.gridLayout; //var tilelon = this.toDecimal2(tileLayout.tilelon); //var tilelat = this.toDecimal2(tileLayout.tilelat); var tilelon = tileLayout.tilelon; var tilelat = tileLayout.tilelat; var startcol = tileLayout.startcol; var startrow = tileLayout.startrow; var rowSign = this.rowSign; return new OpenLayers.Bounds( origin.lon + (startcol + col) * tilelon, origin.lat - (startrow + row * rowSign) * tilelat * rowSign, origin.lon + (startcol + col + 1) * tilelon, origin.lat - (startrow + (row - 1) * rowSign) * tilelat * rowSign ); }