--- /srv/reproducible-results/rbuild-debian/r-b-build.bLgHiLH6/b1/openlayers_2.13.1+ds2-10_armhf.changes +++ /srv/reproducible-results/rbuild-debian/r-b-build.bLgHiLH6/b2/openlayers_2.13.1+ds2-10_armhf.changes ├── Files │ @@ -1,2 +1,2 @@ │ │ - 9f01c9c96ae38156af9859f3be439e64 719880 javascript optional libjs-openlayers_2.13.1+ds2-10_all.deb │ + f3dc48632174b06cb5ba5666912fad85 720948 javascript optional libjs-openlayers_2.13.1+ds2-10_all.deb ├── libjs-openlayers_2.13.1+ds2-10_all.deb │ ├── file list │ │ @@ -1,3 +1,3 @@ │ │ -rw-r--r-- 0 0 0 4 2023-01-14 13:27:41.000000 debian-binary │ │ --rw-r--r-- 0 0 0 3680 2023-01-14 13:27:41.000000 control.tar.xz │ │ --rw-r--r-- 0 0 0 716008 2023-01-14 13:27:41.000000 data.tar.xz │ │ +-rw-r--r-- 0 0 0 3684 2023-01-14 13:27:41.000000 control.tar.xz │ │ +-rw-r--r-- 0 0 0 717072 2023-01-14 13:27:41.000000 data.tar.xz │ ├── control.tar.xz │ │ ├── control.tar │ │ │ ├── ./md5sums │ │ │ │ ├── ./md5sums │ │ │ │ │┄ Files differ │ ├── data.tar.xz │ │ ├── data.tar │ │ │ ├── ./usr/share/javascript/openlayers/OpenLayers.js │ │ │ │ ├── js-beautify {} │ │ │ │ │ @@ -5083,323 +5083,2109 @@ │ │ │ │ │ return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); │ │ │ │ │ }, │ │ │ │ │ _hasSingleTextChild: function(el) { │ │ │ │ │ return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; │ │ │ │ │ } │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer.js │ │ │ │ │ + OpenLayers/Tile.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer │ │ │ │ │ - * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ + * Class: OpenLayers.Tile │ │ │ │ │ + * This is a class designed to designate a single tile, however │ │ │ │ │ + * it is explicitly designed to do relatively little. Tiles store │ │ │ │ │ + * information about themselves -- such as the URL that they are related │ │ │ │ │ + * to, and their size - but do not add themselves to the layer div │ │ │ │ │ + * automatically, for example. Create a new tile with the │ │ │ │ │ + * constructor, or a subclass. │ │ │ │ │ + * │ │ │ │ │ + * TBD 3.0 - remove reference to url in above paragraph │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Tile = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the tile. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * tile.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * beforedraw - Triggered before the tile is drawn. Used to defer │ │ │ │ │ + * drawing to an animation queue. To defer drawing, listeners need │ │ │ │ │ + * to return false, which will abort drawing. The queue handler needs │ │ │ │ │ + * to call (true) to actually draw the tile. │ │ │ │ │ + * loadstart - Triggered when tile loading starts. │ │ │ │ │ + * loadend - Triggered when tile loading ends. │ │ │ │ │ + * loaderror - Triggered before the loadend event (i.e. when the tile is │ │ │ │ │ + * still hidden) if the tile could not be loaded. │ │ │ │ │ + * reload - Triggered when an already loading tile is reloaded. │ │ │ │ │ + * unload - Triggered before a tile is unloaded. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zIndex │ │ │ │ │ - * {Number} The zIndex determines the rendering order for a symbolizer. │ │ │ │ │ - * Symbolizers with larger zIndex values are rendered over symbolizers │ │ │ │ │ - * with smaller zIndex values. Default is 0. │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ + * │ │ │ │ │ + * This options can be set in the ``tileOptions`` option from │ │ │ │ │ + * . For example, to be notified of the │ │ │ │ │ + * ``loadend`` event of each tiles: │ │ │ │ │ + * (code) │ │ │ │ │ + * new OpenLayers.Layer.OSM('osm', 'http://tile.openstreetmap.org/${z}/${x}/${y}.png', { │ │ │ │ │ + * tileOptions: { │ │ │ │ │ + * eventListeners: { │ │ │ │ │ + * 'loadend': function(evt) { │ │ │ │ │ + * // do something on loadend │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - zIndex: 0, │ │ │ │ │ + eventListeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} null │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} layer the tile is attached to │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} url of the request. │ │ │ │ │ * │ │ │ │ │ + * TBD 3.0 │ │ │ │ │ + * Deprecated. The base tile class does not need an url. This should be │ │ │ │ │ + * handled in subclasses. Does not belong here. │ │ │ │ │ + */ │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: bounds │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + bounds: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + size: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: position │ │ │ │ │ + * {} Top Left pixel of the tile │ │ │ │ │ + */ │ │ │ │ │ + position: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: isLoading │ │ │ │ │ + * {Boolean} Is the tile loading? │ │ │ │ │ + */ │ │ │ │ │ + isLoading: false, │ │ │ │ │ + │ │ │ │ │ + /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. │ │ │ │ │ + * there is no need for the base tile class to have a url. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * layer - {} layer that the tile will go in. │ │ │ │ │ + * position - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * url - {} │ │ │ │ │ + * size - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.position = position.clone(); │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + this.url = url; │ │ │ │ │ + if (size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //give the tile a unique id based on its BBOX. │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID("Tile_"); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: unload │ │ │ │ │ + * Call immediately before destroying if you are listening to tile │ │ │ │ │ + * events, so that counters are properly handled if tile is still │ │ │ │ │ + * loading at destroy-time. Will only fire an event if the tile is │ │ │ │ │ + * still loading. │ │ │ │ │ + */ │ │ │ │ │ + unload: function() { │ │ │ │ │ + if (this.isLoading) { │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + this.events.triggerEvent("unload"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Nullify references to prevent circular references and memory leaks. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.position = null; │ │ │ │ │ + │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Clear whatever is currently in the tile, then return whether or not │ │ │ │ │ + * it should actually be re-drawn. This is an example implementation │ │ │ │ │ + * that can be overridden by subclasses. The minimum thing to do here │ │ │ │ │ + * is to call and return the result from . │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * force - {Boolean} If true, the tile will not be cleared and no beforedraw │ │ │ │ │ + * event will be fired. This is used for drawing tiles asynchronously │ │ │ │ │ + * after drawing has been cancelled by returning false from a beforedraw │ │ │ │ │ + * listener. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new symbolizer. │ │ │ │ │ + * {Boolean} Whether or not the tile should actually be drawn. Returns null │ │ │ │ │ + * if a beforedraw listener returned false. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Util.extend(this, config); │ │ │ │ │ + draw: function(force) { │ │ │ │ │ + if (!force) { │ │ │ │ │ + //clear tile's contents and mark as not drawn │ │ │ │ │ + this.clear(); │ │ │ │ │ + } │ │ │ │ │ + var draw = this.shouldDraw(); │ │ │ │ │ + if (draw && !force && this.events.triggerEvent("beforedraw") === false) { │ │ │ │ │ + draw = null; │ │ │ │ │ + } │ │ │ │ │ + return draw; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: shouldDraw │ │ │ │ │ + * Return whether or not the tile should actually be (re-)drawn. The only │ │ │ │ │ + * case where we *wouldn't* want to draw the tile is if the tile is outside │ │ │ │ │ + * its layer's maxExtent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the tile should actually be drawn. │ │ │ │ │ + */ │ │ │ │ │ + shouldDraw: function() { │ │ │ │ │ + var withinMaxExtent = false, │ │ │ │ │ + maxExtent = this.layer.maxExtent; │ │ │ │ │ + if (maxExtent) { │ │ │ │ │ + var map = this.layer.map; │ │ │ │ │ + var worldBounds = map.baseLayer.wrapDateLine && map.getMaxExtent(); │ │ │ │ │ + if (this.bounds.intersectsBounds(maxExtent, { │ │ │ │ │ + inclusive: false, │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + })) { │ │ │ │ │ + withinMaxExtent = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return withinMaxExtent || this.layer.displayOutsideMaxExtent; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Sets the bounds on this instance │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds {} │ │ │ │ │ + */ │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + bounds = bounds.clone(); │ │ │ │ │ + if (this.layer.map.baseLayer.wrapDateLine) { │ │ │ │ │ + var worldExtent = this.layer.map.getMaxExtent(), │ │ │ │ │ + tolerance = this.layer.map.getResolution(); │ │ │ │ │ + bounds = bounds.wrapDateLine(worldExtent, { │ │ │ │ │ + leftTolerance: tolerance, │ │ │ │ │ + rightTolerance: tolerance │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + this.bounds = bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a copy of this symbolizer. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Reposition the tile. │ │ │ │ │ * │ │ │ │ │ - * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * position - {} │ │ │ │ │ + * redraw - {Boolean} Call draw method on tile after moving. │ │ │ │ │ + * Default is true │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(bounds, position, redraw) { │ │ │ │ │ + if (redraw == null) { │ │ │ │ │ + redraw = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + this.position = position.clone(); │ │ │ │ │ + if (redraw) { │ │ │ │ │ + this.draw(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear the tile of any bounds/position-related data so that it can │ │ │ │ │ + * be reused in a new location. │ │ │ │ │ + */ │ │ │ │ │ + clear: function(draw) { │ │ │ │ │ + // to be extended by subclasses │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tile" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Feature.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Feature │ │ │ │ │ + * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ + * class specifically combines a marker and a lonlat. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: data │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + data: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: marker │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + marker: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: popupClass │ │ │ │ │ + * {} The class which will be used to instantiate │ │ │ │ │ + * a new Popup. Default is . │ │ │ │ │ + */ │ │ │ │ │ + popupClass: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: popup │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + popup: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Feature │ │ │ │ │ + * Constructor for features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * data - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(layer, lonlat, data) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.lonlat = lonlat; │ │ │ │ │ + this.data = (data != null) ? data : {}; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + │ │ │ │ │ + //remove the popup from the map │ │ │ │ │ + if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ + if (this.popup != null) { │ │ │ │ │ + this.layer.map.removePopup(this.popup); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // remove the marker from the layer │ │ │ │ │ + if (this.layer != null && this.marker != null) { │ │ │ │ │ + this.layer.removeMarker(this.marker); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.lonlat = null; │ │ │ │ │ + this.data = null; │ │ │ │ │ + if (this.marker != null) { │ │ │ │ │ + this.destroyMarker(this.marker); │ │ │ │ │ + this.marker = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.popup != null) { │ │ │ │ │ + this.destroyPopup(this.popup); │ │ │ │ │ + this.popup = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: onScreen │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ + * (based on its 'lonlat' property) │ │ │ │ │ + */ │ │ │ │ │ + onScreen: function() { │ │ │ │ │ + │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ + var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ + } │ │ │ │ │ + return onScreen; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Marker Object created from the 'lonlat' and 'icon' properties │ │ │ │ │ + * set in this.data. If no 'lonlat' is set, returns null. If no │ │ │ │ │ + * 'icon' is set, OpenLayers.Marker() will load the default image. │ │ │ │ │ + * │ │ │ │ │ + * Note - this.marker is set to return value │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + │ │ │ │ │ + if (this.lonlat != null) { │ │ │ │ │ + this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ + } │ │ │ │ │ + return this.marker; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyMarker │ │ │ │ │ + * Destroys marker. │ │ │ │ │ + * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ + * to also specify an alternative function for destroying it │ │ │ │ │ + */ │ │ │ │ │ + destroyMarker: function() { │ │ │ │ │ + this.marker.destroy(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createPopup │ │ │ │ │ + * Creates a popup object created from the 'lonlat', 'popupSize', │ │ │ │ │ + * and 'popupContentHTML' properties set in this.data. It uses │ │ │ │ │ + * this.marker.icon as default anchor. │ │ │ │ │ + * │ │ │ │ │ + * If no 'lonlat' is set, returns null. │ │ │ │ │ + * If no this.marker has been created, no anchor is sent. │ │ │ │ │ + * │ │ │ │ │ + * Note - the returned popup object is 'owned' by the feature, so you │ │ │ │ │ + * cannot use the popup's destroy method to discard the popup. │ │ │ │ │ + * Instead, you must use the feature's destroyPopup │ │ │ │ │ + * │ │ │ │ │ + * Note - this.popup is set to return value │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * closeBox - {Boolean} create popup with closebox or not │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Returns the created popup, which is also set │ │ │ │ │ + * as 'popup' property of this feature. Will be of whatever type │ │ │ │ │ + * specified by this feature's 'popupClass' property, but must be │ │ │ │ │ + * of type . │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + createPopup: function(closeBox) { │ │ │ │ │ + │ │ │ │ │ + if (this.lonlat != null) { │ │ │ │ │ + if (!this.popup) { │ │ │ │ │ + var anchor = (this.marker) ? this.marker.icon : null; │ │ │ │ │ + var popupClass = this.popupClass ? │ │ │ │ │ + this.popupClass : OpenLayers.Popup.Anchored; │ │ │ │ │ + this.popup = new popupClass(this.id + "_popup", │ │ │ │ │ + this.lonlat, │ │ │ │ │ + this.data.popupSize, │ │ │ │ │ + this.data.popupContentHTML, │ │ │ │ │ + anchor, │ │ │ │ │ + closeBox); │ │ │ │ │ + } │ │ │ │ │ + if (this.data.overflow != null) { │ │ │ │ │ + this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.popup.feature = this; │ │ │ │ │ + } │ │ │ │ │ + return this.popup; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyPopup │ │ │ │ │ + * Destroys the popup created via createPopup. │ │ │ │ │ + * │ │ │ │ │ + * As with the marker, if user overrides the createPopup() function, s/he │ │ │ │ │ + * should also be able to override the destruction │ │ │ │ │ + */ │ │ │ │ │ + destroyPopup: function() { │ │ │ │ │ + if (this.popup) { │ │ │ │ │ + this.popup.feature = null; │ │ │ │ │ + this.popup.destroy(); │ │ │ │ │ + this.popup = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Feature/Vector.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +// TRASH THIS │ │ │ │ │ +OpenLayers.State = { │ │ │ │ │ + /** states */ │ │ │ │ │ + UNKNOWN: 'Unknown', │ │ │ │ │ + INSERT: 'Insert', │ │ │ │ │ + UPDATE: 'Update', │ │ │ │ │ + DELETE: 'Delete' │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Feature.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Feature.Vector │ │ │ │ │ + * Vector features use the OpenLayers.Geometry classes as geometry description. │ │ │ │ │ + * They have an 'attributes' property, which is the data object, and a 'style' │ │ │ │ │ + * property, the default values of which are defined in the │ │ │ │ │ + * objects. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: fid │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + fid: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geometry │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + geometry: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: attributes │ │ │ │ │ + * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ + * describe the feature. │ │ │ │ │ + */ │ │ │ │ │ + attributes: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: bounds │ │ │ │ │ + * {} The box bounding that feature's geometry, that │ │ │ │ │ + * property can be set by an object when │ │ │ │ │ + * deserializing the feature, so in most cases it represents an │ │ │ │ │ + * information set by the server. │ │ │ │ │ + */ │ │ │ │ │ + bounds: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: state │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + state: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: style │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + style: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} If this property is set it will be taken into account by │ │ │ │ │ + * {} when upadting or deleting the feature. │ │ │ │ │ + */ │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: renderIntent │ │ │ │ │ + * {String} rendering intent currently being used │ │ │ │ │ + */ │ │ │ │ │ + renderIntent: "default", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: modified │ │ │ │ │ + * {Object} An object with the originals of the geometry and attributes of │ │ │ │ │ + * the feature, if they were changed. Currently this property is only read │ │ │ │ │ + * by , and written by │ │ │ │ │ + * , which sets the geometry property. │ │ │ │ │ + * Applications can set the originals of modified attributes in the │ │ │ │ │ + * attributes property. Note that applications have to check if this │ │ │ │ │ + * object and the attributes property is already created before using it. │ │ │ │ │ + * After a change made with ModifyFeature, this object could look like │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * geometry: >Object │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * When an application has made changes to feature attributes, it could │ │ │ │ │ + * have set the attributes to something like this: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * attributes: { │ │ │ │ │ + * myAttribute: "original" │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Note that only checks for truthy values in │ │ │ │ │ + * *modified.geometry* and the attribute names in *modified.attributes*, │ │ │ │ │ + * but it is recommended to set the original values (and not just true) as │ │ │ │ │ + * attribute value, so applications could use this information to undo │ │ │ │ │ + * changes. │ │ │ │ │ + */ │ │ │ │ │ + modified: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Feature.Vector │ │ │ │ │ + * Create a vector feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} The geometry that this feature │ │ │ │ │ + * represents. │ │ │ │ │ + * attributes - {Object} An optional object that will be mapped to the │ │ │ │ │ + * property. │ │ │ │ │ + * style - {Object} An optional style object. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(geometry, attributes, style) { │ │ │ │ │ + OpenLayers.Feature.prototype.initialize.apply(this, │ │ │ │ │ + [null, null, attributes]); │ │ │ │ │ + this.lonlat = null; │ │ │ │ │ + this.geometry = geometry ? geometry : null; │ │ │ │ │ + this.state = null; │ │ │ │ │ + this.attributes = {}; │ │ │ │ │ + if (attributes) { │ │ │ │ │ + this.attributes = OpenLayers.Util.extend(this.attributes, │ │ │ │ │ + attributes); │ │ │ │ │ + } │ │ │ │ │ + this.style = style ? style : null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layer) { │ │ │ │ │ + this.layer.removeFeatures(this); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.geometry = null; │ │ │ │ │ + this.modified = null; │ │ │ │ │ + OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ + * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ + * properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this vector feature. │ │ │ │ │ */ │ │ │ │ │ clone: function() { │ │ │ │ │ - var Type = eval(this.CLASS_NAME); │ │ │ │ │ - return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + this.geometry ? this.geometry.clone() : null, │ │ │ │ │ + this.attributes, │ │ │ │ │ + this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ + /** │ │ │ │ │ + * Method: onScreen │ │ │ │ │ + * Determine whether the feature is within the map viewport. This method │ │ │ │ │ + * tests for an intersection between the geometry and the viewport │ │ │ │ │ + * bounds. If a more effecient but less precise geometry bounds │ │ │ │ │ + * intersection is desired, call the method with the boundsOnly │ │ │ │ │ + * parameter true. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * boundsOnly - {Boolean} Only test whether a feature's bounds intersects │ │ │ │ │ + * the viewport bounds. Default is false. If false, the feature's │ │ │ │ │ + * geometry must intersect the viewport for onScreen to return true. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ + * based on its bounds if boundsOnly is true). │ │ │ │ │ + */ │ │ │ │ │ + onScreen: function(boundsOnly) { │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if (this.layer && this.layer.map) { │ │ │ │ │ + var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ + if (boundsOnly) { │ │ │ │ │ + var featureBounds = this.geometry.getBounds(); │ │ │ │ │ + onScreen = screenBounds.intersectsBounds(featureBounds); │ │ │ │ │ + } else { │ │ │ │ │ + var screenPoly = screenBounds.toGeometry(); │ │ │ │ │ + onScreen = screenPoly.intersects(this.geometry); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return onScreen; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getVisibility │ │ │ │ │ + * Determine whether the feature is displayed or not. It may not displayed │ │ │ │ │ + * because: │ │ │ │ │ + * - its style display property is set to 'none', │ │ │ │ │ + * - it doesn't belong to any layer, │ │ │ │ │ + * - the styleMap creates a symbolizer with display property set to 'none' │ │ │ │ │ + * for it, │ │ │ │ │ + * - the layer which it belongs to is not visible. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The feature is currently displayed. │ │ │ │ │ + */ │ │ │ │ │ + getVisibility: function() { │ │ │ │ │ + return !(this.style && this.style.display == 'none' || │ │ │ │ │ + !this.layer || │ │ │ │ │ + this.layer && this.layer.styleMap && │ │ │ │ │ + this.layer.styleMap.createSymbolizer(this, this.renderIntent).display == 'none' || │ │ │ │ │ + this.layer && !this.layer.getVisibility()); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create markers │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ + */ │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + return null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * delete markers │ │ │ │ │ + * │ │ │ │ │ + * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ + * to also specify an alternative function for destroying it │ │ │ │ │ + */ │ │ │ │ │ + destroyMarker: function() { │ │ │ │ │ + // pass │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createPopup │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create popups │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ + */ │ │ │ │ │ + createPopup: function() { │ │ │ │ │ + return null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: atPoint │ │ │ │ │ + * Determins whether the feature intersects with the specified location. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ + * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ + */ │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + if (this.geometry) { │ │ │ │ │ + atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ + toleranceLat); │ │ │ │ │ + } │ │ │ │ │ + return atPoint; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyPopup │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * delete popups │ │ │ │ │ + */ │ │ │ │ │ + destroyPopup: function() { │ │ │ │ │ + // pass │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: move │ │ │ │ │ + * Moves the feature and redraws it at its new location │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * location - { or } the │ │ │ │ │ + * location to which to move the feature. │ │ │ │ │ + */ │ │ │ │ │ + move: function(location) { │ │ │ │ │ + │ │ │ │ │ + if (!this.layer || !this.geometry.move) { │ │ │ │ │ + //do nothing if no layer or immoveable geometry │ │ │ │ │ + return undefined; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var pixel; │ │ │ │ │ + if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ + pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ + } else { │ │ │ │ │ + pixel = location; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat()); │ │ │ │ │ + var res = this.layer.map.getResolution(); │ │ │ │ │ + this.geometry.move(res * (pixel.x - lastPixel.x), │ │ │ │ │ + res * (lastPixel.y - pixel.y)); │ │ │ │ │ + this.layer.drawFeature(this); │ │ │ │ │ + return lastPixel; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: toState │ │ │ │ │ + * Sets the new state │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {String} │ │ │ │ │ + */ │ │ │ │ │ + toState: function(state) { │ │ │ │ │ + if (state == OpenLayers.State.UPDATE) { │ │ │ │ │ + switch (this.state) { │ │ │ │ │ + case OpenLayers.State.UNKNOWN: │ │ │ │ │ + case OpenLayers.State.DELETE: │ │ │ │ │ + this.state = state; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.State.UPDATE: │ │ │ │ │ + case OpenLayers.State.INSERT: │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ + switch (this.state) { │ │ │ │ │ + case OpenLayers.State.UNKNOWN: │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + this.state = state; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else if (state == OpenLayers.State.DELETE) { │ │ │ │ │ + switch (this.state) { │ │ │ │ │ + case OpenLayers.State.INSERT: │ │ │ │ │ + // the feature should be destroyed │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.State.DELETE: │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.State.UNKNOWN: │ │ │ │ │ + case OpenLayers.State.UPDATE: │ │ │ │ │ + this.state = state; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else if (state == OpenLayers.State.UNKNOWN) { │ │ │ │ │ + this.state = state; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Feature.Vector" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Feature.Vector.style │ │ │ │ │ + * OpenLayers features can have a number of style attributes. The 'default' │ │ │ │ │ + * style will typically be used if no other style is specified. These │ │ │ │ │ + * styles correspond for the most part, to the styling properties defined │ │ │ │ │ + * by the SVG standard. │ │ │ │ │ + * Information on fill properties: http://www.w3.org/TR/SVG/painting.html#FillProperties │ │ │ │ │ + * Information on stroke properties: http://www.w3.org/TR/SVG/painting.html#StrokeProperties │ │ │ │ │ + * │ │ │ │ │ + * Symbolizer properties: │ │ │ │ │ + * fill - {Boolean} Set to false if no fill is desired. │ │ │ │ │ + * fillColor - {String} Hex fill color. Default is "#ee9900". │ │ │ │ │ + * fillOpacity - {Number} Fill opacity (0-1). Default is 0.4 │ │ │ │ │ + * stroke - {Boolean} Set to false if no stroke is desired. │ │ │ │ │ + * strokeColor - {String} Hex stroke color. Default is "#ee9900". │ │ │ │ │ + * strokeOpacity - {Number} Stroke opacity (0-1). Default is 1. │ │ │ │ │ + * strokeWidth - {Number} Pixel stroke width. Default is 1. │ │ │ │ │ + * strokeLinecap - {String} Stroke cap type. Default is "round". [butt | round | square] │ │ │ │ │ + * strokeDashstyle - {String} Stroke dash style. Default is "solid". [dot | dash | dashdot | longdash | longdashdot | solid] │ │ │ │ │ + * graphic - {Boolean} Set to false if no graphic is desired. │ │ │ │ │ + * pointRadius - {Number} Pixel point radius. Default is 6. │ │ │ │ │ + * pointerEvents - {String} Default is "visiblePainted". │ │ │ │ │ + * cursor - {String} Default is "". │ │ │ │ │ + * externalGraphic - {String} Url to an external graphic that will be used for rendering points. │ │ │ │ │ + * graphicWidth - {Number} Pixel width for sizing an external graphic. │ │ │ │ │ + * graphicHeight - {Number} Pixel height for sizing an external graphic. │ │ │ │ │ + * graphicOpacity - {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ + * graphicXOffset - {Number} Pixel offset along the positive x axis for displacing an external graphic. │ │ │ │ │ + * graphicYOffset - {Number} Pixel offset along the positive y axis for displacing an external graphic. │ │ │ │ │ + * rotation - {Number} For point symbolizers, this is the rotation of a graphic in the clockwise direction about its center point (or any point off center as specified by graphicXOffset and graphicYOffset). │ │ │ │ │ + * graphicZIndex - {Number} The integer z-index value to use in rendering. │ │ │ │ │ + * graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default), │ │ │ │ │ + * "square", "star", "x", "cross", "triangle". │ │ │ │ │ + * graphicTitle - {String} Tooltip when hovering over a feature. *deprecated*, use title instead │ │ │ │ │ + * title - {String} Tooltip when hovering over a feature. Not supported by the canvas renderer. │ │ │ │ │ + * backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic. │ │ │ │ │ + * backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic. │ │ │ │ │ + * backgroundXOffset - {Number} The x offset (in pixels) for the background graphic. │ │ │ │ │ + * backgroundYOffset - {Number} The y offset (in pixels) for the background graphic. │ │ │ │ │ + * backgroundHeight - {Number} The height of the background graphic. If not provided, the graphicHeight will be used. │ │ │ │ │ + * backgroundWidth - {Number} The width of the background width. If not provided, the graphicWidth will be used. │ │ │ │ │ + * label - {String} The text for an optional label. For browsers that use the canvas renderer, this requires either │ │ │ │ │ + * fillText or mozDrawText to be available. │ │ │ │ │ + * labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string │ │ │ │ │ + * composed of two characters. The first character is for the horizontal alignment, the second for the vertical │ │ │ │ │ + * alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical │ │ │ │ │ + * alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". Default is "cm". │ │ │ │ │ + * labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ + * labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ + * labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * labelOutlineColor - {String} The color of the label outline. Default is 'white'. Only supported by the canvas & SVG renderers. │ │ │ │ │ + * labelOutlineWidth - {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the SVG renderers. │ │ │ │ │ + * labelOutlineOpacity - {Number} The opacity (0-1) of the label outline. Default is fontOpacity. Only supported by the canvas & SVG renderers. │ │ │ │ │ + * fontColor - {String} The font color for the label, to be provided like CSS. │ │ │ │ │ + * fontOpacity - {Number} Opacity (0-1) for the label │ │ │ │ │ + * fontFamily - {String} The font family for the label, to be provided like in CSS. │ │ │ │ │ + * fontSize - {String} The font size for the label, to be provided like in CSS. │ │ │ │ │ + * fontStyle - {String} The font style for the label, to be provided like in CSS. │ │ │ │ │ + * fontWeight - {String} The font weight for the label, to be provided like in CSS. │ │ │ │ │ + * display - {String} Symbolizers will have no effect if display is set to "none". All other values have no effect. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Feature.Vector.style = { │ │ │ │ │ + 'default': { │ │ │ │ │ + fillColor: "#ee9900", │ │ │ │ │ + fillOpacity: 0.4, │ │ │ │ │ + hoverFillColor: "white", │ │ │ │ │ + hoverFillOpacity: 0.8, │ │ │ │ │ + strokeColor: "#ee9900", │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + strokeWidth: 1, │ │ │ │ │ + strokeLinecap: "round", │ │ │ │ │ + strokeDashstyle: "solid", │ │ │ │ │ + hoverStrokeColor: "red", │ │ │ │ │ + hoverStrokeOpacity: 1, │ │ │ │ │ + hoverStrokeWidth: 0.2, │ │ │ │ │ + pointRadius: 6, │ │ │ │ │ + hoverPointRadius: 1, │ │ │ │ │ + hoverPointUnit: "%", │ │ │ │ │ + pointerEvents: "visiblePainted", │ │ │ │ │ + cursor: "inherit", │ │ │ │ │ + fontColor: "#000000", │ │ │ │ │ + labelAlign: "cm", │ │ │ │ │ + labelOutlineColor: "white", │ │ │ │ │ + labelOutlineWidth: 3 │ │ │ │ │ + }, │ │ │ │ │ + 'select': { │ │ │ │ │ + fillColor: "blue", │ │ │ │ │ + fillOpacity: 0.4, │ │ │ │ │ + hoverFillColor: "white", │ │ │ │ │ + hoverFillOpacity: 0.8, │ │ │ │ │ + strokeColor: "blue", │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + strokeWidth: 2, │ │ │ │ │ + strokeLinecap: "round", │ │ │ │ │ + strokeDashstyle: "solid", │ │ │ │ │ + hoverStrokeColor: "red", │ │ │ │ │ + hoverStrokeOpacity: 1, │ │ │ │ │ + hoverStrokeWidth: 0.2, │ │ │ │ │ + pointRadius: 6, │ │ │ │ │ + hoverPointRadius: 1, │ │ │ │ │ + hoverPointUnit: "%", │ │ │ │ │ + pointerEvents: "visiblePainted", │ │ │ │ │ + cursor: "pointer", │ │ │ │ │ + fontColor: "#000000", │ │ │ │ │ + labelAlign: "cm", │ │ │ │ │ + labelOutlineColor: "white", │ │ │ │ │ + labelOutlineWidth: 3 │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + 'temporary': { │ │ │ │ │ + fillColor: "#66cccc", │ │ │ │ │ + fillOpacity: 0.2, │ │ │ │ │ + hoverFillColor: "white", │ │ │ │ │ + hoverFillOpacity: 0.8, │ │ │ │ │ + strokeColor: "#66cccc", │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + strokeLinecap: "round", │ │ │ │ │ + strokeWidth: 2, │ │ │ │ │ + strokeDashstyle: "solid", │ │ │ │ │ + hoverStrokeColor: "red", │ │ │ │ │ + hoverStrokeOpacity: 1, │ │ │ │ │ + hoverStrokeWidth: 0.2, │ │ │ │ │ + pointRadius: 6, │ │ │ │ │ + hoverPointRadius: 1, │ │ │ │ │ + hoverPointUnit: "%", │ │ │ │ │ + pointerEvents: "visiblePainted", │ │ │ │ │ + cursor: "inherit", │ │ │ │ │ + fontColor: "#000000", │ │ │ │ │ + labelAlign: "cm", │ │ │ │ │ + labelOutlineColor: "white", │ │ │ │ │ + labelOutlineWidth: 3 │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + 'delete': { │ │ │ │ │ + display: "none" │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy.js │ │ │ │ │ + OpenLayers/Style.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy │ │ │ │ │ - * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the strategy subclasses instead. │ │ │ │ │ + * Class: OpenLayers.Style │ │ │ │ │ + * This class represents a UserStyle obtained │ │ │ │ │ + * from a SLD, containing styling rules. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Style = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The layer this strategy belongs to. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + name: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this style (set if included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + title: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this style (set if abstract is included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + description: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {} name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ + */ │ │ │ │ │ + layerName: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isDefault │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isDefault: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: active │ │ │ │ │ - * {Boolean} The control is active. │ │ │ │ │ + * Property: rules │ │ │ │ │ + * {Array()} │ │ │ │ │ */ │ │ │ │ │ - active: null, │ │ │ │ │ + rules: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: autoActivate │ │ │ │ │ - * {Boolean} The creator of the strategy can set autoActivate to false │ │ │ │ │ - * to fully control when the protocol is activated and deactivated. │ │ │ │ │ - * Defaults to true. │ │ │ │ │ + * APIProperty: context │ │ │ │ │ + * {Object} An optional object with properties that symbolizers' property │ │ │ │ │ + * values should be evaluated against. If no context is specified, │ │ │ │ │ + * feature.attributes will be used │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + context: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: autoDestroy │ │ │ │ │ - * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ - * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ + * Property: defaultStyle │ │ │ │ │ + * {Object} hash of style properties to use as default for merging │ │ │ │ │ + * rule-based style symbolizers onto. If no rules are defined, │ │ │ │ │ + * createSymbolizer will return this style. If is set to │ │ │ │ │ + * true, the defaultStyle will only be taken into account if there are │ │ │ │ │ + * rules defined. │ │ │ │ │ */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ + defaultStyle: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy │ │ │ │ │ - * Abstract class for vector strategies. Create instances of a subclass. │ │ │ │ │ + * Property: defaultsPerSymbolizer │ │ │ │ │ + * {Boolean} If set to true, the will extend the symbolizer │ │ │ │ │ + * of every rule. Properties of the will also be used to set │ │ │ │ │ + * missing symbolizer properties if the symbolizer has stroke, fill or │ │ │ │ │ + * graphic set to true. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + defaultsPerSymbolizer: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: propertyStyles │ │ │ │ │ + * {Hash of Boolean} cache of style properties that need to be parsed for │ │ │ │ │ + * propertyNames. Property names are keys, values won't be used. │ │ │ │ │ + */ │ │ │ │ │ + propertyStyles: null, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Style │ │ │ │ │ + * Creates a UserStyle. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * style - {Object} Optional hash of style properties that will be │ │ │ │ │ + * used as default style for this style object. This style │ │ │ │ │ + * applies if no rules are specified. Symbolizers defined in │ │ │ │ │ + * rules will extend this default style. │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * rules - {Array()} List of rules to be added to the │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ + initialize: function(style, options) { │ │ │ │ │ + │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - // set the active property here, so that user cannot override it │ │ │ │ │ - this.active = false; │ │ │ │ │ + this.rules = []; │ │ │ │ │ + if (options && options.rules) { │ │ │ │ │ + this.addRules(options.rules); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // use the default style from OpenLayers.Feature.Vector if no style │ │ │ │ │ + // was given in the constructor │ │ │ │ │ + this.setDefaultStyle(style || │ │ │ │ │ + OpenLayers.Feature.Vector.style["default"]); │ │ │ │ │ + │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Clean up the strategy. │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.options = null; │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ + this.rules[i].destroy(); │ │ │ │ │ + this.rules[i] = null; │ │ │ │ │ + } │ │ │ │ │ + this.rules = null; │ │ │ │ │ + this.defaultStyle = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayer │ │ │ │ │ - * Called to set the property. │ │ │ │ │ - * │ │ │ │ │ + * Method: createSymbolizer │ │ │ │ │ + * creates a style by applying all feature-dependent rules to the base │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ + * feature - {} feature to evaluate rules for │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} symbolizer hash │ │ │ │ │ */ │ │ │ │ │ - setLayer: function(layer) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ + createSymbolizer: function(feature) { │ │ │ │ │ + var style = this.defaultsPerSymbolizer ? {} : this.createLiterals( │ │ │ │ │ + OpenLayers.Util.extend({}, this.defaultStyle), feature); │ │ │ │ │ + │ │ │ │ │ + var rules = this.rules; │ │ │ │ │ + │ │ │ │ │ + var rule, context; │ │ │ │ │ + var elseRules = []; │ │ │ │ │ + var appliedRules = false; │ │ │ │ │ + for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ + rule = rules[i]; │ │ │ │ │ + // does the rule apply? │ │ │ │ │ + var applies = rule.evaluate(feature); │ │ │ │ │ + │ │ │ │ │ + if (applies) { │ │ │ │ │ + if (rule instanceof OpenLayers.Rule && rule.elseFilter) { │ │ │ │ │ + elseRules.push(rule); │ │ │ │ │ + } else { │ │ │ │ │ + appliedRules = true; │ │ │ │ │ + this.applySymbolizer(rule, style, feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if no other rules apply, apply the rules with else filters │ │ │ │ │ + if (appliedRules == false && elseRules.length > 0) { │ │ │ │ │ + appliedRules = true; │ │ │ │ │ + for (var i = 0, len = elseRules.length; i < len; i++) { │ │ │ │ │ + this.applySymbolizer(elseRules[i], style, feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // don't display if there were rules but none applied │ │ │ │ │ + if (rules.length > 0 && appliedRules == false) { │ │ │ │ │ + style.display = "none"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (style.label != null && typeof style.label !== "string") { │ │ │ │ │ + style.label = String(style.label); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return style; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ + * Method: applySymbolizer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * rule - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * feature - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ - * the strategy was already active. │ │ │ │ │ + * {Object} A style with new symbolizer applied. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - this.active = true; │ │ │ │ │ - return true; │ │ │ │ │ + applySymbolizer: function(rule, style, feature) { │ │ │ │ │ + var symbolizerPrefix = feature.geometry ? │ │ │ │ │ + this.getSymbolizerPrefix(feature.geometry) : │ │ │ │ │ + OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; │ │ │ │ │ + │ │ │ │ │ + var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; │ │ │ │ │ + │ │ │ │ │ + if (this.defaultsPerSymbolizer === true) { │ │ │ │ │ + var defaults = this.defaultStyle; │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + pointRadius: defaults.pointRadius │ │ │ │ │ + }); │ │ │ │ │ + if (symbolizer.stroke === true || symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + strokeWidth: defaults.strokeWidth, │ │ │ │ │ + strokeColor: defaults.strokeColor, │ │ │ │ │ + strokeOpacity: defaults.strokeOpacity, │ │ │ │ │ + strokeDashstyle: defaults.strokeDashstyle, │ │ │ │ │ + strokeLinecap: defaults.strokeLinecap │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fill === true || symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + fillColor: defaults.fillColor, │ │ │ │ │ + fillOpacity: defaults.fillOpacity │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + pointRadius: this.defaultStyle.pointRadius, │ │ │ │ │ + externalGraphic: this.defaultStyle.externalGraphic, │ │ │ │ │ + graphicName: this.defaultStyle.graphicName, │ │ │ │ │ + graphicOpacity: this.defaultStyle.graphicOpacity, │ │ │ │ │ + graphicWidth: this.defaultStyle.graphicWidth, │ │ │ │ │ + graphicHeight: this.defaultStyle.graphicHeight, │ │ │ │ │ + graphicXOffset: this.defaultStyle.graphicXOffset, │ │ │ │ │ + graphicYOffset: this.defaultStyle.graphicYOffset │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ + │ │ │ │ │ + // merge the style with the current style │ │ │ │ │ + return this.createLiterals( │ │ │ │ │ + OpenLayers.Util.extend(style, symbolizer), feature); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ + * Method: createLiterals │ │ │ │ │ + * creates literals for all style properties that have an entry in │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * style - {Object} style to create literals for. Will be modified │ │ │ │ │ + * inline. │ │ │ │ │ + * feature - {Object} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully deactivated or false if │ │ │ │ │ - * the strategy was already inactive. │ │ │ │ │ + * {Object} the modified style │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.active = false; │ │ │ │ │ - return true; │ │ │ │ │ + createLiterals: function(style, feature) { │ │ │ │ │ + var context = OpenLayers.Util.extend({}, feature.attributes || feature.data); │ │ │ │ │ + OpenLayers.Util.extend(context, this.context); │ │ │ │ │ + │ │ │ │ │ + for (var i in this.propertyStyles) { │ │ │ │ │ + style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ + return style; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy" │ │ │ │ │ + /** │ │ │ │ │ + * Method: findPropertyStyles │ │ │ │ │ + * Looks into all rules for this style and the defaultStyle to collect │ │ │ │ │ + * all the style hash property names containing ${...} strings that have │ │ │ │ │ + * to be replaced using the createLiteral method before returning them. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} hash of property names that need createLiteral parsing. The │ │ │ │ │ + * name of the property is the key, and the value is true; │ │ │ │ │ + */ │ │ │ │ │ + findPropertyStyles: function() { │ │ │ │ │ + var propertyStyles = {}; │ │ │ │ │ + │ │ │ │ │ + // check the default style │ │ │ │ │ + var style = this.defaultStyle; │ │ │ │ │ + this.addPropertyStyles(propertyStyles, style); │ │ │ │ │ + │ │ │ │ │ + // walk through all rules to check for properties in their symbolizer │ │ │ │ │ + var rules = this.rules; │ │ │ │ │ + var symbolizer, value; │ │ │ │ │ + for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ + symbolizer = rules[i].symbolizer; │ │ │ │ │ + for (var key in symbolizer) { │ │ │ │ │ + value = symbolizer[key]; │ │ │ │ │ + if (typeof value == "object") { │ │ │ │ │ + // symbolizer key is "Point", "Line" or "Polygon" │ │ │ │ │ + this.addPropertyStyles(propertyStyles, value); │ │ │ │ │ + } else { │ │ │ │ │ + // symbolizer is a hash of style properties │ │ │ │ │ + this.addPropertyStyles(propertyStyles, symbolizer); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addPropertyStyles │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * propertyStyles - {Object} hash to add new property styles to. Will be │ │ │ │ │ + * modified inline │ │ │ │ │ + * symbolizer - {Object} search this symbolizer for property styles │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} propertyStyles hash │ │ │ │ │ + */ │ │ │ │ │ + addPropertyStyles: function(propertyStyles, symbolizer) { │ │ │ │ │ + var property; │ │ │ │ │ + for (var key in symbolizer) { │ │ │ │ │ + property = symbolizer[key]; │ │ │ │ │ + if (typeof property == "string" && │ │ │ │ │ + property.match(/\$\{\w+\}/)) { │ │ │ │ │ + propertyStyles[key] = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addRules │ │ │ │ │ + * Adds rules to this style. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * rules - {Array()} │ │ │ │ │ + */ │ │ │ │ │ + addRules: function(rules) { │ │ │ │ │ + Array.prototype.push.apply(this.rules, rules); │ │ │ │ │ + this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setDefaultStyle │ │ │ │ │ + * Sets the default style for this style object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * style - {Object} Hash of style properties │ │ │ │ │ + */ │ │ │ │ │ + setDefaultStyle: function(style) { │ │ │ │ │ + this.defaultStyle = style; │ │ │ │ │ + this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSymbolizerPrefix │ │ │ │ │ + * Returns the correct symbolizer prefix according to the │ │ │ │ │ + * geometry type of the passed geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} key of the according symbolizer │ │ │ │ │ + */ │ │ │ │ │ + getSymbolizerPrefix: function(geometry) { │ │ │ │ │ + var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ + for (var i = 0, len = prefixes.length; i < len; i++) { │ │ │ │ │ + if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) { │ │ │ │ │ + return prefixes[i]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this style. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this style. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ + // clone rules │ │ │ │ │ + if (this.rules) { │ │ │ │ │ + options.rules = []; │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ + options.rules.push(this.rules[i].clone()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // clone context │ │ │ │ │ + options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ + //clone default style │ │ │ │ │ + var defaultStyle = OpenLayers.Util.extend({}, this.defaultStyle); │ │ │ │ │ + return new OpenLayers.Style(defaultStyle, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Style" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Function: createLiteral │ │ │ │ │ + * converts a style value holding a combination of PropertyName and Literal │ │ │ │ │ + * into a Literal, taking the property values from the passed features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * value - {String} value to parse. If this string contains a construct like │ │ │ │ │ + * "foo ${bar}", then "foo " will be taken as literal, and "${bar}" │ │ │ │ │ + * will be replaced by the value of the "bar" attribute of the passed │ │ │ │ │ + * feature. │ │ │ │ │ + * context - {Object} context to take attribute values from │ │ │ │ │ + * feature - {} optional feature to pass to │ │ │ │ │ + * for evaluating functions in the │ │ │ │ │ + * context. │ │ │ │ │ + * property - {String} optional, name of the property for which the literal is │ │ │ │ │ + * being created for evaluating functions in the context. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} the parsed value. In the example of the value parameter above, the │ │ │ │ │ + * result would be "foo valueOfBar", assuming that the passed feature has an │ │ │ │ │ + * attribute named "bar" with the value "valueOfBar". │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style.createLiteral = function(value, context, feature, property) { │ │ │ │ │ + if (typeof value == "string" && value.indexOf("${") != -1) { │ │ │ │ │ + value = OpenLayers.String.format(value, context, [feature, property]); │ │ │ │ │ + value = (isNaN(value) || !value) ? value : parseFloat(value); │ │ │ │ │ + } │ │ │ │ │ + return value; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES │ │ │ │ │ + * {Array} prefixes of the sld symbolizers. These are the │ │ │ │ │ + * same as the main geometry types │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon', 'Text', │ │ │ │ │ + 'Raster' │ │ │ │ │ +]; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format.js │ │ │ │ │ + OpenLayers/Rule.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format │ │ │ │ │ - * Base class for format reading/writing a variety of formats. Subclasses │ │ │ │ │ - * of OpenLayers.Format are expected to have read and write methods. │ │ │ │ │ + * Class: OpenLayers.Rule │ │ │ │ │ + * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} A reference to options passed to the constructor. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: externalProjection │ │ │ │ │ - * {} When passed a externalProjection and │ │ │ │ │ - * internalProjection, the format will reproject the geometries it │ │ │ │ │ - * reads or writes. The externalProjection is the projection used by │ │ │ │ │ - * the content which is passed into read or which comes out of write. │ │ │ │ │ - * In order to reproject, a projection transformation function for the │ │ │ │ │ - * specified projections must be available. This support may be │ │ │ │ │ - * provided via proj4js or via a custom transformation function. See │ │ │ │ │ - * {} for more information on │ │ │ │ │ - * custom transformations. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} name of this rule │ │ │ │ │ */ │ │ │ │ │ - externalProjection: null, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: internalProjection │ │ │ │ │ - * {} When passed a externalProjection and │ │ │ │ │ - * internalProjection, the format will reproject the geometries it │ │ │ │ │ - * reads or writes. The internalProjection is the projection used by │ │ │ │ │ - * the geometries which are returned by read or which are passed into │ │ │ │ │ - * write. In order to reproject, a projection transformation function │ │ │ │ │ - * for the specified projections must be available. This support may be │ │ │ │ │ - * provided via proj4js or via a custom transformation function. See │ │ │ │ │ - * {} for more information on │ │ │ │ │ - * custom transformations. │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this rule (set if included in SLD) │ │ │ │ │ */ │ │ │ │ │ - internalProjection: null, │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: data │ │ │ │ │ - * {Object} When is true, this is the parsed string sent to │ │ │ │ │ - * . │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ */ │ │ │ │ │ - data: null, │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: keepData │ │ │ │ │ - * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: context │ │ │ │ │ + * {Object} An optional object with properties that the rule should be │ │ │ │ │ + * evaluated against. If no context is specified, feature.attributes will │ │ │ │ │ + * be used. │ │ │ │ │ */ │ │ │ │ │ - keepData: false, │ │ │ │ │ + context: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * Property: filter │ │ │ │ │ + * {} Optional filter for the rule. │ │ │ │ │ + */ │ │ │ │ │ + filter: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: elseFilter │ │ │ │ │ + * {Boolean} Determines whether this rule is only to be applied only if │ │ │ │ │ + * no other rules match (ElseFilter according to the SLD specification). │ │ │ │ │ + * Default is false. For instances of OpenLayers.Rule, if elseFilter is │ │ │ │ │ + * false, the rule will always apply. For subclasses, the else property is │ │ │ │ │ + * ignored. │ │ │ │ │ + */ │ │ │ │ │ + elseFilter: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: symbolizer │ │ │ │ │ + * {Object} Symbolizer or hash of symbolizers for this rule. If hash of │ │ │ │ │ + * symbolizers, keys are one or more of ["Point", "Line", "Polygon"]. The │ │ │ │ │ + * latter if useful if it is required to style e.g. vertices of a line │ │ │ │ │ + * with a point symbolizer. Note, however, that this is not implemented │ │ │ │ │ + * yet in OpenLayers, but it is the way how symbolizers are defined in │ │ │ │ │ + * SLD. │ │ │ │ │ + */ │ │ │ │ │ + symbolizer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: symbolizers │ │ │ │ │ + * {Array} Collection of symbolizers associated with this rule. If │ │ │ │ │ + * provided at construction, the symbolizers array has precedence │ │ │ │ │ + * over the deprecated symbolizer property. Note that multiple │ │ │ │ │ + * symbolizers are not currently supported by the vector renderers. │ │ │ │ │ + * Rules with multiple symbolizers are currently only useful for │ │ │ │ │ + * maintaining elements in an SLD document. │ │ │ │ │ + */ │ │ │ │ │ + symbolizers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScaleDenominator │ │ │ │ │ + * {Number} or {String} minimum scale at which to draw the feature. │ │ │ │ │ + * In the case of a String, this can be a combination of text and │ │ │ │ │ + * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ + */ │ │ │ │ │ + minScaleDenominator: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScaleDenominator │ │ │ │ │ + * {Number} or {String} maximum scale at which to draw the feature. │ │ │ │ │ + * In the case of a String, this can be a combination of text and │ │ │ │ │ + * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ + */ │ │ │ │ │ + maxScaleDenominator: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Rule │ │ │ │ │ + * Creates a Rule. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * format │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * keepData - {Boolean} If true, upon , the data property will be │ │ │ │ │ - * set to the parsed object (e.g. the json or xml object). │ │ │ │ │ - * │ │ │ │ │ + * rule │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * An instance of OpenLayers.Format │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.symbolizer = {}; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + if (this.symbolizers) { │ │ │ │ │ + delete this.symbolizer; │ │ │ │ │ + } │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i in this.symbolizer) { │ │ │ │ │ + this.symbolizer[i] = null; │ │ │ │ │ + } │ │ │ │ │ + this.symbolizer = null; │ │ │ │ │ + delete this.symbolizers; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * evaluates this rule for a specific feature │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} feature to apply the rule to. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} true if the rule applies, false if it does not. │ │ │ │ │ + * This rule is the default rule and always returns true. │ │ │ │ │ + */ │ │ │ │ │ + evaluate: function(feature) { │ │ │ │ │ + var context = this.getContext(feature); │ │ │ │ │ + var applies = true; │ │ │ │ │ + │ │ │ │ │ + if (this.minScaleDenominator || this.maxScaleDenominator) { │ │ │ │ │ + var scale = feature.layer.map.getScale(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // check if within minScale/maxScale bounds │ │ │ │ │ + if (this.minScaleDenominator) { │ │ │ │ │ + applies = scale >= OpenLayers.Style.createLiteral( │ │ │ │ │ + this.minScaleDenominator, context); │ │ │ │ │ + } │ │ │ │ │ + if (applies && this.maxScaleDenominator) { │ │ │ │ │ + applies = scale < OpenLayers.Style.createLiteral( │ │ │ │ │ + this.maxScaleDenominator, context); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // check if optional filter applies │ │ │ │ │ + if (applies && this.filter) { │ │ │ │ │ + // feature id filters get the feature, others get the context │ │ │ │ │ + if (this.filter.CLASS_NAME == "OpenLayers.Filter.FeatureId") { │ │ │ │ │ + applies = this.filter.evaluate(feature); │ │ │ │ │ + } else { │ │ │ │ │ + applies = this.filter.evaluate(context); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return applies; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getContext │ │ │ │ │ + * Gets the context for evaluating this rule │ │ │ │ │ + * │ │ │ │ │ + * Paramters: │ │ │ │ │ + * feature - {} feature to take the context from if │ │ │ │ │ + * none is specified. │ │ │ │ │ + */ │ │ │ │ │ + getContext: function(feature) { │ │ │ │ │ + var context = this.context; │ │ │ │ │ + if (!context) { │ │ │ │ │ + context = feature.attributes || feature.data; │ │ │ │ │ + } │ │ │ │ │ + if (typeof this.context == "function") { │ │ │ │ │ + context = this.context(feature); │ │ │ │ │ + } │ │ │ │ │ + return context; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this rule. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this rule. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ + if (this.symbolizers) { │ │ │ │ │ + // clone symbolizers │ │ │ │ │ + var len = this.symbolizers.length; │ │ │ │ │ + options.symbolizers = new Array(len); │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + options.symbolizers[i] = this.symbolizers[i].clone(); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // clone symbolizer │ │ │ │ │ + options.symbolizer = {}; │ │ │ │ │ + var value, type; │ │ │ │ │ + for (var key in this.symbolizer) { │ │ │ │ │ + value = this.symbolizer[key]; │ │ │ │ │ + type = typeof value; │ │ │ │ │ + if (type === "object") { │ │ │ │ │ + options.symbolizer[key] = OpenLayers.Util.extend({}, value); │ │ │ │ │ + } else if (type === "string") { │ │ │ │ │ + options.symbolizer[key] = value; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // clone filter │ │ │ │ │ + options.filter = this.filter && this.filter.clone(); │ │ │ │ │ + // clone context │ │ │ │ │ + options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ + return new OpenLayers.Rule(options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Spherical.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: Spherical │ │ │ │ │ + * The OpenLayers.Spherical namespace includes utility functions for │ │ │ │ │ + * calculations on the basis of a spherical earth (ignoring ellipsoidal │ │ │ │ │ + * effects), which is accurate enough for most purposes. │ │ │ │ │ + * │ │ │ │ │ + * Relevant links: │ │ │ │ │ + * * http://www.movable-type.co.uk/scripts/latlong.html │ │ │ │ │ + * * http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: computeDistanceBetween │ │ │ │ │ + * Computes the distance between two LonLats. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ + * a JavaScript literal with lon lat properties. │ │ │ │ │ + * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ + * JavaScript literal with lon lat properties. │ │ │ │ │ + * radius - {Float} The radius. Optional. Defaults to 6378137 meters. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The distance in meters. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Spherical.computeDistanceBetween = function(from, to, radius) { │ │ │ │ │ + var R = radius || OpenLayers.Spherical.DEFAULT_RADIUS; │ │ │ │ │ + var sinHalfDeltaLon = Math.sin(Math.PI * (to.lon - from.lon) / 360); │ │ │ │ │ + var sinHalfDeltaLat = Math.sin(Math.PI * (to.lat - from.lat) / 360); │ │ │ │ │ + var a = sinHalfDeltaLat * sinHalfDeltaLat + │ │ │ │ │ + sinHalfDeltaLon * sinHalfDeltaLon * Math.cos(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ + return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: computeHeading │ │ │ │ │ + * Computes the heading from one LonLat to another LonLat. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ + * a JavaScript literal with lon lat properties. │ │ │ │ │ + * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ + * JavaScript literal with lon lat properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The heading in degrees. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Spherical.computeHeading = function(from, to) { │ │ │ │ │ + var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ + var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) - │ │ │ │ │ + Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180); │ │ │ │ │ + return 180 * Math.atan2(y, x) / Math.PI; │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Protocol.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Protocol │ │ │ │ │ + * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the protocol subclasses instead. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: format │ │ │ │ │ + * {} The format used by this protocol. │ │ │ │ │ + */ │ │ │ │ │ + format: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ + */ │ │ │ │ │ + options: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the protocol can set autoDestroy to false │ │ │ │ │ + * to fully control when the protocol is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ + */ │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultFilter │ │ │ │ │ + * {} Optional default filter to read requests │ │ │ │ │ + */ │ │ │ │ │ + defaultFilter: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Protocol │ │ │ │ │ + * Abstract class for vector protocols. Create instances of a subclass. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ + * Method: mergeWithDefaultFilter │ │ │ │ │ + * Merge filter passed to the read method with the default one │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} │ │ │ │ │ + */ │ │ │ │ │ + mergeWithDefaultFilter: function(filter) { │ │ │ │ │ + var merged; │ │ │ │ │ + if (filter && this.defaultFilter) { │ │ │ │ │ + merged = new OpenLayers.Filter.Logical({ │ │ │ │ │ + type: OpenLayers.Filter.Logical.AND, │ │ │ │ │ + filters: [this.defaultFilter, filter] │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + merged = filter || this.defaultFilter || undefined; │ │ │ │ │ + } │ │ │ │ │ + return merged; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + * Clean up the protocol. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() {}, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.options = null; │ │ │ │ │ + this.format = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ - * Read data from a string, and return an object whose type depends on the │ │ │ │ │ - * subclass. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Construct a request for reading new features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {string} Data to read/parse. │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * Depends on the subclass │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - throw new Error('Read not implemented.'); │ │ │ │ │ + read: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.filter = this.mergeWithDefaultFilter(options.filter); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ - * Accept an object, and return a string. │ │ │ │ │ + * APIMethod: create │ │ │ │ │ + * Construct a request for writing newly created features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * object - {Object} Object to be serialized │ │ │ │ │ + * features - {Array({})} or │ │ │ │ │ + * {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string representation of the object. │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - write: function(object) { │ │ │ │ │ - throw new Error('Write not implemented.'); │ │ │ │ │ + create: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: update │ │ │ │ │ + * Construct a request updating modified features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array({})} or │ │ │ │ │ + * {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ + */ │ │ │ │ │ + update: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: delete │ │ │ │ │ + * Construct a request deleting a removed feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ + */ │ │ │ │ │ + "delete": function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: commit │ │ │ │ │ + * Go over the features and for each take action │ │ │ │ │ + * based on the feature state. Possible actions are create, │ │ │ │ │ + * update and delete. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array({})} │ │ │ │ │ + * options - {Object} Object whose possible keys are "create", "update", │ │ │ │ │ + * "delete", "callback" and "scope", the values referenced by the │ │ │ │ │ + * first three are objects as passed to the "create", "update", and │ │ │ │ │ + * "delete" methods, the value referenced by the "callback" key is │ │ │ │ │ + * a function which is called when the commit operation is complete │ │ │ │ │ + * using the scope referenced by the "scope" key. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array({})} An array of │ │ │ │ │ + * objects. │ │ │ │ │ + */ │ │ │ │ │ + commit: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: abort │ │ │ │ │ + * Abort an ongoing request. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * response - {} │ │ │ │ │ + */ │ │ │ │ │ + abort: function(response) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createCallback │ │ │ │ │ + * Returns a function that applies the given public method with resp and │ │ │ │ │ + * options arguments. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * method - {Function} The method to be applied by the callback. │ │ │ │ │ + * response - {} The protocol response object. │ │ │ │ │ + * options - {Object} Options sent to the protocol method │ │ │ │ │ + */ │ │ │ │ │ + createCallback: function(method, response, options) { │ │ │ │ │ + return OpenLayers.Function.bind(function() { │ │ │ │ │ + method.apply(this, [response, options]); │ │ │ │ │ + }, this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Protocol.Response │ │ │ │ │ + * Protocols return Response objects to their users. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Protocol.Response = OpenLayers.Class({ │ │ │ │ │ + /** │ │ │ │ │ + * Property: code │ │ │ │ │ + * {Number} - OpenLayers.Protocol.Response.SUCCESS or │ │ │ │ │ + * OpenLayers.Protocol.Response.FAILURE │ │ │ │ │ + */ │ │ │ │ │ + code: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: requestType │ │ │ │ │ + * {String} The type of request this response corresponds to. Either │ │ │ │ │ + * "create", "read", "update" or "delete". │ │ │ │ │ + */ │ │ │ │ │ + requestType: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: last │ │ │ │ │ + * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ + * false otherwise, defaults to true. │ │ │ │ │ + */ │ │ │ │ │ + last: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: features │ │ │ │ │ + * {Array({})} or {} │ │ │ │ │ + * The features returned in the response by the server. Depending on the │ │ │ │ │ + * protocol's read payload, either features or data will be populated. │ │ │ │ │ + */ │ │ │ │ │ + features: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: data │ │ │ │ │ + * {Object} │ │ │ │ │ + * The data returned in the response by the server. Depending on the │ │ │ │ │ + * protocol's read payload, either features or data will be populated. │ │ │ │ │ + */ │ │ │ │ │ + data: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: reqFeatures │ │ │ │ │ + * {Array({})} or {} │ │ │ │ │ + * The features provided by the user and placed in the request by the │ │ │ │ │ + * protocol. │ │ │ │ │ + */ │ │ │ │ │ + reqFeatures: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: priv │ │ │ │ │ + */ │ │ │ │ │ + priv: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: error │ │ │ │ │ + * {Object} The error object in case a service exception was encountered. │ │ │ │ │ + */ │ │ │ │ │ + error: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: success │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} - true on success, false otherwise │ │ │ │ │ + */ │ │ │ │ │ + success: function() { │ │ │ │ │ + return this.code > 0; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol.Response" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Protocol.Response.SUCCESS = 1; │ │ │ │ │ +OpenLayers.Protocol.Response.FAILURE = 0; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Util/vendorPrefix.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ @@ -5640,1274 +7426,378 @@ │ │ │ │ │ requestFrame: requestFrame, │ │ │ │ │ start: start, │ │ │ │ │ stop: stop │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ })(window); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Kinetic.js │ │ │ │ │ + OpenLayers/Tween.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ * @requires OpenLayers/Animation.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Tween │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Tween = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: threshold │ │ │ │ │ - * In most cases changing the threshold isn't needed. │ │ │ │ │ - * In px/ms, default to 0. │ │ │ │ │ + * APIProperty: easing │ │ │ │ │ + * {(Function)} Easing equation used for the animation │ │ │ │ │ + * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ */ │ │ │ │ │ - threshold: 0, │ │ │ │ │ + easing: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: deceleration │ │ │ │ │ - * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ + * APIProperty: begin │ │ │ │ │ + * {Object} Values to start the animation with │ │ │ │ │ */ │ │ │ │ │ - deceleration: 0.0035, │ │ │ │ │ + begin: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: nbPoints │ │ │ │ │ - * {Integer} the number of points we use to calculate the kinetic │ │ │ │ │ - * initial values. │ │ │ │ │ + * APIProperty: finish │ │ │ │ │ + * {Object} Values to finish the animation with │ │ │ │ │ */ │ │ │ │ │ - nbPoints: 100, │ │ │ │ │ + finish: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delay │ │ │ │ │ - * {Float} time to consider to calculate the kinetic initial values. │ │ │ │ │ - * In ms, default to 200. │ │ │ │ │ + * APIProperty: duration │ │ │ │ │ + * {int} duration of the tween (number of steps) │ │ │ │ │ */ │ │ │ │ │ - delay: 200, │ │ │ │ │ + duration: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: points │ │ │ │ │ - * List of points use to calculate the kinetic initial values. │ │ │ │ │ + * APIProperty: callbacks │ │ │ │ │ + * {Object} An object with start, eachStep and done properties whose values │ │ │ │ │ + * are functions to be call during the animation. They are passed the │ │ │ │ │ + * current computed value as argument. │ │ │ │ │ */ │ │ │ │ │ - points: undefined, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * ID of the timer. │ │ │ │ │ + * Property: time │ │ │ │ │ + * {int} Step counter │ │ │ │ │ */ │ │ │ │ │ - timerId: undefined, │ │ │ │ │ + time: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Kinetic │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * APIProperty: minFrameRate │ │ │ │ │ + * {Number} The minimum framerate for animations in frames per second. After │ │ │ │ │ + * each step, the time spent in the animation is compared to the calculated │ │ │ │ │ + * time at this frame rate. If the animation runs longer than the calculated │ │ │ │ │ + * time, the next step is skipped. Default is 30. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ + minFrameRate: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: begin │ │ │ │ │ - * Begins the dragging. │ │ │ │ │ + * Property: startTime │ │ │ │ │ + * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ + * frames │ │ │ │ │ */ │ │ │ │ │ - begin: function() { │ │ │ │ │ - OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ - this.timerId = undefined; │ │ │ │ │ - this.points = []; │ │ │ │ │ - }, │ │ │ │ │ + startTime: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Updates during the dragging. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The new position. │ │ │ │ │ + * Property: animationId │ │ │ │ │ + * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ */ │ │ │ │ │ - update: function(xy) { │ │ │ │ │ - this.points.unshift({ │ │ │ │ │ - xy: xy, │ │ │ │ │ - tick: new Date().getTime() │ │ │ │ │ - }); │ │ │ │ │ - if (this.points.length > this.nbPoints) { │ │ │ │ │ - this.points.pop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + animationId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: end │ │ │ │ │ - * Ends the dragging, start the kinetic. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The last position. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with two properties: "speed", and "theta". The │ │ │ │ │ - * "speed" and "theta" values are to be passed to the move │ │ │ │ │ - * function when starting the animation. │ │ │ │ │ + * Property: playing │ │ │ │ │ + * {Boolean} Tells if the easing is currently playing │ │ │ │ │ */ │ │ │ │ │ - end: function(xy) { │ │ │ │ │ - var last, now = new Date().getTime(); │ │ │ │ │ - for (var i = 0, l = this.points.length, point; i < l; i++) { │ │ │ │ │ - point = this.points[i]; │ │ │ │ │ - if (now - point.tick > this.delay) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - last = point; │ │ │ │ │ - } │ │ │ │ │ - if (!last) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var time = new Date().getTime() - last.tick; │ │ │ │ │ - var dist = Math.sqrt(Math.pow(xy.x - last.xy.x, 2) + │ │ │ │ │ - Math.pow(xy.y - last.xy.y, 2)); │ │ │ │ │ - var speed = dist / time; │ │ │ │ │ - if (speed == 0 || speed < this.threshold) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var theta = Math.asin((xy.y - last.xy.y) / dist); │ │ │ │ │ - if (last.xy.x <= xy.x) { │ │ │ │ │ - theta = Math.PI - theta; │ │ │ │ │ - } │ │ │ │ │ - return { │ │ │ │ │ - speed: speed, │ │ │ │ │ - theta: theta │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ + playing: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Launch the kinetic move pan. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tween │ │ │ │ │ + * Creates a Tween. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * info - {Object} An object with two properties, "speed", and "theta". │ │ │ │ │ - * These values are those returned from the "end" call. │ │ │ │ │ - * callback - {Function} Function called on every step of the animation, │ │ │ │ │ - * receives x, y (values to pan), end (is the last point). │ │ │ │ │ + * easing - {(Function)} easing function method to use │ │ │ │ │ */ │ │ │ │ │ - move: function(info, callback) { │ │ │ │ │ - var v0 = info.speed; │ │ │ │ │ - var fx = Math.cos(info.theta); │ │ │ │ │ - var fy = -Math.sin(info.theta); │ │ │ │ │ - │ │ │ │ │ - var initialTime = new Date().getTime(); │ │ │ │ │ - │ │ │ │ │ - var lastX = 0; │ │ │ │ │ - var lastY = 0; │ │ │ │ │ - │ │ │ │ │ - var timerCallback = function() { │ │ │ │ │ - if (this.timerId == null) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var t = new Date().getTime() - initialTime; │ │ │ │ │ - │ │ │ │ │ - var p = (-this.deceleration * Math.pow(t, 2)) / 2.0 + v0 * t; │ │ │ │ │ - var x = p * fx; │ │ │ │ │ - var y = p * fy; │ │ │ │ │ - │ │ │ │ │ - var args = {}; │ │ │ │ │ - args.end = false; │ │ │ │ │ - var v = -this.deceleration * t + v0; │ │ │ │ │ - │ │ │ │ │ - if (v <= 0) { │ │ │ │ │ - OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - args.end = true; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - args.x = x - lastX; │ │ │ │ │ - args.y = y - lastY; │ │ │ │ │ - lastX = x; │ │ │ │ │ - lastY = y; │ │ │ │ │ - callback(args.x, args.y, args.end); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - this.timerId = OpenLayers.Animation.start( │ │ │ │ │ - OpenLayers.Function.bind(timerCallback, this) │ │ │ │ │ - ); │ │ │ │ │ + initialize: function(easing) { │ │ │ │ │ + this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Kinetic" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Popup.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Popup │ │ │ │ │ - * A popup is a small div that can opened and closed on the map. │ │ │ │ │ - * Typically opened in response to clicking on a marker. │ │ │ │ │ - * See . Popup's don't require their own │ │ │ │ │ - * layer and are added the the map using the │ │ │ │ │ - * method. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * popup = new OpenLayers.Popup("chicken", │ │ │ │ │ - * new OpenLayers.LonLat(5,40), │ │ │ │ │ - * new OpenLayers.Size(200,200), │ │ │ │ │ - * "example popup", │ │ │ │ │ - * true); │ │ │ │ │ - * │ │ │ │ │ - * map.addPopup(popup); │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Popup = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} custom event manager │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** Property: id │ │ │ │ │ - * {String} the unique identifier assigned to this popup. │ │ │ │ │ - */ │ │ │ │ │ - id: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} the position of this popup on the map │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: div │ │ │ │ │ - * {DOMElement} the div that contains this popup. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentSize │ │ │ │ │ - * {} the width and height of the content. │ │ │ │ │ - */ │ │ │ │ │ - contentSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} the width and height of the popup. │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentHTML │ │ │ │ │ - * {String} An HTML string for this popup to display. │ │ │ │ │ - */ │ │ │ │ │ - contentHTML: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backgroundColor │ │ │ │ │ - * {String} the background color used by the popup. │ │ │ │ │ - */ │ │ │ │ │ - backgroundColor: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: opacity │ │ │ │ │ - * {float} the opacity of this popup (between 0.0 and 1.0) │ │ │ │ │ - */ │ │ │ │ │ - opacity: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: border │ │ │ │ │ - * {String} the border size of the popup. (eg 2px) │ │ │ │ │ - */ │ │ │ │ │ - border: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentDiv │ │ │ │ │ - * {DOMElement} a reference to the element that holds the content of │ │ │ │ │ - * the div. │ │ │ │ │ - */ │ │ │ │ │ - contentDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: groupDiv │ │ │ │ │ - * {DOMElement} First and only child of 'div'. The group Div contains the │ │ │ │ │ - * 'contentDiv' and the 'closeDiv'. │ │ │ │ │ - */ │ │ │ │ │ - groupDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: closeDiv │ │ │ │ │ - * {DOMElement} the optional closer image │ │ │ │ │ - */ │ │ │ │ │ - closeDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoSize │ │ │ │ │ - * {Boolean} Resize the popup to auto-fit the contents. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - autoSize: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minSize │ │ │ │ │ - * {} Minimum size allowed for the popup's contents. │ │ │ │ │ - */ │ │ │ │ │ - minSize: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxSize │ │ │ │ │ - * {} Maximum size allowed for the popup's contents. │ │ │ │ │ - */ │ │ │ │ │ - maxSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: displayClass │ │ │ │ │ - * {String} The CSS class of the popup. │ │ │ │ │ - */ │ │ │ │ │ - displayClass: "olPopup", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentDisplayClass │ │ │ │ │ - * {String} The CSS class of the popup content div. │ │ │ │ │ - */ │ │ │ │ │ - contentDisplayClass: "olPopupContent", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: padding │ │ │ │ │ - * {int or } An extra opportunity to specify internal │ │ │ │ │ - * padding of the content div inside the popup. This was originally │ │ │ │ │ - * confused with the css padding as specified in style.css's │ │ │ │ │ - * 'olPopupContent' class. We would like to get rid of this altogether, │ │ │ │ │ - * except that it does come in handy for the framed and anchoredbubble │ │ │ │ │ - * popups, who need to maintain yet another barrier between their │ │ │ │ │ - * content and the outer border of the popup itself. │ │ │ │ │ + * APIMethod: start │ │ │ │ │ + * Plays the Tween, and calls the callback method on each step │ │ │ │ │ * │ │ │ │ │ - * Note that in order to not break API, we must continue to support │ │ │ │ │ - * this property being set as an integer. Really, though, we'd like to │ │ │ │ │ - * have this specified as a Bounds object so that user can specify │ │ │ │ │ - * distinct left, top, right, bottom paddings. With the 3.0 release │ │ │ │ │ - * we can make this only a bounds. │ │ │ │ │ - */ │ │ │ │ │ - padding: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: disableFirefoxOverflowHack │ │ │ │ │ - * {Boolean} The hack for overflow in Firefox causes all elements │ │ │ │ │ - * to be re-drawn, which causes Flash elements to be │ │ │ │ │ - * re-initialized, which is troublesome. │ │ │ │ │ - * With this property the hack can be disabled. │ │ │ │ │ - */ │ │ │ │ │ - disableFirefoxOverflowHack: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: fixPadding │ │ │ │ │ - * To be removed in 3.0, this function merely helps us to deal with the │ │ │ │ │ - * case where the user may have set an integer value for padding, │ │ │ │ │ - * instead of an object. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * begin - {Object} values to start the animation with │ │ │ │ │ + * finish - {Object} values to finish the animation with │ │ │ │ │ + * duration - {int} duration of the tween (number of steps) │ │ │ │ │ + * options - {Object} hash of options (callbacks (start, eachStep, done), │ │ │ │ │ + * minFrameRate) │ │ │ │ │ */ │ │ │ │ │ - fixPadding: function() { │ │ │ │ │ - if (typeof this.padding == "number") { │ │ │ │ │ - this.padding = new OpenLayers.Bounds( │ │ │ │ │ - this.padding, this.padding, this.padding, this.padding │ │ │ │ │ - ); │ │ │ │ │ + start: function(begin, finish, duration, options) { │ │ │ │ │ + this.playing = true; │ │ │ │ │ + this.begin = begin; │ │ │ │ │ + this.finish = finish; │ │ │ │ │ + this.duration = duration; │ │ │ │ │ + this.callbacks = options.callbacks; │ │ │ │ │ + this.minFrameRate = options.minFrameRate || 30; │ │ │ │ │ + this.time = 0; │ │ │ │ │ + this.startTime = new Date().getTime(); │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + if (this.callbacks && this.callbacks.start) { │ │ │ │ │ + this.callbacks.start.call(this, this.begin); │ │ │ │ │ } │ │ │ │ │ + this.animationId = OpenLayers.Animation.start( │ │ │ │ │ + OpenLayers.Function.bind(this.play, this) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: panMapIfOutOfView │ │ │ │ │ - * {Boolean} When drawn, pan map such that the entire popup is visible in │ │ │ │ │ - * the current viewport (if necessary). │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - panMapIfOutOfView: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: keepInMap │ │ │ │ │ - * {Boolean} If panMapIfOutOfView is false, and this property is true, │ │ │ │ │ - * contrain the popup such that it always fits in the available map │ │ │ │ │ - * space. By default, this is not set on the base class. If you are │ │ │ │ │ - * creating popups that are near map edges and not allowing pannning, │ │ │ │ │ - * and especially if you have a popup which has a │ │ │ │ │ - * fixedRelativePosition, setting this to false may be a smart thing to │ │ │ │ │ - * do. Subclasses may want to override this setting. │ │ │ │ │ - * │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - keepInMap: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: closeOnMove │ │ │ │ │ - * {Boolean} When map pans, close the popup. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - closeOnMove: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} this gets set in Map.js when the popup is added to the map │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Popup │ │ │ │ │ - * Create a popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} a unqiue identifier for this popup. If null is passed │ │ │ │ │ - * an identifier will be automatically generated. │ │ │ │ │ - * lonlat - {} The position on the map the popup will │ │ │ │ │ - * be shown. │ │ │ │ │ - * contentSize - {} The size of the content. │ │ │ │ │ - * contentHTML - {String} An HTML string to display inside the │ │ │ │ │ - * popup. │ │ │ │ │ - * closeBox - {Boolean} Whether to display a close box inside │ │ │ │ │ - * the popup. │ │ │ │ │ - * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { │ │ │ │ │ - if (id == null) { │ │ │ │ │ - id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.id = id; │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ - │ │ │ │ │ - this.contentSize = (contentSize != null) ? contentSize : │ │ │ │ │ - new OpenLayers.Size( │ │ │ │ │ - OpenLayers.Popup.WIDTH, │ │ │ │ │ - OpenLayers.Popup.HEIGHT); │ │ │ │ │ - if (contentHTML != null) { │ │ │ │ │ - this.contentHTML = contentHTML; │ │ │ │ │ - } │ │ │ │ │ - this.backgroundColor = OpenLayers.Popup.COLOR; │ │ │ │ │ - this.opacity = OpenLayers.Popup.OPACITY; │ │ │ │ │ - this.border = OpenLayers.Popup.BORDER; │ │ │ │ │ - │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id, null, null, │ │ │ │ │ - null, null, null, "hidden"); │ │ │ │ │ - this.div.className = this.displayClass; │ │ │ │ │ - │ │ │ │ │ - var groupDivId = this.id + "_GroupDiv"; │ │ │ │ │ - this.groupDiv = OpenLayers.Util.createDiv(groupDivId, null, null, │ │ │ │ │ - null, "relative", null, │ │ │ │ │ - "hidden"); │ │ │ │ │ - │ │ │ │ │ - var id = this.div.id + "_contentDiv"; │ │ │ │ │ - this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(), │ │ │ │ │ - null, "relative"); │ │ │ │ │ - this.contentDiv.className = this.contentDisplayClass; │ │ │ │ │ - this.groupDiv.appendChild(this.contentDiv); │ │ │ │ │ - this.div.appendChild(this.groupDiv); │ │ │ │ │ - │ │ │ │ │ - if (closeBox) { │ │ │ │ │ - this.addCloseBox(closeBoxCallback); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.registerEvents(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + * APIMethod: stop │ │ │ │ │ + * Stops the Tween, and calls the done callback │ │ │ │ │ + * Doesn't do anything if animation is already finished │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.contentHTML = null; │ │ │ │ │ - │ │ │ │ │ - this.backgroundColor = null; │ │ │ │ │ - this.opacity = null; │ │ │ │ │ - this.border = null; │ │ │ │ │ - │ │ │ │ │ - if (this.closeOnMove && this.map) { │ │ │ │ │ - this.map.events.unregister("movestart", this, this.hide); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.closeDiv); │ │ │ │ │ - this.groupDiv.removeChild(this.closeDiv); │ │ │ │ │ + stop: function() { │ │ │ │ │ + if (!this.playing) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - this.closeDiv = null; │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.groupDiv); │ │ │ │ │ - this.groupDiv = null; │ │ │ │ │ │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.removePopup(this); │ │ │ │ │ + if (this.callbacks && this.callbacks.done) { │ │ │ │ │ + this.callbacks.done.call(this, this.finish); │ │ │ │ │ } │ │ │ │ │ - this.map = null; │ │ │ │ │ - this.div = null; │ │ │ │ │ - │ │ │ │ │ - this.autoSize = null; │ │ │ │ │ - this.minSize = null; │ │ │ │ │ - this.maxSize = null; │ │ │ │ │ - this.padding = null; │ │ │ │ │ - this.panMapIfOutOfView = null; │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + this.playing = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Constructs the elements that make up the popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} the position the popup in pixels. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} Reference to a div that contains the drawn popup │ │ │ │ │ + /** │ │ │ │ │ + * Method: play │ │ │ │ │ + * Calls the appropriate easing method │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - if (px == null) { │ │ │ │ │ - if ((this.lonlat != null) && (this.map != null)) { │ │ │ │ │ - px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ + play: function() { │ │ │ │ │ + var value = {}; │ │ │ │ │ + for (var i in this.begin) { │ │ │ │ │ + var b = this.begin[i]; │ │ │ │ │ + var f = this.finish[i]; │ │ │ │ │ + if (b == null || f == null || isNaN(b) || isNaN(f)) { │ │ │ │ │ + throw new TypeError('invalid value for Tween'); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // this assumes that this.map already exists, which is okay because │ │ │ │ │ - // this.draw is only called once the popup has been added to the map. │ │ │ │ │ - if (this.closeOnMove) { │ │ │ │ │ - this.map.events.register("movestart", this, this.hide); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //listen to movestart, moveend to disable overflow (FF bug) │ │ │ │ │ - if (!this.disableFirefoxOverflowHack && OpenLayers.BROWSER_NAME == 'firefox') { │ │ │ │ │ - this.map.events.register("movestart", this, function() { │ │ │ │ │ - var style = document.defaultView.getComputedStyle( │ │ │ │ │ - this.contentDiv, null │ │ │ │ │ - ); │ │ │ │ │ - var currentOverflow = style.getPropertyValue("overflow"); │ │ │ │ │ - if (currentOverflow != "hidden") { │ │ │ │ │ - this.contentDiv._oldOverflow = currentOverflow; │ │ │ │ │ - this.contentDiv.style.overflow = "hidden"; │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.map.events.register("moveend", this, function() { │ │ │ │ │ - var oldOverflow = this.contentDiv._oldOverflow; │ │ │ │ │ - if (oldOverflow) { │ │ │ │ │ - this.contentDiv.style.overflow = oldOverflow; │ │ │ │ │ - this.contentDiv._oldOverflow = null; │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - if (!this.autoSize && !this.size) { │ │ │ │ │ - this.setSize(this.contentSize); │ │ │ │ │ - } │ │ │ │ │ - this.setBackgroundColor(); │ │ │ │ │ - this.setOpacity(); │ │ │ │ │ - this.setBorder(); │ │ │ │ │ - this.setContentHTML(); │ │ │ │ │ │ │ │ │ │ - if (this.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ + var c = f - b; │ │ │ │ │ + value[i] = this.easing.apply(this, [this.time, b, c, this.duration]); │ │ │ │ │ } │ │ │ │ │ + this.time++; │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updatePosition │ │ │ │ │ - * if the popup has a lonlat and its map members set, │ │ │ │ │ - * then have it move itself to its proper position │ │ │ │ │ - */ │ │ │ │ │ - updatePosition: function() { │ │ │ │ │ - if ((this.lonlat) && (this.map)) { │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ - if (px) { │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ + if (this.callbacks && this.callbacks.eachStep) { │ │ │ │ │ + // skip frames if frame rate drops below threshold │ │ │ │ │ + if ((new Date().getTime() - this.startTime) / this.time <= 1000 / this.minFrameRate) { │ │ │ │ │ + this.callbacks.eachStep.call(this, value); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} the top and left position of the popup div. │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ + if (this.time > this.duration) { │ │ │ │ │ + this.stop(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: visible │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Boolean indicating whether or not the popup is visible │ │ │ │ │ - */ │ │ │ │ │ - visible: function() { │ │ │ │ │ - return OpenLayers.Element.visible(this.div); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toggle │ │ │ │ │ - * Toggles visibility of the popup. │ │ │ │ │ + * Create empty functions for all easing methods. │ │ │ │ │ */ │ │ │ │ │ - toggle: function() { │ │ │ │ │ - if (this.visible()) { │ │ │ │ │ - this.hide(); │ │ │ │ │ - } else { │ │ │ │ │ - this.show(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tween" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing │ │ │ │ │ + * │ │ │ │ │ + * Credits: │ │ │ │ │ + * Easing Equations by Robert Penner, │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing = { │ │ │ │ │ /** │ │ │ │ │ - * Method: show │ │ │ │ │ - * Makes the popup visible. │ │ │ │ │ + * Create empty functions for all easing methods. │ │ │ │ │ */ │ │ │ │ │ - show: function() { │ │ │ │ │ - this.div.style.display = ''; │ │ │ │ │ - │ │ │ │ │ - if (this.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: hide │ │ │ │ │ - * Makes the popup invisible. │ │ │ │ │ - */ │ │ │ │ │ - hide: function() { │ │ │ │ │ - this.div.style.display = 'none'; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing.Linear │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing.Linear = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * Used to adjust the size of the popup. │ │ │ │ │ - * │ │ │ │ │ + * Function: easeIn │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * contentSize - {} the new size for the popup's │ │ │ │ │ - * contents div (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(contentSize) { │ │ │ │ │ - this.size = contentSize.clone(); │ │ │ │ │ - │ │ │ │ │ - // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ - // must add that to the desired "size". │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ - │ │ │ │ │ - // take into account the popup's 'padding' property │ │ │ │ │ - this.fixPadding(); │ │ │ │ │ - wPadding += this.padding.left + this.padding.right; │ │ │ │ │ - hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ - │ │ │ │ │ - // make extra space for the close div │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ - wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //increase size of the main popup div to take into account the │ │ │ │ │ - // users's desired padding and close div. │ │ │ │ │ - this.size.w += wPadding; │ │ │ │ │ - this.size.h += hPadding; │ │ │ │ │ - │ │ │ │ │ - //now if our browser is IE, we need to actually make the contents │ │ │ │ │ - // div itself bigger to take its own padding into effect. this makes │ │ │ │ │ - // me want to shoot someone, but so it goes. │ │ │ │ │ - if (OpenLayers.BROWSER_NAME == "msie") { │ │ │ │ │ - this.contentSize.w += │ │ │ │ │ - contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - this.contentSize.h += │ │ │ │ │ - contentDivPadding.bottom + contentDivPadding.top; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.width = this.size.w + "px"; │ │ │ │ │ - this.div.style.height = this.size.h + "px"; │ │ │ │ │ - } │ │ │ │ │ - if (this.contentDiv != null) { │ │ │ │ │ - this.contentDiv.style.width = contentSize.w + "px"; │ │ │ │ │ - this.contentDiv.style.height = contentSize.h + "px"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: updateSize │ │ │ │ │ - * Auto size the popup so that it precisely fits its contents (as │ │ │ │ │ - * determined by this.contentDiv.innerHTML). Popup size will, of │ │ │ │ │ - * course, be limited by the available space on the current map │ │ │ │ │ - */ │ │ │ │ │ - updateSize: function() { │ │ │ │ │ - │ │ │ │ │ - // determine actual render dimensions of the contents by putting its │ │ │ │ │ - // contents into a fake contentDiv (for the CSS) and then measuring it │ │ │ │ │ - var preparedHTML = "
" + │ │ │ │ │ - this.contentDiv.innerHTML + │ │ │ │ │ - "
"; │ │ │ │ │ - │ │ │ │ │ - var containerElement = (this.map) ? this.map.div : document.body; │ │ │ │ │ - var realSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ - preparedHTML, null, { │ │ │ │ │ - displayClass: this.displayClass, │ │ │ │ │ - containerElement: containerElement │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // is the "real" size of the div is safe to display in our map? │ │ │ │ │ - var safeSize = this.getSafeContentSize(realSize); │ │ │ │ │ - │ │ │ │ │ - var newSize = null; │ │ │ │ │ - if (safeSize.equals(realSize)) { │ │ │ │ │ - //real size of content is small enough to fit on the map, │ │ │ │ │ - // so we use real size. │ │ │ │ │ - newSize = realSize; │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - │ │ │ │ │ - // make a new 'size' object with the clipped dimensions │ │ │ │ │ - // set or null if not clipped. │ │ │ │ │ - var fixedSize = { │ │ │ │ │ - w: (safeSize.w < realSize.w) ? safeSize.w : null, │ │ │ │ │ - h: (safeSize.h < realSize.h) ? safeSize.h : null │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - if (fixedSize.w && fixedSize.h) { │ │ │ │ │ - //content is too big in both directions, so we will use │ │ │ │ │ - // max popup size (safeSize), knowing well that it will │ │ │ │ │ - // overflow both ways. │ │ │ │ │ - newSize = safeSize; │ │ │ │ │ - } else { │ │ │ │ │ - //content is clipped in only one direction, so we need to │ │ │ │ │ - // run getRenderedDimensions() again with a fixed dimension │ │ │ │ │ - var clippedSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ - preparedHTML, fixedSize, { │ │ │ │ │ - displayClass: this.contentDisplayClass, │ │ │ │ │ - containerElement: containerElement │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - //if the clipped size is still the same as the safeSize, │ │ │ │ │ - // that means that our content must be fixed in the │ │ │ │ │ - // offending direction. If overflow is 'auto', this means │ │ │ │ │ - // we are going to have a scrollbar for sure, so we must │ │ │ │ │ - // adjust for that. │ │ │ │ │ - // │ │ │ │ │ - var currentOverflow = OpenLayers.Element.getStyle( │ │ │ │ │ - this.contentDiv, "overflow" │ │ │ │ │ - ); │ │ │ │ │ - if ((currentOverflow != "hidden") && │ │ │ │ │ - (clippedSize.equals(safeSize))) { │ │ │ │ │ - var scrollBar = OpenLayers.Util.getScrollbarWidth(); │ │ │ │ │ - if (fixedSize.w) { │ │ │ │ │ - clippedSize.h += scrollBar; │ │ │ │ │ - } else { │ │ │ │ │ - clippedSize.w += scrollBar; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - newSize = this.getSafeContentSize(clippedSize); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.setSize(newSize); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBackgroundColor │ │ │ │ │ - * Sets the background color of the popup. │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * color - {String} the background color. eg "#FFBBBB" │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - setBackgroundColor: function(color) { │ │ │ │ │ - if (color != undefined) { │ │ │ │ │ - this.backgroundColor = color; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.backgroundColor = this.backgroundColor; │ │ │ │ │ - } │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Sets the opacity of the popup. │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - if (opacity != undefined) { │ │ │ │ │ - this.opacity = opacity; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - // for Mozilla and Safari │ │ │ │ │ - this.div.style.opacity = this.opacity; │ │ │ │ │ - │ │ │ │ │ - // for IE │ │ │ │ │ - this.div.style.filter = 'alpha(opacity=' + this.opacity * 100 + ')'; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBorder │ │ │ │ │ - * Sets the border style of the popup. │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * border - {String} The border style value. eg 2px │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - setBorder: function(border) { │ │ │ │ │ - if (border != undefined) { │ │ │ │ │ - this.border = border; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.border = this.border; │ │ │ │ │ - } │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setContentHTML │ │ │ │ │ - * Allows the user to set the HTML content of the popup. │ │ │ │ │ - * │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * contentHTML - {String} HTML for the div. │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - setContentHTML: function(contentHTML) { │ │ │ │ │ - │ │ │ │ │ - if (contentHTML != null) { │ │ │ │ │ - this.contentHTML = contentHTML; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if ((this.contentDiv != null) && │ │ │ │ │ - (this.contentHTML != null) && │ │ │ │ │ - (this.contentHTML != this.contentDiv.innerHTML)) { │ │ │ │ │ - │ │ │ │ │ - this.contentDiv.innerHTML = this.contentHTML; │ │ │ │ │ - │ │ │ │ │ - if (this.autoSize) { │ │ │ │ │ - │ │ │ │ │ - //if popup has images, listen for when they finish │ │ │ │ │ - // loading and resize accordingly │ │ │ │ │ - this.registerImageListeners(); │ │ │ │ │ - │ │ │ │ │ - //auto size the popup to its current contents │ │ │ │ │ - this.updateSize(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ + easeInOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: registerImageListeners │ │ │ │ │ - * Called when an image contained by the popup loaded. this function │ │ │ │ │ - * updates the popup size, then unregisters the image load listener. │ │ │ │ │ - */ │ │ │ │ │ - registerImageListeners: function() { │ │ │ │ │ - │ │ │ │ │ - // As the images load, this function will call updateSize() to │ │ │ │ │ - // resize the popup to fit the content div (which presumably is now │ │ │ │ │ - // bigger than when the image was not loaded). │ │ │ │ │ - // │ │ │ │ │ - // If the 'panMapIfOutOfView' property is set, we will pan the newly │ │ │ │ │ - // resized popup back into view. │ │ │ │ │ - // │ │ │ │ │ - // Note that this function, when called, will have 'popup' and │ │ │ │ │ - // 'img' properties in the context. │ │ │ │ │ - // │ │ │ │ │ - var onImgLoad = function() { │ │ │ │ │ - if (this.popup.id === null) { // this.popup has been destroyed! │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.popup.updateSize(); │ │ │ │ │ - │ │ │ │ │ - if (this.popup.visible() && this.popup.panMapIfOutOfView) { │ │ │ │ │ - this.popup.panIntoView(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Event.stopObserving( │ │ │ │ │ - this.img, "load", this.img._onImgLoad │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - //cycle through the images and if their size is 0x0, that means that │ │ │ │ │ - // they haven't been loaded yet, so we attach the listener, which │ │ │ │ │ - // will fire when the images finish loading and will resize the │ │ │ │ │ - // popup accordingly to its new size. │ │ │ │ │ - var images = this.contentDiv.getElementsByTagName("img"); │ │ │ │ │ - for (var i = 0, len = images.length; i < len; i++) { │ │ │ │ │ - var img = images[i]; │ │ │ │ │ - if (img.width == 0 || img.height == 0) { │ │ │ │ │ - │ │ │ │ │ - var context = { │ │ │ │ │ - 'popup': this, │ │ │ │ │ - 'img': img │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - //expando this function to the image itself before registering │ │ │ │ │ - // it. This way we can easily and properly unregister it. │ │ │ │ │ - img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.observe(img, 'load', img._onImgLoad); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing.Expo = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getSafeContentSize │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * size - {} Desired size to make the popup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A size to make the popup which is neither smaller │ │ │ │ │ - * than the specified minimum size, nor bigger than the maximum │ │ │ │ │ - * size (which is calculated relative to the size of the viewport). │ │ │ │ │ - */ │ │ │ │ │ - getSafeContentSize: function(size) { │ │ │ │ │ - │ │ │ │ │ - var safeContentSize = size.clone(); │ │ │ │ │ - │ │ │ │ │ - // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ - // must add that to the desired "size". │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ - │ │ │ │ │ - // take into account the popup's 'padding' property │ │ │ │ │ - this.fixPadding(); │ │ │ │ │ - wPadding += this.padding.left + this.padding.right; │ │ │ │ │ - hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ - │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ - wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // prevent the popup from being smaller than a specified minimal size │ │ │ │ │ - if (this.minSize) { │ │ │ │ │ - safeContentSize.w = Math.max(safeContentSize.w, │ │ │ │ │ - (this.minSize.w - wPadding)); │ │ │ │ │ - safeContentSize.h = Math.max(safeContentSize.h, │ │ │ │ │ - (this.minSize.h - hPadding)); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // prevent the popup from being bigger than a specified maximum size │ │ │ │ │ - if (this.maxSize) { │ │ │ │ │ - safeContentSize.w = Math.min(safeContentSize.w, │ │ │ │ │ - (this.maxSize.w - wPadding)); │ │ │ │ │ - safeContentSize.h = Math.min(safeContentSize.h, │ │ │ │ │ - (this.maxSize.h - hPadding)); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //make sure the desired size to set doesn't result in a popup that │ │ │ │ │ - // is bigger than the map's viewport. │ │ │ │ │ - // │ │ │ │ │ - if (this.map && this.map.size) { │ │ │ │ │ - │ │ │ │ │ - var extraX = 0, │ │ │ │ │ - extraY = 0; │ │ │ │ │ - if (this.keepInMap && !this.panMapIfOutOfView) { │ │ │ │ │ - var px = this.map.getPixelFromLonLat(this.lonlat); │ │ │ │ │ - switch (this.relativePosition) { │ │ │ │ │ - case "tr": │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "tl": │ │ │ │ │ - extraX = this.map.size.w - px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "bl": │ │ │ │ │ - extraX = this.map.size.w - px.x; │ │ │ │ │ - extraY = px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "br": │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = px.y; │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var maxY = this.map.size.h - │ │ │ │ │ - this.map.paddingForPopups.top - │ │ │ │ │ - this.map.paddingForPopups.bottom - │ │ │ │ │ - hPadding - extraY; │ │ │ │ │ - │ │ │ │ │ - var maxX = this.map.size.w - │ │ │ │ │ - this.map.paddingForPopups.left - │ │ │ │ │ - this.map.paddingForPopups.right - │ │ │ │ │ - wPadding - extraX; │ │ │ │ │ - │ │ │ │ │ - safeContentSize.w = Math.min(safeContentSize.w, maxX); │ │ │ │ │ - safeContentSize.h = Math.min(safeContentSize.h, maxY); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return safeContentSize; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getContentDivPadding │ │ │ │ │ - * Glorious, oh glorious hack in order to determine the css 'padding' of │ │ │ │ │ - * the contentDiv. IE/Opera return null here unless we actually add the │ │ │ │ │ - * popup's main 'div' element (which contains contentDiv) to the DOM. │ │ │ │ │ - * So we make it invisible and then add it to the document temporarily. │ │ │ │ │ - * │ │ │ │ │ - * Once we've taken the padding readings we need, we then remove it │ │ │ │ │ - * from the DOM (it will actually get added to the DOM in │ │ │ │ │ - * Map.js's addPopup) │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - getContentDivPadding: function() { │ │ │ │ │ - │ │ │ │ │ - //use cached value if we have it │ │ │ │ │ - var contentDivPadding = this._contentDivPadding; │ │ │ │ │ - if (!contentDivPadding) { │ │ │ │ │ - │ │ │ │ │ - if (this.div.parentNode == null) { │ │ │ │ │ - //make the div invisible and add it to the page │ │ │ │ │ - this.div.style.display = "none"; │ │ │ │ │ - document.body.appendChild(this.div); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //read the padding settings from css, put them in an OL.Bounds │ │ │ │ │ - contentDivPadding = new OpenLayers.Bounds( │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-left"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-bottom"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-right"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-top") │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - //cache the value │ │ │ │ │ - this._contentDivPadding = contentDivPadding; │ │ │ │ │ - │ │ │ │ │ - if (this.div.parentNode == document.body) { │ │ │ │ │ - //remove the div from the page and make it visible again │ │ │ │ │ - document.body.removeChild(this.div); │ │ │ │ │ - this.div.style.display = ""; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return contentDivPadding; │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addCloseBox │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * callback - {Function} The callback to be called when the close button │ │ │ │ │ - * is clicked. │ │ │ │ │ - */ │ │ │ │ │ - addCloseBox: function(callback) { │ │ │ │ │ - │ │ │ │ │ - this.closeDiv = OpenLayers.Util.createDiv( │ │ │ │ │ - this.id + "_close", null, { │ │ │ │ │ - w: 17, │ │ │ │ │ - h: 17 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - this.closeDiv.className = "olPopupCloseBox"; │ │ │ │ │ - │ │ │ │ │ - // use the content div's css padding to determine if we should │ │ │ │ │ - // padd the close div │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - │ │ │ │ │ - this.closeDiv.style.right = contentDivPadding.right + "px"; │ │ │ │ │ - this.closeDiv.style.top = contentDivPadding.top + "px"; │ │ │ │ │ - this.groupDiv.appendChild(this.closeDiv); │ │ │ │ │ - │ │ │ │ │ - var closePopup = callback || function(e) { │ │ │ │ │ - this.hide(); │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Event.observe(this.closeDiv, "touchend", │ │ │ │ │ - OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ - OpenLayers.Event.observe(this.closeDiv, "click", │ │ │ │ │ - OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: panIntoView │ │ │ │ │ - * Pans the map such that the popup is totaly viewable (if necessary) │ │ │ │ │ - */ │ │ │ │ │ - panIntoView: function() { │ │ │ │ │ - │ │ │ │ │ - var mapSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - //start with the top left corner of the popup, in px, │ │ │ │ │ - // relative to the viewport │ │ │ │ │ - var origTL = this.map.getViewPortPxFromLayerPx(new OpenLayers.Pixel( │ │ │ │ │ - parseInt(this.div.style.left), │ │ │ │ │ - parseInt(this.div.style.top) │ │ │ │ │ - )); │ │ │ │ │ - var newTL = origTL.clone(); │ │ │ │ │ - │ │ │ │ │ - //new left (compare to margins, using this.size to calculate right) │ │ │ │ │ - if (origTL.x < this.map.paddingForPopups.left) { │ │ │ │ │ - newTL.x = this.map.paddingForPopups.left; │ │ │ │ │ - } else │ │ │ │ │ - if ((origTL.x + this.size.w) > (mapSize.w - this.map.paddingForPopups.right)) { │ │ │ │ │ - newTL.x = mapSize.w - this.map.paddingForPopups.right - this.size.w; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //new top (compare to margins, using this.size to calculate bottom) │ │ │ │ │ - if (origTL.y < this.map.paddingForPopups.top) { │ │ │ │ │ - newTL.y = this.map.paddingForPopups.top; │ │ │ │ │ - } else │ │ │ │ │ - if ((origTL.y + this.size.h) > (mapSize.h - this.map.paddingForPopups.bottom)) { │ │ │ │ │ - newTL.y = mapSize.h - this.map.paddingForPopups.bottom - this.size.h; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var dx = origTL.x - newTL.x; │ │ │ │ │ - var dy = origTL.y - newTL.y; │ │ │ │ │ - │ │ │ │ │ - this.map.pan(dx, dy); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: registerEvents │ │ │ │ │ - * Registers events on the popup. │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ * │ │ │ │ │ - * Do this in a separate function so that subclasses can │ │ │ │ │ - * choose to override it if they wish to deal differently │ │ │ │ │ - * with mouse events │ │ │ │ │ - * │ │ │ │ │ - * Note in the following handler functions that some special │ │ │ │ │ - * care is needed to deal correctly with mousing and popups. │ │ │ │ │ - * │ │ │ │ │ - * Because the user might select the zoom-rectangle option and │ │ │ │ │ - * then drag it over a popup, we need a safe way to allow the │ │ │ │ │ - * mousemove and mouseup events to pass through the popup when │ │ │ │ │ - * they are initiated from outside. The same procedure is needed for │ │ │ │ │ - * touchmove and touchend events. │ │ │ │ │ - * │ │ │ │ │ - * Otherwise, we want to essentially kill the event propagation │ │ │ │ │ - * for all other events, though we have to do so carefully, │ │ │ │ │ - * without disabling basic html functionality, like clicking on │ │ │ │ │ - * hyperlinks or drag-selecting text. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - registerEvents: function() { │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div, null, true); │ │ │ │ │ - │ │ │ │ │ - function onTouchstart(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - } │ │ │ │ │ - this.events.on({ │ │ │ │ │ - "mousedown": this.onmousedown, │ │ │ │ │ - "mousemove": this.onmousemove, │ │ │ │ │ - "mouseup": this.onmouseup, │ │ │ │ │ - "click": this.onclick, │ │ │ │ │ - "mouseout": this.onmouseout, │ │ │ │ │ - "dblclick": this.ondblclick, │ │ │ │ │ - "touchstart": onTouchstart, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmousedown │ │ │ │ │ - * When mouse goes down within the popup, make a note of │ │ │ │ │ - * it locally, and then do not propagate the mousedown │ │ │ │ │ - * (but do so safely so that user can select text inside) │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - onmousedown: function(evt) { │ │ │ │ │ - this.mousedown = true; │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + easeInOut: function(t, b, c, d) { │ │ │ │ │ + if (t == 0) return b; │ │ │ │ │ + if (t == d) return b + c; │ │ │ │ │ + if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; │ │ │ │ │ + return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmousemove │ │ │ │ │ - * If the drag was started within the popup, then │ │ │ │ │ - * do not propagate the mousemove (but do so safely │ │ │ │ │ - * so that user can select text inside) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onmousemove: function(evt) { │ │ │ │ │ - if (this.mousedown) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Expo" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmouseup │ │ │ │ │ - * When mouse comes up within the popup, after going down │ │ │ │ │ - * in it, reset the flag, and then (once again) do not │ │ │ │ │ - * propagate the event, but do so safely so that user can │ │ │ │ │ - * select text inside │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onmouseup: function(evt) { │ │ │ │ │ - if (this.mousedown) { │ │ │ │ │ - this.mousedown = false; │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing.Quad │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing.Quad = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onclick │ │ │ │ │ - * Ignore clicks, but allowing default browser handling │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - onclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * (t /= d) * t + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmouseout │ │ │ │ │ - * When mouse goes out of the popup set the flag to false so that │ │ │ │ │ - * if they let go and then drag back in, we won't be confused. │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - onmouseout: function(evt) { │ │ │ │ │ - this.mousedown = false; │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: ondblclick │ │ │ │ │ - * Ignore double-clicks, but allowing default browser handling │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - ondblclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + easeInOut: function(t, b, c, d) { │ │ │ │ │ + if ((t /= d / 2) < 1) return c / 2 * t * t + b; │ │ │ │ │ + return -c / 2 * ((--t) * (t - 2) - 1) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ -OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ -OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ -OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ -OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Quad" │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Events.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ @@ -8077,10159 +8967,2356 @@ │ │ │ │ │ │ │ │ │ │ OpenLayers.Event.observe(element, 'MSPointerUp', cb); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Events" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Tween.js │ │ │ │ │ + OpenLayers/Geometry.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Namespace: OpenLayers.Tween │ │ │ │ │ + * Class: OpenLayers.Geometry │ │ │ │ │ + * A Geometry is a description of a geographic object. Create an instance of │ │ │ │ │ + * this class with the constructor. This is a base class, │ │ │ │ │ + * typical geometry types are described by subclasses of this class. │ │ │ │ │ + * │ │ │ │ │ + * Note that if you use the method, you must │ │ │ │ │ + * explicitly include the OpenLayers.Format.WKT in your build. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Tween = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: easing │ │ │ │ │ - * {(Function)} Easing equation used for the animation │ │ │ │ │ - * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ - */ │ │ │ │ │ - easing: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: begin │ │ │ │ │ - * {Object} Values to start the animation with │ │ │ │ │ - */ │ │ │ │ │ - begin: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: finish │ │ │ │ │ - * {Object} Values to finish the animation with │ │ │ │ │ - */ │ │ │ │ │ - finish: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: duration │ │ │ │ │ - * {int} duration of the tween (number of steps) │ │ │ │ │ - */ │ │ │ │ │ - duration: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: callbacks │ │ │ │ │ - * {Object} An object with start, eachStep and done properties whose values │ │ │ │ │ - * are functions to be call during the animation. They are passed the │ │ │ │ │ - * current computed value as argument. │ │ │ │ │ - */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ +OpenLayers.Geometry = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: time │ │ │ │ │ - * {int} Step counter │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique identifier for this geometry. │ │ │ │ │ */ │ │ │ │ │ - time: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minFrameRate │ │ │ │ │ - * {Number} The minimum framerate for animations in frames per second. After │ │ │ │ │ - * each step, the time spent in the animation is compared to the calculated │ │ │ │ │ - * time at this frame rate. If the animation runs longer than the calculated │ │ │ │ │ - * time, the next step is skipped. Default is 30. │ │ │ │ │ + * Property: parent │ │ │ │ │ + * {}This is set when a Geometry is added as component │ │ │ │ │ + * of another geometry │ │ │ │ │ */ │ │ │ │ │ - minFrameRate: null, │ │ │ │ │ + parent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startTime │ │ │ │ │ - * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ - * frames │ │ │ │ │ + * Property: bounds │ │ │ │ │ + * {} The bounds of this geometry │ │ │ │ │ */ │ │ │ │ │ - startTime: null, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: animationId │ │ │ │ │ - * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ + * Constructor: OpenLayers.Geometry │ │ │ │ │ + * Creates a geometry object. │ │ │ │ │ */ │ │ │ │ │ - animationId: null, │ │ │ │ │ + initialize: function() { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: playing │ │ │ │ │ - * {Boolean} Tells if the easing is currently playing │ │ │ │ │ - */ │ │ │ │ │ - playing: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tween │ │ │ │ │ - * Creates a Tween. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * easing - {(Function)} easing function method to use │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(easing) { │ │ │ │ │ - this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: start │ │ │ │ │ - * Plays the Tween, and calls the callback method on each step │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a clone of this geometry. Does not set any non-standard │ │ │ │ │ + * properties of the cloned geometry. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * begin - {Object} values to start the animation with │ │ │ │ │ - * finish - {Object} values to finish the animation with │ │ │ │ │ - * duration - {int} duration of the tween (number of steps) │ │ │ │ │ - * options - {Object} hash of options (callbacks (start, eachStep, done), │ │ │ │ │ - * minFrameRate) │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this geometry. │ │ │ │ │ */ │ │ │ │ │ - start: function(begin, finish, duration, options) { │ │ │ │ │ - this.playing = true; │ │ │ │ │ - this.begin = begin; │ │ │ │ │ - this.finish = finish; │ │ │ │ │ - this.duration = duration; │ │ │ │ │ - this.callbacks = options.callbacks; │ │ │ │ │ - this.minFrameRate = options.minFrameRate || 30; │ │ │ │ │ - this.time = 0; │ │ │ │ │ - this.startTime = new Date().getTime(); │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - if (this.callbacks && this.callbacks.start) { │ │ │ │ │ - this.callbacks.start.call(this, this.begin); │ │ │ │ │ - } │ │ │ │ │ - this.animationId = OpenLayers.Animation.start( │ │ │ │ │ - OpenLayers.Function.bind(this.play, this) │ │ │ │ │ - ); │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Geometry(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: stop │ │ │ │ │ - * Stops the Tween, and calls the done callback │ │ │ │ │ - * Doesn't do anything if animation is already finished │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Set the bounds for this Geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - stop: function() { │ │ │ │ │ - if (!this.playing) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.callbacks && this.callbacks.done) { │ │ │ │ │ - this.callbacks.done.call(this, this.finish); │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + if (bounds) { │ │ │ │ │ + this.bounds = bounds.clone(); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - this.playing = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: play │ │ │ │ │ - * Calls the appropriate easing method │ │ │ │ │ + * Method: clearBounds │ │ │ │ │ + * Nullify this components bounds and that of its parent as well. │ │ │ │ │ */ │ │ │ │ │ - play: function() { │ │ │ │ │ - var value = {}; │ │ │ │ │ - for (var i in this.begin) { │ │ │ │ │ - var b = this.begin[i]; │ │ │ │ │ - var f = this.finish[i]; │ │ │ │ │ - if (b == null || f == null || isNaN(b) || isNaN(f)) { │ │ │ │ │ - throw new TypeError('invalid value for Tween'); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var c = f - b; │ │ │ │ │ - value[i] = this.easing.apply(this, [this.time, b, c, this.duration]); │ │ │ │ │ - } │ │ │ │ │ - this.time++; │ │ │ │ │ - │ │ │ │ │ - if (this.callbacks && this.callbacks.eachStep) { │ │ │ │ │ - // skip frames if frame rate drops below threshold │ │ │ │ │ - if ((new Date().getTime() - this.startTime) / this.time <= 1000 / this.minFrameRate) { │ │ │ │ │ - this.callbacks.eachStep.call(this, value); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.time > this.duration) { │ │ │ │ │ - this.stop(); │ │ │ │ │ + clearBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + if (this.parent) { │ │ │ │ │ + this.parent.clearBounds(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Create empty functions for all easing methods. │ │ │ │ │ - */ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tween" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing │ │ │ │ │ - * │ │ │ │ │ - * Credits: │ │ │ │ │ - * Easing Equations by Robert Penner, │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing = { │ │ │ │ │ - /** │ │ │ │ │ - * Create empty functions for all easing methods. │ │ │ │ │ - */ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Linear │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Linear = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ + * Method: extendBounds │ │ │ │ │ + * Extend the existing bounds to include the new bounds. │ │ │ │ │ + * If geometry's bounds is not yet set, then set a new Bounds. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * newBounds - {} │ │ │ │ │ */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + extendBounds: function(newBounds) { │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if (!bounds) { │ │ │ │ │ + this.setBounds(newBounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.bounds.extend(newBounds); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ + * APIMethod: getBounds │ │ │ │ │ + * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ + * is calculated again, this makes queries faster. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + getBounds: function() { │ │ │ │ │ + if (this.bounds == null) { │ │ │ │ │ + this.calculateBounds(); │ │ │ │ │ + } │ │ │ │ │ + return this.bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds for the geometry. │ │ │ │ │ */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + // │ │ │ │ │ + // This should be overridden by subclasses. │ │ │ │ │ + // │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Expo = { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ + * Valid options depend on the specific geometry type. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - if (t == 0) return b; │ │ │ │ │ - if (t == d) return b + c; │ │ │ │ │ - if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; │ │ │ │ │ - return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Expo" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Quad │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Quad = { │ │ │ │ │ + distanceTo: function(geometry, options) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * (t /= d) * t + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ - }, │ │ │ │ │ + getVertices: function(nodes) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ + * Method: atPoint │ │ │ │ │ + * Note - This is only an approximation based on the bounds of the │ │ │ │ │ + * geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ + * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ + * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - if ((t /= d / 2) < 1) return c / 2 * t * t + b; │ │ │ │ │ - return -c / 2 * ((--t) * (t - 2) - 1) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Quad" │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Projection.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Projection │ │ │ │ │ - * Methods for coordinate transforms between coordinate systems. By default, │ │ │ │ │ - * OpenLayers ships with the ability to transform coordinates between │ │ │ │ │ - * geographic (EPSG:4326) and web or spherical mercator (EPSG:900913 et al.) │ │ │ │ │ - * coordinate reference systems. See the method for details │ │ │ │ │ - * on usage. │ │ │ │ │ - * │ │ │ │ │ - * Additional transforms may be added by using the │ │ │ │ │ - * library. If the proj4js library is included, the method │ │ │ │ │ - * will work between any two coordinate reference systems with proj4js │ │ │ │ │ - * definitions. │ │ │ │ │ - * │ │ │ │ │ - * If the proj4js library is not included, or if you wish to allow transforms │ │ │ │ │ - * between arbitrary coordinate reference systems, use the │ │ │ │ │ - * method to register a custom transform method. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: proj │ │ │ │ │ - * {Object} Proj4js.Proj instance. │ │ │ │ │ + * {Boolean} Whether or not the geometry is at the specified location │ │ │ │ │ */ │ │ │ │ │ - proj: null, │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: projCode │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - projCode: null, │ │ │ │ │ + var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ + var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: titleRegEx │ │ │ │ │ - * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ - */ │ │ │ │ │ - titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ + var toleranceBounds = │ │ │ │ │ + new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ + this.bounds.bottom - dY, │ │ │ │ │ + this.bounds.right + dX, │ │ │ │ │ + this.bounds.top + dY); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Projection │ │ │ │ │ - * This class offers several methods for interacting with a wrapped │ │ │ │ │ - * pro4js projection object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * projCode - {String} A string identifying the Well Known Identifier for │ │ │ │ │ - * the projection. │ │ │ │ │ - * options - {Object} An optional object to set additional properties │ │ │ │ │ - * on the projection. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A projection object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(projCode, options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.projCode = projCode; │ │ │ │ │ - if (typeof Proj4js == "object") { │ │ │ │ │ - this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ + atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ } │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCode │ │ │ │ │ - * Get the string SRS code. │ │ │ │ │ - * │ │ │ │ │ + * Method: getLength │ │ │ │ │ + * Calculate the length of this geometry. This method is defined in │ │ │ │ │ + * subclasses. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The SRS code. │ │ │ │ │ + * {Float} The length of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - getCode: function() { │ │ │ │ │ - return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ + getLength: function() { │ │ │ │ │ + //to be overridden by geometries that actually have a length │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getUnits │ │ │ │ │ - * Get the units string for the projection -- returns null if │ │ │ │ │ - * proj4js is not available. │ │ │ │ │ - * │ │ │ │ │ + * Method: getArea │ │ │ │ │ + * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The units abbreviation. │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - getUnits: function() { │ │ │ │ │ - return this.proj ? this.proj.units : null; │ │ │ │ │ + getArea: function() { │ │ │ │ │ + //to be overridden by geometries that actually have an area │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: toString │ │ │ │ │ - * Convert projection to string (getCode wrapper). │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The projection code. │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - return this.getCode(); │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: equals │ │ │ │ │ - * Test equality of two projection instances. Determines equality based │ │ │ │ │ - * soley on the projection code. │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Returns a text representation of the geometry. If the WKT format is │ │ │ │ │ + * included in a build, this will be the Well-Known Text │ │ │ │ │ + * representation. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The two projections are equivalent. │ │ │ │ │ + * {String} String representation of this geometry. │ │ │ │ │ */ │ │ │ │ │ - equals: function(projection) { │ │ │ │ │ - var p = projection, │ │ │ │ │ - equals = false; │ │ │ │ │ - if (p) { │ │ │ │ │ - if (!(p instanceof OpenLayers.Projection)) { │ │ │ │ │ - p = new OpenLayers.Projection(p); │ │ │ │ │ - } │ │ │ │ │ - if ((typeof Proj4js == "object") && this.proj.defData && p.proj.defData) { │ │ │ │ │ - equals = this.proj.defData.replace(this.titleRegEx, "") == │ │ │ │ │ - p.proj.defData.replace(this.titleRegEx, ""); │ │ │ │ │ - } else if (p.getCode) { │ │ │ │ │ - var source = this.getCode(), │ │ │ │ │ - target = p.getCode(); │ │ │ │ │ - equals = source == target || │ │ │ │ │ - !!OpenLayers.Projection.transforms[source] && │ │ │ │ │ - OpenLayers.Projection.transforms[source][target] === │ │ │ │ │ - OpenLayers.Projection.nullTransform; │ │ │ │ │ - } │ │ │ │ │ + toString: function() { │ │ │ │ │ + var string; │ │ │ │ │ + if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ + string = OpenLayers.Format.WKT.prototype.write( │ │ │ │ │ + new OpenLayers.Feature.Vector(this) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + string = Object.prototype.toString.call(this); │ │ │ │ │ } │ │ │ │ │ - return equals; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* Method: destroy │ │ │ │ │ - * Destroy projection object. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - delete this.proj; │ │ │ │ │ - delete this.projCode; │ │ │ │ │ + return string; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Projection" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: transforms │ │ │ │ │ - * {Object} Transforms is an object, with from properties, each of which may │ │ │ │ │ - * have a to property. This allows you to define projections without │ │ │ │ │ - * requiring support for proj4js to be included. │ │ │ │ │ + * Function: OpenLayers.Geometry.fromWKT │ │ │ │ │ + * Generate a geometry given a Well-Known Text string. For this method to │ │ │ │ │ + * work, you must include the OpenLayers.Format.WKT in your build │ │ │ │ │ + * explicitly. │ │ │ │ │ * │ │ │ │ │ - * This object has keys which correspond to a 'source' projection object. The │ │ │ │ │ - * keys should be strings, corresponding to the projection.getCode() value. │ │ │ │ │ - * Each source projection object should have a set of destination projection │ │ │ │ │ - * keys included in the object. │ │ │ │ │ - * │ │ │ │ │ - * Each value in the destination object should be a transformation function, │ │ │ │ │ - * where the function is expected to be passed an object with a .x and a .y │ │ │ │ │ - * property. The function should return the object, with the .x and .y │ │ │ │ │ - * transformed according to the transformation function. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * wkt - {String} A string representing the geometry in Well-Known Text. │ │ │ │ │ * │ │ │ │ │ - * Note - Properties on this object should not be set directly. To add a │ │ │ │ │ - * transform method to this object, use the method. For an │ │ │ │ │ - * example of usage, see the OpenLayers.Layer.SphericalMercator file. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.transforms = {}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIProperty: defaults │ │ │ │ │ - * {Object} Defaults for the SRS codes known to OpenLayers (currently │ │ │ │ │ - * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, │ │ │ │ │ - * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units, │ │ │ │ │ - * maxExtent (the validity extent for the SRS) and yx (true if this SRS is │ │ │ │ │ - * known to have a reverse axis order). │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry of the appropriate class. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Projection.defaults = { │ │ │ │ │ - "EPSG:4326": { │ │ │ │ │ - units: "degrees", │ │ │ │ │ - maxExtent: [-180, -90, 180, 90], │ │ │ │ │ - yx: true │ │ │ │ │ - }, │ │ │ │ │ - "CRS:84": { │ │ │ │ │ - units: "degrees", │ │ │ │ │ - maxExtent: [-180, -90, 180, 90] │ │ │ │ │ - }, │ │ │ │ │ - "EPSG:900913": { │ │ │ │ │ - units: "m", │ │ │ │ │ - maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34] │ │ │ │ │ +OpenLayers.Geometry.fromWKT = function(wkt) { │ │ │ │ │ + var geom; │ │ │ │ │ + if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ + var format = OpenLayers.Geometry.fromWKT.format; │ │ │ │ │ + if (!format) { │ │ │ │ │ + format = new OpenLayers.Format.WKT(); │ │ │ │ │ + OpenLayers.Geometry.fromWKT.format = format; │ │ │ │ │ + } │ │ │ │ │ + var result = format.read(wkt); │ │ │ │ │ + if (result instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ + geom = result.geometry; │ │ │ │ │ + } else if (OpenLayers.Util.isArray(result)) { │ │ │ │ │ + var len = result.length; │ │ │ │ │ + var components = new Array(len); │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + components[i] = result[i].geometry; │ │ │ │ │ + } │ │ │ │ │ + geom = new OpenLayers.Geometry.Collection(components); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return geom; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addTransform │ │ │ │ │ - * Set a custom transform method between two projections. Use this method in │ │ │ │ │ - * cases where the proj4js lib is not available or where custom projections │ │ │ │ │ - * need to be handled. │ │ │ │ │ + * Method: OpenLayers.Geometry.segmentsIntersect │ │ │ │ │ + * Determine whether two line segments intersect. Optionally calculates │ │ │ │ │ + * and returns the intersection point. This function is optimized for │ │ │ │ │ + * cases where seg1.x2 >= seg2.x1 || seg2.x2 >= seg1.x1. In those │ │ │ │ │ + * obvious cases where there is no intersection, the function should │ │ │ │ │ + * not be called. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * from - {String} The code for the source projection │ │ │ │ │ - * to - {String} the code for the destination projection │ │ │ │ │ - * method - {Function} A function that takes a point as an argument and │ │ │ │ │ - * transforms that point from the source to the destination projection │ │ │ │ │ - * in place. The original point should be modified. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.addTransform = function(from, to, method) { │ │ │ │ │ - if (method === OpenLayers.Projection.nullTransform) { │ │ │ │ │ - var defaults = OpenLayers.Projection.defaults[from]; │ │ │ │ │ - if (defaults && !OpenLayers.Projection.defaults[to]) { │ │ │ │ │ - OpenLayers.Projection.defaults[to] = defaults; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!OpenLayers.Projection.transforms[from]) { │ │ │ │ │ - OpenLayers.Projection.transforms[from] = {}; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Projection.transforms[from][to] = method; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Transform a point coordinate from one projection to another. Note that │ │ │ │ │ - * the input point is transformed in place. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - { | Object} An object with x and y │ │ │ │ │ - * properties representing coordinates in those dimensions. │ │ │ │ │ - * source - {OpenLayers.Projection} Source map coordinate system │ │ │ │ │ - * dest - {OpenLayers.Projection} Destination map coordinate system │ │ │ │ │ + * seg1 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ + * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ + * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ + * seg2 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ + * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ + * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ + * options - {Object} Optional properties for calculating the intersection. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * point - {Boolean} Return the intersection point. If false, the actual │ │ │ │ │ + * intersection point will not be calculated. If true and the segments │ │ │ │ │ + * intersect, the intersection point will be returned. If true and │ │ │ │ │ + * the segments do not intersect, false will be returned. If true and │ │ │ │ │ + * the segments are coincident, true will be returned. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, if the segments are │ │ │ │ │ + * within the tolerance distance, this will be considered an intersection. │ │ │ │ │ + * In addition, if the point option is true and the calculated intersection │ │ │ │ │ + * is within the tolerance distance of an end point, the endpoint will be │ │ │ │ │ + * returned instead of the calculated intersection. Further, if the │ │ │ │ │ + * intersection is within the tolerance of endpoints on both segments, or │ │ │ │ │ + * if two segment endpoints are within the tolerance distance of eachother │ │ │ │ │ + * (but no intersection is otherwise calculated), an endpoint on the │ │ │ │ │ + * first segment provided will be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * point - {object} A transformed coordinate. The original point is modified. │ │ │ │ │ + * {Boolean | } The two segments intersect. │ │ │ │ │ + * If the point argument is true, the return will be the intersection │ │ │ │ │ + * point or false if none exists. If point is true and the segments │ │ │ │ │ + * are coincident, return will be true (and the instersection is equal │ │ │ │ │ + * to the shorter segment). │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Projection.transform = function(point, source, dest) { │ │ │ │ │ - if (source && dest) { │ │ │ │ │ - if (!(source instanceof OpenLayers.Projection)) { │ │ │ │ │ - source = new OpenLayers.Projection(source); │ │ │ │ │ +OpenLayers.Geometry.segmentsIntersect = function(seg1, seg2, options) { │ │ │ │ │ + var point = options && options.point; │ │ │ │ │ + var tolerance = options && options.tolerance; │ │ │ │ │ + var intersection = false; │ │ │ │ │ + var x11_21 = seg1.x1 - seg2.x1; │ │ │ │ │ + var y11_21 = seg1.y1 - seg2.y1; │ │ │ │ │ + var x12_11 = seg1.x2 - seg1.x1; │ │ │ │ │ + var y12_11 = seg1.y2 - seg1.y1; │ │ │ │ │ + var y22_21 = seg2.y2 - seg2.y1; │ │ │ │ │ + var x22_21 = seg2.x2 - seg2.x1; │ │ │ │ │ + var d = (y22_21 * x12_11) - (x22_21 * y12_11); │ │ │ │ │ + var n1 = (x22_21 * y11_21) - (y22_21 * x11_21); │ │ │ │ │ + var n2 = (x12_11 * y11_21) - (y12_11 * x11_21); │ │ │ │ │ + if (d == 0) { │ │ │ │ │ + // parallel │ │ │ │ │ + if (n1 == 0 && n2 == 0) { │ │ │ │ │ + // coincident │ │ │ │ │ + intersection = true; │ │ │ │ │ } │ │ │ │ │ - if (!(dest instanceof OpenLayers.Projection)) { │ │ │ │ │ - dest = new OpenLayers.Projection(dest); │ │ │ │ │ + } else { │ │ │ │ │ + var along1 = n1 / d; │ │ │ │ │ + var along2 = n2 / d; │ │ │ │ │ + if (along1 >= 0 && along1 <= 1 && along2 >= 0 && along2 <= 1) { │ │ │ │ │ + // intersect │ │ │ │ │ + if (!point) { │ │ │ │ │ + intersection = true; │ │ │ │ │ + } else { │ │ │ │ │ + // calculate the intersection point │ │ │ │ │ + var x = seg1.x1 + (along1 * x12_11); │ │ │ │ │ + var y = seg1.y1 + (along1 * y12_11); │ │ │ │ │ + intersection = new OpenLayers.Geometry.Point(x, y); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (source.proj && dest.proj) { │ │ │ │ │ - point = Proj4js.transform(source.proj, dest.proj, point); │ │ │ │ │ + } │ │ │ │ │ + if (tolerance) { │ │ │ │ │ + var dist; │ │ │ │ │ + if (intersection) { │ │ │ │ │ + if (point) { │ │ │ │ │ + var segs = [seg1, seg2]; │ │ │ │ │ + var seg, x, y; │ │ │ │ │ + // check segment endpoints for proximity to intersection │ │ │ │ │ + // set intersection to first endpoint within the tolerance │ │ │ │ │ + outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ + seg = segs[i]; │ │ │ │ │ + for (var j = 1; j < 3; ++j) { │ │ │ │ │ + x = seg["x" + j]; │ │ │ │ │ + y = seg["y" + j]; │ │ │ │ │ + dist = Math.sqrt( │ │ │ │ │ + Math.pow(x - intersection.x, 2) + │ │ │ │ │ + Math.pow(y - intersection.y, 2) │ │ │ │ │ + ); │ │ │ │ │ + if (dist < tolerance) { │ │ │ │ │ + intersection.x = x; │ │ │ │ │ + intersection.y = y; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ } else { │ │ │ │ │ - var sourceCode = source.getCode(); │ │ │ │ │ - var destCode = dest.getCode(); │ │ │ │ │ - var transforms = OpenLayers.Projection.transforms; │ │ │ │ │ - if (transforms[sourceCode] && transforms[sourceCode][destCode]) { │ │ │ │ │ - transforms[sourceCode][destCode](point); │ │ │ │ │ + // no calculated intersection, but segments could be within │ │ │ │ │ + // the tolerance of one another │ │ │ │ │ + var segs = [seg1, seg2]; │ │ │ │ │ + var source, target, x, y, p, result; │ │ │ │ │ + // check segment endpoints for proximity to intersection │ │ │ │ │ + // set intersection to first endpoint within the tolerance │ │ │ │ │ + outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ + source = segs[i]; │ │ │ │ │ + target = segs[(i + 1) % 2]; │ │ │ │ │ + for (var j = 1; j < 3; ++j) { │ │ │ │ │ + p = { │ │ │ │ │ + x: source["x" + j], │ │ │ │ │ + y: source["y" + j] │ │ │ │ │ + }; │ │ │ │ │ + result = OpenLayers.Geometry.distanceToSegment(p, target); │ │ │ │ │ + if (result.distance < tolerance) { │ │ │ │ │ + if (point) { │ │ │ │ │ + intersection = new OpenLayers.Geometry.Point(p.x, p.y); │ │ │ │ │ + } else { │ │ │ │ │ + intersection = true; │ │ │ │ │ + } │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return point; │ │ │ │ │ + return intersection; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: nullTransform │ │ │ │ │ - * A null transformation - useful for defining projection aliases when │ │ │ │ │ - * proj4js is not available: │ │ │ │ │ + * Function: OpenLayers.Geometry.distanceToSegment │ │ │ │ │ * │ │ │ │ │ - * (code) │ │ │ │ │ - * OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913", │ │ │ │ │ - * OpenLayers.Projection.nullTransform); │ │ │ │ │ - * OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857", │ │ │ │ │ - * OpenLayers.Projection.nullTransform); │ │ │ │ │ - * (end) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {Object} An object with x and y properties representing the │ │ │ │ │ + * point coordinates. │ │ │ │ │ + * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ + * representing endpoint coordinates. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object with distance, along, x, and y properties. The distance │ │ │ │ │ + * will be the shortest distance between the input point and segment. │ │ │ │ │ + * The x and y properties represent the coordinates along the segment │ │ │ │ │ + * where the shortest distance meets the segment. The along attribute │ │ │ │ │ + * describes how far between the two segment points the given point is. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Projection.nullTransform = function(point) { │ │ │ │ │ - return point; │ │ │ │ │ +OpenLayers.Geometry.distanceToSegment = function(point, segment) { │ │ │ │ │ + var result = OpenLayers.Geometry.distanceSquaredToSegment(point, segment); │ │ │ │ │ + result.distance = Math.sqrt(result.distance); │ │ │ │ │ + return result; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Note: Transforms for web mercator <-> geographic │ │ │ │ │ - * OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100. │ │ │ │ │ - * OpenLayers originally started referring to EPSG:900913 as web mercator. │ │ │ │ │ - * The EPSG has declared EPSG:3857 to be web mercator. │ │ │ │ │ - * ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as │ │ │ │ │ - * equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084. │ │ │ │ │ - * For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and │ │ │ │ │ - * urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis │ │ │ │ │ - * order for EPSG:4326. │ │ │ │ │ + * Function: OpenLayers.Geometry.distanceSquaredToSegment │ │ │ │ │ + * │ │ │ │ │ + * Usually the distanceToSegment function should be used. This variant however │ │ │ │ │ + * can be used for comparisons where the exact distance is not important. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {Object} An object with x and y properties representing the │ │ │ │ │ + * point coordinates. │ │ │ │ │ + * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ + * representing endpoint coordinates. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object with squared distance, along, x, and y properties. │ │ │ │ │ + * The distance will be the shortest distance between the input point and │ │ │ │ │ + * segment. The x and y properties represent the coordinates along the │ │ │ │ │ + * segment where the shortest distance meets the segment. The along │ │ │ │ │ + * attribute describes how far between the two segment points the given │ │ │ │ │ + * point is. │ │ │ │ │ */ │ │ │ │ │ -(function() { │ │ │ │ │ - │ │ │ │ │ - var pole = 20037508.34; │ │ │ │ │ - │ │ │ │ │ - function inverseMercator(xy) { │ │ │ │ │ - xy.x = 180 * xy.x / pole; │ │ │ │ │ - xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2); │ │ │ │ │ - return xy; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - function forwardMercator(xy) { │ │ │ │ │ - xy.x = xy.x * pole / 180; │ │ │ │ │ - var y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole; │ │ │ │ │ - xy.y = Math.max(-20037508.34, Math.min(y, 20037508.34)); │ │ │ │ │ - return xy; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - function map(base, codes) { │ │ │ │ │ - var add = OpenLayers.Projection.addTransform; │ │ │ │ │ - var same = OpenLayers.Projection.nullTransform; │ │ │ │ │ - var i, len, code, other, j; │ │ │ │ │ - for (i = 0, len = codes.length; i < len; ++i) { │ │ │ │ │ - code = codes[i]; │ │ │ │ │ - add(base, code, forwardMercator); │ │ │ │ │ - add(code, base, inverseMercator); │ │ │ │ │ - for (j = i + 1; j < len; ++j) { │ │ │ │ │ - other = codes[j]; │ │ │ │ │ - add(code, other, same); │ │ │ │ │ - add(other, code, same); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // list of equivalent codes for web mercator │ │ │ │ │ - var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"], │ │ │ │ │ - geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"], │ │ │ │ │ - i; │ │ │ │ │ - for (i = mercator.length - 1; i >= 0; --i) { │ │ │ │ │ - map(mercator[i], geographic); │ │ │ │ │ - } │ │ │ │ │ - for (i = geographic.length - 1; i >= 0; --i) { │ │ │ │ │ - map(geographic[i], mercator); │ │ │ │ │ +OpenLayers.Geometry.distanceSquaredToSegment = function(point, segment) { │ │ │ │ │ + var x0 = point.x; │ │ │ │ │ + var y0 = point.y; │ │ │ │ │ + var x1 = segment.x1; │ │ │ │ │ + var y1 = segment.y1; │ │ │ │ │ + var x2 = segment.x2; │ │ │ │ │ + var y2 = segment.y2; │ │ │ │ │ + var dx = x2 - x1; │ │ │ │ │ + var dy = y2 - y1; │ │ │ │ │ + var along = ((dx * (x0 - x1)) + (dy * (y0 - y1))) / │ │ │ │ │ + (Math.pow(dx, 2) + Math.pow(dy, 2)); │ │ │ │ │ + var x, y; │ │ │ │ │ + if (along <= 0.0) { │ │ │ │ │ + x = x1; │ │ │ │ │ + y = y1; │ │ │ │ │ + } else if (along >= 1.0) { │ │ │ │ │ + x = x2; │ │ │ │ │ + y = y2; │ │ │ │ │ + } else { │ │ │ │ │ + x = x1 + along * dx; │ │ │ │ │ + y = y1 + along * dy; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ -})(); │ │ │ │ │ + return { │ │ │ │ │ + distance: Math.pow(x - x0, 2) + Math.pow(y - y0, 2), │ │ │ │ │ + x: x, │ │ │ │ │ + y: y, │ │ │ │ │ + along: along │ │ │ │ │ + }; │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Map.js │ │ │ │ │ + OpenLayers/Format.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Tween.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Map │ │ │ │ │ - * Instances of OpenLayers.Map are interactive maps embedded in a web page. │ │ │ │ │ - * Create a new map with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * On their own maps do not provide much functionality. To extend a map │ │ │ │ │ - * it's necessary to add controls () and │ │ │ │ │ - * layers () to the map. │ │ │ │ │ + * Class: OpenLayers.Format │ │ │ │ │ + * Base class for format reading/writing a variety of formats. Subclasses │ │ │ │ │ + * of OpenLayers.Format are expected to have read and write methods. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Map = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: Z_INDEX_BASE │ │ │ │ │ - * {Object} Base z-indexes for different classes of thing │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} A reference to options passed to the constructor. │ │ │ │ │ */ │ │ │ │ │ - Z_INDEX_BASE: { │ │ │ │ │ - BaseLayer: 100, │ │ │ │ │ - Overlay: 325, │ │ │ │ │ - Feature: 725, │ │ │ │ │ - Popup: 750, │ │ │ │ │ - Control: 1000 │ │ │ │ │ - }, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * map.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to map.events.object. │ │ │ │ │ - * element - {DOMElement} A reference to map.events.element. │ │ │ │ │ - * │ │ │ │ │ - * Browser events have the following additional properties: │ │ │ │ │ - * xy - {} The pixel location of the event (relative │ │ │ │ │ - * to the the map viewport). │ │ │ │ │ - * │ │ │ │ │ - * Supported map event types: │ │ │ │ │ - * preaddlayer - triggered before a layer has been added. The event │ │ │ │ │ - * object will include a *layer* property that references the layer │ │ │ │ │ - * to be added. When a listener returns "false" the adding will be │ │ │ │ │ - * aborted. │ │ │ │ │ - * addlayer - triggered after a layer has been added. The event object │ │ │ │ │ - * will include a *layer* property that references the added layer. │ │ │ │ │ - * preremovelayer - triggered before a layer has been removed. The event │ │ │ │ │ - * object will include a *layer* property that references the layer │ │ │ │ │ - * to be removed. When a listener returns "false" the removal will be │ │ │ │ │ - * aborted. │ │ │ │ │ - * removelayer - triggered after a layer has been removed. The event │ │ │ │ │ - * object will include a *layer* property that references the removed │ │ │ │ │ - * layer. │ │ │ │ │ - * changelayer - triggered after a layer name change, order change, │ │ │ │ │ - * opacity change, params change, visibility change (actual visibility, │ │ │ │ │ - * not the layer's visibility property) or attribution change (due to │ │ │ │ │ - * extent change). Listeners will receive an event object with *layer* │ │ │ │ │ - * and *property* properties. The *layer* property will be a reference │ │ │ │ │ - * to the changed layer. The *property* property will be a key to the │ │ │ │ │ - * changed property (name, order, opacity, params, visibility or │ │ │ │ │ - * attribution). │ │ │ │ │ - * movestart - triggered after the start of a drag, pan, or zoom. The event │ │ │ │ │ - * object may include a *zoomChanged* property that tells whether the │ │ │ │ │ - * zoom has changed. │ │ │ │ │ - * move - triggered after each drag, pan, or zoom │ │ │ │ │ - * moveend - triggered after a drag, pan, or zoom completes │ │ │ │ │ - * zoomend - triggered after a zoom completes │ │ │ │ │ - * mouseover - triggered after mouseover the map │ │ │ │ │ - * mouseout - triggered after mouseout the map │ │ │ │ │ - * mousemove - triggered after mousemove the map │ │ │ │ │ - * changebaselayer - triggered after the base layer changes │ │ │ │ │ - * updatesize - triggered after the method was executed │ │ │ │ │ + * APIProperty: externalProjection │ │ │ │ │ + * {} When passed a externalProjection and │ │ │ │ │ + * internalProjection, the format will reproject the geometries it │ │ │ │ │ + * reads or writes. The externalProjection is the projection used by │ │ │ │ │ + * the content which is passed into read or which comes out of write. │ │ │ │ │ + * In order to reproject, a projection transformation function for the │ │ │ │ │ + * specified projections must be available. This support may be │ │ │ │ │ + * provided via proj4js or via a custom transformation function. See │ │ │ │ │ + * {} for more information on │ │ │ │ │ + * custom transformations. │ │ │ │ │ */ │ │ │ │ │ + externalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} Unique identifier for the map │ │ │ │ │ + * APIProperty: internalProjection │ │ │ │ │ + * {} When passed a externalProjection and │ │ │ │ │ + * internalProjection, the format will reproject the geometries it │ │ │ │ │ + * reads or writes. The internalProjection is the projection used by │ │ │ │ │ + * the geometries which are returned by read or which are passed into │ │ │ │ │ + * write. In order to reproject, a projection transformation function │ │ │ │ │ + * for the specified projections must be available. This support may be │ │ │ │ │ + * provided via proj4js or via a custom transformation function. See │ │ │ │ │ + * {} for more information on │ │ │ │ │ + * custom transformations. │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + internalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: fractionalZoom │ │ │ │ │ - * {Boolean} For a base layer that supports it, allow the map resolution │ │ │ │ │ - * to be set to a value between one of the values in the resolutions │ │ │ │ │ - * array. Default is false. │ │ │ │ │ - * │ │ │ │ │ - * When fractionalZoom is set to true, it is possible to zoom to │ │ │ │ │ - * an arbitrary extent. This requires a base layer from a source │ │ │ │ │ - * that supports requests for arbitrary extents (i.e. not cached │ │ │ │ │ - * tiles on a regular lattice). This means that fractionalZoom │ │ │ │ │ - * will not work with commercial layers (Google, Yahoo, VE), layers │ │ │ │ │ - * using TileCache, or any other pre-cached data sources. │ │ │ │ │ - * │ │ │ │ │ - * If you are using fractionalZoom, then you should also use │ │ │ │ │ - * instead of layer.resolutions[zoom] as the │ │ │ │ │ - * former works for non-integer zoom levels. │ │ │ │ │ + * APIProperty: data │ │ │ │ │ + * {Object} When is true, this is the parsed string sent to │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - fractionalZoom: false, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the map │ │ │ │ │ + * APIProperty: keepData │ │ │ │ │ + * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + keepData: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: allOverlays │ │ │ │ │ - * {Boolean} Allow the map to function with "overlays" only. Defaults to │ │ │ │ │ - * false. If true, the lowest layer in the draw order will act as │ │ │ │ │ - * the base layer. In addition, if set to true, all layers will │ │ │ │ │ - * have isBaseLayer set to false when they are added to the map. │ │ │ │ │ + * Constructor: OpenLayers.Format │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you set map.allOverlays to true, then you *cannot* use │ │ │ │ │ - * map.setBaseLayer or layer.setIsBaseLayer. With allOverlays true, │ │ │ │ │ - * the lowest layer in the draw layer is the base layer. So, to change │ │ │ │ │ - * the base layer, use or to set the layer │ │ │ │ │ - * index to 0. │ │ │ │ │ - */ │ │ │ │ │ - allOverlays: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement|String} The element that contains the map (or an id for │ │ │ │ │ - * that element). If the constructor is called │ │ │ │ │ - * with two arguments, this should be provided as the first argument. │ │ │ │ │ - * Alternatively, the map constructor can be called with the options │ │ │ │ │ - * object as the only argument. In this case (one argument), a │ │ │ │ │ - * div property may or may not be provided. If the div property │ │ │ │ │ - * is not provided, the map can be rendered to a container later │ │ │ │ │ - * using the method. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you are calling after map construction, do not use │ │ │ │ │ - * auto. Instead, divide your by your │ │ │ │ │ - * maximum expected dimension. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} The map is currently being dragged. │ │ │ │ │ - */ │ │ │ │ │ - dragging: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} Size of the main div (this.div) │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: viewPortDiv │ │ │ │ │ - * {HTMLDivElement} The element that represents the map viewport │ │ │ │ │ - */ │ │ │ │ │ - viewPortDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerOrigin │ │ │ │ │ - * {} The lonlat at which the later container was │ │ │ │ │ - * re-initialized (on-zoom) │ │ │ │ │ - */ │ │ │ │ │ - layerContainerOrigin: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerDiv │ │ │ │ │ - * {HTMLDivElement} The element that contains the layers. │ │ │ │ │ - */ │ │ │ │ │ - layerContainerDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} Ordered list of layers in the map │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: controls │ │ │ │ │ - * {Array()} List of controls associated with the map. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * format │ │ │ │ │ * │ │ │ │ │ - * If not provided in the map options at construction, the map will │ │ │ │ │ - * by default be given the following controls if present in the build: │ │ │ │ │ - * - or │ │ │ │ │ - * - or │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ - controls: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: popups │ │ │ │ │ - * {Array()} List of popups associated with the map │ │ │ │ │ - */ │ │ │ │ │ - popups: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: baseLayer │ │ │ │ │ - * {} The currently selected base layer. This determines │ │ │ │ │ - * min/max zoom level, projection, etc. │ │ │ │ │ - */ │ │ │ │ │ - baseLayer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: center │ │ │ │ │ - * {} The current center of the map │ │ │ │ │ - */ │ │ │ │ │ - center: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The resolution of the map. │ │ │ │ │ - */ │ │ │ │ │ - resolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoom │ │ │ │ │ - * {Integer} The current zoom level of the map │ │ │ │ │ - */ │ │ │ │ │ - zoom: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panRatio │ │ │ │ │ - * {Float} The ratio of the current extent within │ │ │ │ │ - * which panning will tween. │ │ │ │ │ - */ │ │ │ │ │ - panRatio: 1.5, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: options │ │ │ │ │ - * {Object} The options object passed to the class constructor. Read-only. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - // Options │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileSize │ │ │ │ │ - * {} Set in the map options to override the default tile │ │ │ │ │ - * size for this map. │ │ │ │ │ - */ │ │ │ │ │ - tileSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: projection │ │ │ │ │ - * {String} Set in the map options to specify the default projection │ │ │ │ │ - * for layers added to this map. When using a projection other than EPSG:4326 │ │ │ │ │ - * (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), │ │ │ │ │ - * also set maxExtent, maxResolution or resolutions. Default is "EPSG:4326". │ │ │ │ │ - * Note that the projection of the map is usually determined │ │ │ │ │ - * by that of the current baseLayer (see and ). │ │ │ │ │ - */ │ │ │ │ │ - projection: "EPSG:4326", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: units │ │ │ │ │ - * {String} The map units. Possible values are 'degrees' (or 'dd'), 'm', │ │ │ │ │ - * 'ft', 'km', 'mi', 'inches'. Normally taken from the projection. │ │ │ │ │ - * Only required if both map and layers do not define a projection, │ │ │ │ │ - * or if they define a projection which does not define units │ │ │ │ │ - */ │ │ │ │ │ - units: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: resolutions │ │ │ │ │ - * {Array(Float)} A list of map resolutions (map units per pixel) in │ │ │ │ │ - * descending order. If this is not set in the layer constructor, it │ │ │ │ │ - * will be set based on other resolution related properties │ │ │ │ │ - * (maxExtent, maxResolution, maxScale, etc.). │ │ │ │ │ - */ │ │ │ │ │ - resolutions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxResolution │ │ │ │ │ - * {Float} Required if you are not displaying the whole world on a tile │ │ │ │ │ - * with the size specified in . │ │ │ │ │ - */ │ │ │ │ │ - maxResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ + * Valid options: │ │ │ │ │ + * keepData - {Boolean} If true, upon , the data property will be │ │ │ │ │ + * set to the parsed object (e.g. the json or xml object). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * An instance of OpenLayers.Format │ │ │ │ │ */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.options = options; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ + * Method: read │ │ │ │ │ + * Read data from a string, and return an object whose type depends on the │ │ │ │ │ + * subclass. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {string} Data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * Depends on the subclass │ │ │ │ │ */ │ │ │ │ │ - minScale: null, │ │ │ │ │ + read: function(data) { │ │ │ │ │ + throw new Error('Read not implemented.'); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The maximum extent for the map. │ │ │ │ │ - * Default depends on projection; if this is one of those defined in OpenLayers.Projection.defaults │ │ │ │ │ - * (EPSG:4326 or web mercator), maxExtent will be set to the value defined there; │ │ │ │ │ - * else, defaults to null. │ │ │ │ │ - * To restrict user panning and zooming of the map, use instead. │ │ │ │ │ - * The value for will change calculations for tile URLs. │ │ │ │ │ + * Method: write │ │ │ │ │ + * Accept an object, and return a string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} Object to be serialized │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representation of the object. │ │ │ │ │ */ │ │ │ │ │ - maxExtent: null, │ │ │ │ │ + write: function(object) { │ │ │ │ │ + throw new Error('Write not implemented.'); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The minimum extent for the map. Defaults to null. │ │ │ │ │ - */ │ │ │ │ │ - minExtent: null, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Point.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: restrictedExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * Limit map navigation to this extent where possible. │ │ │ │ │ - * If a non-null restrictedExtent is set, panning will be restricted │ │ │ │ │ - * to the given bounds. In addition, zooming to a resolution that │ │ │ │ │ - * displays more than the restricted extent will center the map │ │ │ │ │ - * on the restricted extent. If you wish to limit the zoom level │ │ │ │ │ - * or resolution, use maxResolution. │ │ │ │ │ - */ │ │ │ │ │ - restrictedExtent: null, │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} Number of zoom levels for the map. Defaults to 16. Set a │ │ │ │ │ - * different value in the map options if needed. │ │ │ │ │ - */ │ │ │ │ │ - numZoomLevels: 16, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: theme │ │ │ │ │ - * {String} Relative path to a CSS file from which to load theme styles. │ │ │ │ │ - * Specify null in the map options (e.g. {theme: null}) if you │ │ │ │ │ - * want to get cascading style declarations - by putting links to │ │ │ │ │ - * stylesheets or style declarations directly in your page. │ │ │ │ │ - */ │ │ │ │ │ - theme: null, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Point │ │ │ │ │ + * Point geometry class. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} Requires proj4js support for projections other │ │ │ │ │ - * than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by │ │ │ │ │ - * several controls to display data to user. If this property is set, │ │ │ │ │ - * it will be set on any control which has a null displayProjection │ │ │ │ │ - * property at the time the control is added to the map. │ │ │ │ │ - */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileManager │ │ │ │ │ - * {|Object} By default, and if the build contains │ │ │ │ │ - * TileManager.js, the map will use the TileManager to queue image requests │ │ │ │ │ - * and to cache tile image elements. To create a map without a TileManager │ │ │ │ │ - * configure the map with tileManager: null. To create a TileManager with │ │ │ │ │ - * non-default options, supply the options instead or alternatively supply │ │ │ │ │ - * an instance of {}. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fallThrough │ │ │ │ │ - * {Boolean} Should OpenLayers allow events on the map to fall through to │ │ │ │ │ - * other elements on the page, or should it swallow them? (#457) │ │ │ │ │ - * Default is to swallow. │ │ │ │ │ - */ │ │ │ │ │ - fallThrough: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoUpdateSize │ │ │ │ │ - * {Boolean} Should OpenLayers automatically update the size of the map │ │ │ │ │ - * when the resize event is fired. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - autoUpdateSize: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panTween │ │ │ │ │ - * {} Animated panning tween object, see panTo() │ │ │ │ │ - */ │ │ │ │ │ - panTween: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: panMethod │ │ │ │ │ - * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ - * OpenLayers.Easing.Expo.easeOut. Setting this to 'null' turns off │ │ │ │ │ - * animated panning. │ │ │ │ │ - */ │ │ │ │ │ - panMethod: OpenLayers.Easing.Expo.easeOut, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panDuration │ │ │ │ │ - * {Integer} The number of steps to be passed to the │ │ │ │ │ - * OpenLayers.Tween.start() method when the map is │ │ │ │ │ - * panned. │ │ │ │ │ - * Default is 50. │ │ │ │ │ + * APIProperty: x │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - panDuration: 50, │ │ │ │ │ + x: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomTween │ │ │ │ │ - * {} Animated zooming tween object, see zoomTo() │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: y │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - zoomTween: null, │ │ │ │ │ + y: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomMethod │ │ │ │ │ - * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ - * OpenLayers.Easing.Quad.easeOut. Setting this to 'null' turns off │ │ │ │ │ - * animated zooming. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ + * Construct a point geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {float} │ │ │ │ │ + * y - {float} │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - zoomMethod: OpenLayers.Easing.Quad.easeOut, │ │ │ │ │ + initialize: function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomDuration │ │ │ │ │ - * {Integer} The number of steps to be passed to the │ │ │ │ │ - * OpenLayers.Tween.start() method when the map is zoomed. │ │ │ │ │ - * Default is 20. │ │ │ │ │ - */ │ │ │ │ │ - zoomDuration: 20, │ │ │ │ │ + this.x = parseFloat(x); │ │ │ │ │ + this.y = parseFloat(y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: paddingForPopups │ │ │ │ │ - * {} Outside margin of the popup. Used to prevent │ │ │ │ │ - * the popup from getting too close to the map border. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ */ │ │ │ │ │ - paddingForPopups: null, │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerOriginPx │ │ │ │ │ - * {Object} Cached object representing the layer container origin (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - layerContainerOriginPx: null, │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: minPx │ │ │ │ │ - * {Object} An object with a 'x' and 'y' values that is the lower │ │ │ │ │ - * left of maxExtent in viewport pixel space. │ │ │ │ │ - * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ - * is valid. It is also used in the getLonLatFromViewPortPx function │ │ │ │ │ - * of Layer. │ │ │ │ │ - */ │ │ │ │ │ - minPx: null, │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: maxPx │ │ │ │ │ - * {Object} An object with a 'x' and 'y' values that is the top │ │ │ │ │ - * right of maxExtent in viewport pixel space. │ │ │ │ │ - * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ - * is valid. │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * Create a new Bounds based on the lon/lat │ │ │ │ │ */ │ │ │ │ │ - maxPx: null, │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ + this.x, this.y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Map │ │ │ │ │ - * Constructor for a new OpenLayers.Map instance. There are two possible │ │ │ │ │ - * ways to call the map constructor. See the examples below. │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * div - {DOMElement|String} The element or id of an element in your page │ │ │ │ │ - * that will contain the map. May be omitted if the
option is │ │ │ │ │ - * provided or if you intend to call the method later. │ │ │ │ │ - * options - {Object} Optional object with properties to tag onto the map. │ │ │ │ │ - * │ │ │ │ │ - * Valid options (in addition to the listed API properties): │ │ │ │ │ - * center - {|Array} The default initial center of the map. │ │ │ │ │ - * If provided as array, the first value is the x coordinate, │ │ │ │ │ - * and the 2nd value is the y coordinate. │ │ │ │ │ - * Only specify if is provided. │ │ │ │ │ - * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ - * and the querystring contains coordinates, center will be set │ │ │ │ │ - * by that, and this option will be ignored. │ │ │ │ │ - * zoom - {Number} The initial zoom level for the map. Only specify if │ │ │ │ │ - * is provided. │ │ │ │ │ - * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ - * and the querystring contains a zoom level, zoom will be set │ │ │ │ │ - * by that, and this option will be ignored. │ │ │ │ │ - * extent - {|Array} The initial extent of the map. │ │ │ │ │ - * If provided as an array, the array should consist of │ │ │ │ │ - * four values (left, bottom, right, top). │ │ │ │ │ - * Only specify if
and are not provided. │ │ │ │ │ - * │ │ │ │ │ - * Examples: │ │ │ │ │ - * (code) │ │ │ │ │ - * // create a map with default options in an element with the id "map1" │ │ │ │ │ - * var map = new OpenLayers.Map("map1"); │ │ │ │ │ - * │ │ │ │ │ - * // create a map with non-default options in an element with id "map2" │ │ │ │ │ - * var options = { │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000), │ │ │ │ │ - * center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095) │ │ │ │ │ - * }; │ │ │ │ │ - * var map = new OpenLayers.Map("map2", options); │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ * │ │ │ │ │ - * // map with non-default options - same as above but with a single argument, │ │ │ │ │ - * // a restricted extent, and using arrays for bounds and center │ │ │ │ │ - * var map = new OpenLayers.Map({ │ │ │ │ │ - * div: "map_id", │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146], │ │ │ │ │ - * restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962], │ │ │ │ │ - * center: [-12356463.476333, 5621521.4854095] │ │ │ │ │ - * }); │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ * │ │ │ │ │ - * // create a map without a reference to a container - call render later │ │ │ │ │ - * var map = new OpenLayers.Map({ │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000) │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(div, options) { │ │ │ │ │ - │ │ │ │ │ - // If only one argument is provided, check if it is an object. │ │ │ │ │ - if (arguments.length === 1 && typeof div === "object") { │ │ │ │ │ - options = div; │ │ │ │ │ - div = options && options.div; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // Simple-type defaults are set in class definition. │ │ │ │ │ - // Now set complex-type defaults │ │ │ │ │ - this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH, │ │ │ │ │ - OpenLayers.Map.TILE_HEIGHT); │ │ │ │ │ - │ │ │ │ │ - this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15); │ │ │ │ │ - │ │ │ │ │ - this.theme = OpenLayers._getScriptLocation() + │ │ │ │ │ - 'theme/default/style.css'; │ │ │ │ │ - │ │ │ │ │ - // backup original options │ │ │ │ │ - this.options = OpenLayers.Util.extend({}, options); │ │ │ │ │ - │ │ │ │ │ - // now override default options │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - │ │ │ │ │ - var projCode = this.projection instanceof OpenLayers.Projection ? │ │ │ │ │ - this.projection.projCode : this.projection; │ │ │ │ │ - OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]); │ │ │ │ │ - │ │ │ │ │ - // allow extents and center to be arrays │ │ │ │ │ - if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.maxExtent = new OpenLayers.Bounds(this.maxExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.minExtent && !(this.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.minExtent = new OpenLayers.Bounds(this.minExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.restrictedExtent && !(this.restrictedExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.restrictedExtent = new OpenLayers.Bounds(this.restrictedExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.center && !(this.center instanceof OpenLayers.LonLat)) { │ │ │ │ │ - this.center = new OpenLayers.LonLat(this.center); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // initialize layers array │ │ │ │ │ - this.layers = []; │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID("OpenLayers.Map_"); │ │ │ │ │ - │ │ │ │ │ - this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ - if (!this.div) { │ │ │ │ │ - this.div = document.createElement("div"); │ │ │ │ │ - this.div.style.height = "1px"; │ │ │ │ │ - this.div.style.width = "1px"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ - │ │ │ │ │ - // the viewPortDiv is the outermost div we modify │ │ │ │ │ - var id = this.id + "_OpenLayers_ViewPort"; │ │ │ │ │ - this.viewPortDiv = OpenLayers.Util.createDiv(id, null, null, null, │ │ │ │ │ - "relative", null, │ │ │ │ │ - "hidden"); │ │ │ │ │ - this.viewPortDiv.style.width = "100%"; │ │ │ │ │ - this.viewPortDiv.style.height = "100%"; │ │ │ │ │ - this.viewPortDiv.className = "olMapViewport"; │ │ │ │ │ - this.div.appendChild(this.viewPortDiv); │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events( │ │ │ │ │ - this, this.viewPortDiv, null, this.fallThrough, { │ │ │ │ │ - includeXY: true │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.TileManager && this.tileManager !== null) { │ │ │ │ │ - if (!(this.tileManager instanceof OpenLayers.TileManager)) { │ │ │ │ │ - this.tileManager = new OpenLayers.TileManager(this.tileManager); │ │ │ │ │ - } │ │ │ │ │ - this.tileManager.addMap(this); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // the layerContainerDiv is the one that holds all the layers │ │ │ │ │ - id = this.id + "_OpenLayers_Container"; │ │ │ │ │ - this.layerContainerDiv = OpenLayers.Util.createDiv(id); │ │ │ │ │ - this.layerContainerDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] - 1; │ │ │ │ │ - this.layerContainerOriginPx = { │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }; │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - │ │ │ │ │ - this.viewPortDiv.appendChild(this.layerContainerDiv); │ │ │ │ │ - │ │ │ │ │ - this.updateSize(); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.autoUpdateSize === true) { │ │ │ │ │ - // updateSize on catching the window's resize │ │ │ │ │ - // Note that this is ok, as updateSize() does nothing if the │ │ │ │ │ - // map's size has not actually changed. │ │ │ │ │ - this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize, │ │ │ │ │ - this); │ │ │ │ │ - OpenLayers.Event.observe(window, 'resize', │ │ │ │ │ - this.updateSizeDestroy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // only append link stylesheet if the theme property is set │ │ │ │ │ - if (this.theme) { │ │ │ │ │ - // check existing links for equivalent url │ │ │ │ │ - var addNode = true; │ │ │ │ │ - var nodes = document.getElementsByTagName('link'); │ │ │ │ │ - for (var i = 0, len = nodes.length; i < len; ++i) { │ │ │ │ │ - if (OpenLayers.Util.isEquivalentUrl(nodes.item(i).href, │ │ │ │ │ - this.theme)) { │ │ │ │ │ - addNode = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // only add a new node if one with an equivalent url hasn't already │ │ │ │ │ - // been added │ │ │ │ │ - if (addNode) { │ │ │ │ │ - var cssNode = document.createElement('link'); │ │ │ │ │ - cssNode.setAttribute('rel', 'stylesheet'); │ │ │ │ │ - cssNode.setAttribute('type', 'text/css'); │ │ │ │ │ - cssNode.setAttribute('href', this.theme); │ │ │ │ │ - document.getElementsByTagName('head')[0].appendChild(cssNode); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.controls == null) { // default controls │ │ │ │ │ - this.controls = []; │ │ │ │ │ - if (OpenLayers.Control != null) { // running full or lite? │ │ │ │ │ - // Navigation or TouchNavigation depending on what is in build │ │ │ │ │ - if (OpenLayers.Control.Navigation) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Navigation()); │ │ │ │ │ - } else if (OpenLayers.Control.TouchNavigation) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.TouchNavigation()); │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.Zoom) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Zoom()); │ │ │ │ │ - } else if (OpenLayers.Control.PanZoom) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.PanZoom()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.Control.ArgParser) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.ArgParser()); │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.Attribution) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Attribution()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - this.addControlToMap(this.controls[i]); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.popups = []; │ │ │ │ │ - │ │ │ │ │ - this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - // always call map.destroy() │ │ │ │ │ - OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); │ │ │ │ │ - │ │ │ │ │ - // add any initial layers │ │ │ │ │ - if (options && options.layers) { │ │ │ │ │ - /** │ │ │ │ │ - * If you have set options.center, the map center property will be │ │ │ │ │ - * set at this point. However, since setCenter has not been called, │ │ │ │ │ - * addLayers gets confused. So we delete the map center in this │ │ │ │ │ - * case. Because the check below uses options.center, it will │ │ │ │ │ - * be properly set below. │ │ │ │ │ - */ │ │ │ │ │ - delete this.center; │ │ │ │ │ - delete this.zoom; │ │ │ │ │ - this.addLayers(options.layers); │ │ │ │ │ - // set center (and optionally zoom) │ │ │ │ │ - if (options.center && !this.getCenter()) { │ │ │ │ │ - // zoom can be undefined here │ │ │ │ │ - this.setCenter(options.center, options.zoom); │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var distance, x0, y0, x1, y1, result; │ │ │ │ │ + if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + x0 = this.x; │ │ │ │ │ + y0 = this.y; │ │ │ │ │ + x1 = geometry.x; │ │ │ │ │ + y1 = geometry.y; │ │ │ │ │ + distance = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); │ │ │ │ │ + result = !details ? │ │ │ │ │ + distance : { │ │ │ │ │ + x0: x0, │ │ │ │ │ + y0: y0, │ │ │ │ │ + x1: x1, │ │ │ │ │ + y1: y1, │ │ │ │ │ + distance: distance │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + result = geometry.distanceTo(this, options); │ │ │ │ │ + if (details) { │ │ │ │ │ + // switch coord order since this geom is target │ │ │ │ │ + result = { │ │ │ │ │ + x0: result.x1, │ │ │ │ │ + y0: result.y1, │ │ │ │ │ + x1: result.x0, │ │ │ │ │ + y1: result.y0, │ │ │ │ │ + distance: result.distance │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (this.panMethod) { │ │ │ │ │ - this.panTween = new OpenLayers.Tween(this.panMethod); │ │ │ │ │ - } │ │ │ │ │ - if (this.zoomMethod && this.applyTransform.transform) { │ │ │ │ │ - this.zoomTween = new OpenLayers.Tween(this.zoomMethod); │ │ │ │ │ - } │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getViewport │ │ │ │ │ - * Get the DOMElement representing the view port. │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geom - {} The geometry to test. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - getViewport: function() { │ │ │ │ │ - return this.viewPortDiv; │ │ │ │ │ + equals: function(geom) { │ │ │ │ │ + var equals = false; │ │ │ │ │ + if (geom != null) { │ │ │ │ │ + equals = ((this.x == geom.x && this.y == geom.y) || │ │ │ │ │ + (isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y))); │ │ │ │ │ + } │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: render │ │ │ │ │ - * Render the map to a specified container. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * div - {String|DOMElement} The container that the map should be rendered │ │ │ │ │ - * to. If different than the current container, the map viewport │ │ │ │ │ - * will be moved from the current to the new container. │ │ │ │ │ + * Method: toShortString │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Shortened String representation of Point object. │ │ │ │ │ + * (ex. "5, 42") │ │ │ │ │ */ │ │ │ │ │ - render: function(div) { │ │ │ │ │ - this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ - OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ - this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ - this.div.appendChild(this.viewPortDiv); │ │ │ │ │ - this.updateSize(); │ │ │ │ │ + toShortString: function() { │ │ │ │ │ + return (this.x + ", " + this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unloadDestroy │ │ │ │ │ - * Function that is called to destroy the map on page unload. stored here │ │ │ │ │ - * so that if map is manually destroyed, we can unregister this. │ │ │ │ │ - */ │ │ │ │ │ - unloadDestroy: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateSizeDestroy │ │ │ │ │ - * When the map is destroyed, we need to stop listening to updateSize │ │ │ │ │ - * events: this method stores the function we need to unregister in │ │ │ │ │ - * non-IE browsers. │ │ │ │ │ - */ │ │ │ │ │ - updateSizeDestroy: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this map. │ │ │ │ │ - * Note that if you are using an application which removes a container │ │ │ │ │ - * of the map from the DOM, you need to ensure that you destroy the │ │ │ │ │ - * map *before* this happens; otherwise, the page unload handler │ │ │ │ │ - * will fail because the DOM elements that map.destroy() wants │ │ │ │ │ - * to clean up will be gone. (See │ │ │ │ │ - * http://trac.osgeo.org/openlayers/ticket/2277 for more information). │ │ │ │ │ - * This will apply to GeoExt and also to other applications which │ │ │ │ │ - * modify the DOM of the container of the OpenLayers Map. │ │ │ │ │ + * APIMethod: move │ │ │ │ │ + * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ + * This modifies the position of the geometry and clears the cached │ │ │ │ │ + * bounds. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ + * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // if unloadDestroy is null, we've already been destroyed │ │ │ │ │ - if (!this.unloadDestroy) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // make sure panning doesn't continue after destruction │ │ │ │ │ - if (this.panTween) { │ │ │ │ │ - this.panTween.stop(); │ │ │ │ │ - this.panTween = null; │ │ │ │ │ - } │ │ │ │ │ - // make sure zooming doesn't continue after destruction │ │ │ │ │ - if (this.zoomTween) { │ │ │ │ │ - this.zoomTween.stop(); │ │ │ │ │ - this.zoomTween = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // map has been destroyed. dont do it again! │ │ │ │ │ - OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); │ │ │ │ │ - this.unloadDestroy = null; │ │ │ │ │ - │ │ │ │ │ - if (this.updateSizeDestroy) { │ │ │ │ │ - OpenLayers.Event.stopObserving(window, 'resize', │ │ │ │ │ - this.updateSizeDestroy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.paddingForPopups = null; │ │ │ │ │ - │ │ │ │ │ - if (this.controls != null) { │ │ │ │ │ - for (var i = this.controls.length - 1; i >= 0; --i) { │ │ │ │ │ - this.controls[i].destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.controls = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.layers != null) { │ │ │ │ │ - for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ - //pass 'false' to destroy so that map wont try to set a new │ │ │ │ │ - // baselayer after each baselayer is removed │ │ │ │ │ - this.layers[i].destroy(false); │ │ │ │ │ - } │ │ │ │ │ - this.layers = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.viewPortDiv && this.viewPortDiv.parentNode) { │ │ │ │ │ - this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ - } │ │ │ │ │ - this.viewPortDiv = null; │ │ │ │ │ - │ │ │ │ │ - if (this.tileManager) { │ │ │ │ │ - this.tileManager.removeMap(this); │ │ │ │ │ - this.tileManager = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - this.options = null; │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + this.x = this.x + x; │ │ │ │ │ + this.y = this.y + y; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setOptions │ │ │ │ │ - * Change the map options │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a point around another. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Hashtable of options to tag to the map │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - setOptions: function(options) { │ │ │ │ │ - var updatePxExtent = this.minPx && │ │ │ │ │ - options.restrictedExtent != this.restrictedExtent; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - // force recalculation of minPx and maxPx │ │ │ │ │ - updatePxExtent && this.moveTo(this.getCachedCenter(), this.zoom, { │ │ │ │ │ - forceZoomChange: true │ │ │ │ │ - }); │ │ │ │ │ + rotate: function(angle, origin) { │ │ │ │ │ + angle *= Math.PI / 180; │ │ │ │ │ + var radius = this.distanceTo(origin); │ │ │ │ │ + var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x); │ │ │ │ │ + this.x = origin.x + (radius * Math.cos(theta)); │ │ │ │ │ + this.y = origin.y + (radius * Math.sin(theta)); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTileSize │ │ │ │ │ - * Get the tile size for the map │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - getTileSize: function() { │ │ │ │ │ - return this.tileSize; │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getBy │ │ │ │ │ - * Get a list of objects given a property and a match item. │ │ │ │ │ + * APIMethod: resize │ │ │ │ │ + * Resize a point relative to some origin. For points, this has the effect │ │ │ │ │ + * of scaling a vector (from the origin to the point). This method is │ │ │ │ │ + * more useful on geometry collection subclasses. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * array - {String} A property on the map whose value is an array. │ │ │ │ │ - * property - {String} A property on each item of the given array. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(map[array][i][property]) evaluates to true, the item will │ │ │ │ │ - * be included in the array returned. If no items are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ + * scale - {Float} Ratio of the new distance from the origin to the old │ │ │ │ │ + * distance from the origin. A scale of 2 doubles the │ │ │ │ │ + * distance between the point and origin. │ │ │ │ │ + * origin - {} Point of origin for resizing │ │ │ │ │ + * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} An array of items where the given property matches the given │ │ │ │ │ - * criteria. │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - getBy: function(array, property, match) { │ │ │ │ │ - var test = (typeof match.test == "function"); │ │ │ │ │ - var found = OpenLayers.Array.filter(this[array], function(item) { │ │ │ │ │ - return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ - }); │ │ │ │ │ - return found; │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + ratio = (ratio == undefined) ? 1 : ratio; │ │ │ │ │ + this.x = origin.x + (scale * ratio * (this.x - origin.x)); │ │ │ │ │ + this.y = origin.y + (scale * (this.y - origin.y)); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersBy │ │ │ │ │ - * Get a list of layers with properties matching the given criteria. │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * property - {String} A layer property to be matched. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ - * included in the array returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given criteria. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - getLayersBy: function(property, match) { │ │ │ │ │ - return this.getBy("layers", property, match); │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + intersect = this.equals(geometry); │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ + } │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersByName │ │ │ │ │ - * Get a list of layers with names matching the given name. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Translate the x,y properties of the point from source to dest. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * match - {String | Object} A layer name. The name can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * name.test(layer.name) evaluates to true, the layer will be included │ │ │ │ │ - * in the list of layers returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given name. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getLayersByName: function(match) { │ │ │ │ │ - return this.getLayersBy("name", match); │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if ((source && dest)) { │ │ │ │ │ + OpenLayers.Projection.transform( │ │ │ │ │ + this, source, dest); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersByClass │ │ │ │ │ - * Get a list of layers of a given class (CLASS_NAME). │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * match - {String | Object} A layer class name. The match can also be a │ │ │ │ │ - * regular expression literal or object. In addition, it can be any │ │ │ │ │ - * object with a method named test. For reqular expressions or other, │ │ │ │ │ - * if type.test(layer.CLASS_NAME) evaluates to true, the layer will │ │ │ │ │ - * be included in the list of layers returned. If no layers are │ │ │ │ │ - * found, an empty array is returned. │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given class. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getLayersByClass: function(match) { │ │ │ │ │ - return this.getLayersBy("CLASS_NAME", match); │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + return [this]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Collection.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Collection │ │ │ │ │ + * A Collection is exactly what it sounds like: A collection of different │ │ │ │ │ + * Geometries. These are stored in the local parameter (which │ │ │ │ │ + * can be passed as a parameter to the constructor). │ │ │ │ │ + * │ │ │ │ │ + * As new geometries are added to the collection, they are NOT cloned. │ │ │ │ │ + * When removing geometries, they need to be specified by reference (ie you │ │ │ │ │ + * have to pass in the *exact* geometry to be removed). │ │ │ │ │ + * │ │ │ │ │ + * The and functions here merely iterate through │ │ │ │ │ + * the components, summing their respective areas and lengths. │ │ │ │ │ + * │ │ │ │ │ + * Create a new instance with the constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControlsBy │ │ │ │ │ - * Get a list of controls with properties matching the given criteria. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} A control property to be matched. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ - * included in the array returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} A list of controls matching the given │ │ │ │ │ - * criteria. An empty array is returned if no matches are found. │ │ │ │ │ + * APIProperty: components │ │ │ │ │ + * {Array()} The component parts of this geometry │ │ │ │ │ */ │ │ │ │ │ - getControlsBy: function(property, match) { │ │ │ │ │ - return this.getBy("controls", property, match); │ │ │ │ │ - }, │ │ │ │ │ + components: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControlsByClass │ │ │ │ │ - * Get a list of controls of a given class (CLASS_NAME). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * match - {String | Object} A control class name. The match can also be a │ │ │ │ │ - * regular expression literal or object. In addition, it can be any │ │ │ │ │ - * object with a method named test. For reqular expressions or other, │ │ │ │ │ - * if type.test(control.CLASS_NAME) evaluates to true, the control will │ │ │ │ │ - * be included in the list of controls returned. If no controls are │ │ │ │ │ - * found, an empty array is returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} A list of controls matching the given class. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null value means the │ │ │ │ │ + * component types are not restricted. │ │ │ │ │ */ │ │ │ │ │ - getControlsByClass: function(match) { │ │ │ │ │ - return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Layer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Layers to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ + componentTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayer │ │ │ │ │ - * Get a layer based on its id │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ + * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} A layer id │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} Optional array of geometries │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The Layer with the corresponding id from the map's │ │ │ │ │ - * layer collection, or null if not found. │ │ │ │ │ */ │ │ │ │ │ - getLayer: function(id) { │ │ │ │ │ - var foundLayer = null; │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer.id == id) { │ │ │ │ │ - foundLayer = layer; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + initialize: function(components) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.components = []; │ │ │ │ │ + if (components != null) { │ │ │ │ │ + this.addComponents(components); │ │ │ │ │ } │ │ │ │ │ - return foundLayer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayerZIndex │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * zIdx - {int} │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - setLayerZIndex: function(layer, zIdx) { │ │ │ │ │ - layer.setZIndex( │ │ │ │ │ - this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] + │ │ │ │ │ - zIdx * 5); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.components.length = 0; │ │ │ │ │ + this.components = null; │ │ │ │ │ + OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetLayersZIndex │ │ │ │ │ - * Reset each layer's z-index based on layer's array index │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clone this geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this collection │ │ │ │ │ */ │ │ │ │ │ - resetLayersZIndex: function() { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - this.setLayerZIndex(layer, i); │ │ │ │ │ + clone: function() { │ │ │ │ │ + var geometry = eval("new " + this.CLASS_NAME + "()"); │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + geometry.addComponent(this.components[i].clone()); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ + │ │ │ │ │ + return geometry; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addLayer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * │ │ │ │ │ + * Method: getComponentsString │ │ │ │ │ + * Get a string representing the components for this collection │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} True if the layer has been added to the map. │ │ │ │ │ + * {String} A string representation of the components of this geometry │ │ │ │ │ */ │ │ │ │ │ - addLayer: function(layer) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - if (this.layers[i] == layer) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.events.triggerEvent("preaddlayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }) === false) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (this.allOverlays) { │ │ │ │ │ - layer.isBaseLayer = false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - layer.div.className = "olLayerDiv"; │ │ │ │ │ - layer.div.style.overflow = ""; │ │ │ │ │ - this.setLayerZIndex(layer, this.layers.length); │ │ │ │ │ - │ │ │ │ │ - if (layer.isFixed) { │ │ │ │ │ - this.viewPortDiv.appendChild(layer.div); │ │ │ │ │ - } else { │ │ │ │ │ - this.layerContainerDiv.appendChild(layer.div); │ │ │ │ │ + getComponentsString: function() { │ │ │ │ │ + var strings = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + strings.push(this.components[i].toShortString()); │ │ │ │ │ } │ │ │ │ │ - this.layers.push(layer); │ │ │ │ │ - layer.setMap(this); │ │ │ │ │ + return strings.join(","); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (layer.isBaseLayer || (this.allOverlays && !this.baseLayer)) { │ │ │ │ │ - if (this.baseLayer == null) { │ │ │ │ │ - // set the first baselaye we add as the baselayer │ │ │ │ │ - this.setBaseLayer(layer); │ │ │ │ │ - } else { │ │ │ │ │ - layer.setVisibility(false); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds by iterating through the components and │ │ │ │ │ + * calling calling extendBounds() on each item. │ │ │ │ │ + */ │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + var bounds = new OpenLayers.Bounds(); │ │ │ │ │ + var components = this.components; │ │ │ │ │ + if (components) { │ │ │ │ │ + for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ + bounds.extend(components[i].getBounds()); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - layer.redraw(); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("addlayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.events.triggerEvent("added", { │ │ │ │ │ - map: this, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.afterAdd(); │ │ │ │ │ - │ │ │ │ │ - return true; │ │ │ │ │ + // to preserve old behavior, we only set bounds if non-null │ │ │ │ │ + // in the future, we could add bounds.isEmpty() │ │ │ │ │ + if (bounds.left != null && bounds.bottom != null && │ │ │ │ │ + bounds.right != null && bounds.top != null) { │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addLayers │ │ │ │ │ + * APIMethod: addComponents │ │ │ │ │ + * Add components to this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layers - {Array()} │ │ │ │ │ + * components - {Array()} An array of geometries to add │ │ │ │ │ */ │ │ │ │ │ - addLayers: function(layers) { │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - this.addLayer(layers[i]); │ │ │ │ │ + addComponents: function(components) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ + this.addComponent(components[i]); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeLayer │ │ │ │ │ - * Removes a layer from the map by removing its visual element (the │ │ │ │ │ - * layer.div property), then removing it from the map's internal list │ │ │ │ │ - * of layers, setting the layer's map property to null. │ │ │ │ │ - * │ │ │ │ │ - * a "removelayer" event is triggered. │ │ │ │ │ - * │ │ │ │ │ - * very worthy of mention is that simply removing a layer from a map │ │ │ │ │ - * will not cause the removal of any popups which may have been created │ │ │ │ │ - * by the layer. this is due to the fact that it was decided at some │ │ │ │ │ - * point that popups would not belong to layers. thus there is no way │ │ │ │ │ - * for us to know here to which layer the popup belongs. │ │ │ │ │ - * │ │ │ │ │ - * A simple solution to this is simply to call destroy() on the layer. │ │ │ │ │ - * the default OpenLayers.Layer class's destroy() function │ │ │ │ │ - * automatically takes care to remove itself from whatever map it has │ │ │ │ │ - * been attached to. │ │ │ │ │ - * │ │ │ │ │ - * The correct solution is for the layer itself to register an │ │ │ │ │ - * event-handler on "removelayer" and when it is called, if it │ │ │ │ │ - * recognizes itself as the layer being removed, then it cycles through │ │ │ │ │ - * its own personal list of popups, removing them from the map. │ │ │ │ │ + /** │ │ │ │ │ + * Method: addComponent │ │ │ │ │ + * Add a new component (geometry) to the collection. If this.componentTypes │ │ │ │ │ + * is set, then the component class name must be in the componentTypes array. │ │ │ │ │ + * │ │ │ │ │ + * The bounds cache is reset. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * setNewBaseLayer - {Boolean} Default is true │ │ │ │ │ + * component - {} A geometry to add │ │ │ │ │ + * index - {int} Optional index into the array to insert the component │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component geometry was successfully added │ │ │ │ │ */ │ │ │ │ │ - removeLayer: function(layer, setNewBaseLayer) { │ │ │ │ │ - if (this.events.triggerEvent("preremovelayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }) === false) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (setNewBaseLayer == null) { │ │ │ │ │ - setNewBaseLayer = true; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (layer.isFixed) { │ │ │ │ │ - this.viewPortDiv.removeChild(layer.div); │ │ │ │ │ - } else { │ │ │ │ │ - this.layerContainerDiv.removeChild(layer.div); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.removeItem(this.layers, layer); │ │ │ │ │ - layer.removeMap(this); │ │ │ │ │ - layer.map = null; │ │ │ │ │ + addComponent: function(component, index) { │ │ │ │ │ + var added = false; │ │ │ │ │ + if (component) { │ │ │ │ │ + if (this.componentTypes == null || │ │ │ │ │ + (OpenLayers.Util.indexOf(this.componentTypes, │ │ │ │ │ + component.CLASS_NAME) > -1)) { │ │ │ │ │ │ │ │ │ │ - // if we removed the base layer, need to set a new one │ │ │ │ │ - if (this.baseLayer == layer) { │ │ │ │ │ - this.baseLayer = null; │ │ │ │ │ - if (setNewBaseLayer) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var iLayer = this.layers[i]; │ │ │ │ │ - if (iLayer.isBaseLayer || this.allOverlays) { │ │ │ │ │ - this.setBaseLayer(iLayer); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + if (index != null && (index < this.components.length)) { │ │ │ │ │ + var components1 = this.components.slice(0, index); │ │ │ │ │ + var components2 = this.components.slice(index, │ │ │ │ │ + this.components.length); │ │ │ │ │ + components1.push(component); │ │ │ │ │ + this.components = components1.concat(components2); │ │ │ │ │ + } else { │ │ │ │ │ + this.components.push(component); │ │ │ │ │ } │ │ │ │ │ + component.parent = this; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + added = true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.resetLayersZIndex(); │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("removelayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.events.triggerEvent("removed", { │ │ │ │ │ - map: this, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ + return added; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getNumLayers │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Int} The number of layers attached to the map. │ │ │ │ │ - */ │ │ │ │ │ - getNumLayers: function() { │ │ │ │ │ - return this.layers.length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerIndex │ │ │ │ │ + * APIMethod: removeComponents │ │ │ │ │ + * Remove components from this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ + * components - {Array()} The components to be removed │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The current (zero-based) index of the given layer in the map's │ │ │ │ │ - * layer stack. Returns -1 if the layer isn't on the map. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A component was removed. │ │ │ │ │ */ │ │ │ │ │ - getLayerIndex: function(layer) { │ │ │ │ │ - return OpenLayers.Util.indexOf(this.layers, layer); │ │ │ │ │ - }, │ │ │ │ │ + removeComponents: function(components) { │ │ │ │ │ + var removed = false; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setLayerIndex │ │ │ │ │ - * Move the given layer to the specified (zero-based) index in the layer │ │ │ │ │ - * list, changing its z-index in the map display. Use │ │ │ │ │ - * map.getLayerIndex() to find out the current index of a layer. Note │ │ │ │ │ - * that this cannot (or at least should not) be effectively used to │ │ │ │ │ - * raise base layers above overlays. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * idx - {int} │ │ │ │ │ - */ │ │ │ │ │ - setLayerIndex: function(layer, idx) { │ │ │ │ │ - var base = this.getLayerIndex(layer); │ │ │ │ │ - if (idx < 0) { │ │ │ │ │ - idx = 0; │ │ │ │ │ - } else if (idx > this.layers.length) { │ │ │ │ │ - idx = this.layers.length; │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ } │ │ │ │ │ - if (base != idx) { │ │ │ │ │ - this.layers.splice(base, 1); │ │ │ │ │ - this.layers.splice(idx, 0, layer); │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - this.setLayerZIndex(this.layers[i], i); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: layer, │ │ │ │ │ - property: "order" │ │ │ │ │ - }); │ │ │ │ │ - if (this.allOverlays) { │ │ │ │ │ - if (idx === 0) { │ │ │ │ │ - this.setBaseLayer(layer); │ │ │ │ │ - } else if (this.baseLayer !== this.layers[0]) { │ │ │ │ │ - this.setBaseLayer(this.layers[0]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ + removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ } │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: raiseLayer │ │ │ │ │ - * Change the index of the given layer by delta. If delta is positive, │ │ │ │ │ - * the layer is moved up the map's layer stack; if delta is negative, │ │ │ │ │ - * the layer is moved down. Again, note that this cannot (or at least │ │ │ │ │ - * should not) be effectively used to raise base layers above overlays. │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeComponent │ │ │ │ │ + * Remove a component from this geometry. │ │ │ │ │ * │ │ │ │ │ - * Paremeters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * delta - {int} │ │ │ │ │ - */ │ │ │ │ │ - raiseLayer: function(layer, delta) { │ │ │ │ │ - var idx = this.getLayerIndex(layer) + delta; │ │ │ │ │ - this.setLayerIndex(layer, idx); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setBaseLayer │ │ │ │ │ - * Allows user to specify one of the currently-loaded layers as the Map's │ │ │ │ │ - * new base layer. │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newBaseLayer - {} │ │ │ │ │ + * component - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - setBaseLayer: function(newBaseLayer) { │ │ │ │ │ - │ │ │ │ │ - if (newBaseLayer != this.baseLayer) { │ │ │ │ │ - │ │ │ │ │ - // ensure newBaseLayer is already loaded │ │ │ │ │ - if (OpenLayers.Util.indexOf(this.layers, newBaseLayer) != -1) { │ │ │ │ │ - │ │ │ │ │ - // preserve center and scale when changing base layers │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - var newResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - this.getScale(), newBaseLayer.units │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // make the old base layer invisible │ │ │ │ │ - if (this.baseLayer != null && !this.allOverlays) { │ │ │ │ │ - this.baseLayer.setVisibility(false); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // set new baselayer │ │ │ │ │ - this.baseLayer = newBaseLayer; │ │ │ │ │ - │ │ │ │ │ - if (!this.allOverlays || this.baseLayer.visibility) { │ │ │ │ │ - this.baseLayer.setVisibility(true); │ │ │ │ │ - // Layer may previously have been visible but not in range. │ │ │ │ │ - // In this case we need to redraw it to make it visible. │ │ │ │ │ - if (this.baseLayer.inRange === false) { │ │ │ │ │ - this.baseLayer.redraw(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + removeComponent: function(component) { │ │ │ │ │ │ │ │ │ │ - // recenter the map │ │ │ │ │ - if (center != null) { │ │ │ │ │ - // new zoom level derived from old scale │ │ │ │ │ - var newZoom = this.getZoomForResolution( │ │ │ │ │ - newResolution || this.resolution, true │ │ │ │ │ - ); │ │ │ │ │ - // zoom and force zoom change │ │ │ │ │ - this.setCenter(center, newZoom, false, true); │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ │ │ │ │ │ - this.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this.baseLayer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ + // to this.getBounds(); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Control Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Controls to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addControl │ │ │ │ │ - * Add the passed over control to the map. Optionally │ │ │ │ │ - * position the control at the given pixel. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * px - {} │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ + * Calculate the length of this geometry │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The length of the geometry │ │ │ │ │ */ │ │ │ │ │ - addControl: function(control, px) { │ │ │ │ │ - this.controls.push(control); │ │ │ │ │ - this.addControlToMap(control, px); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i].getLength(); │ │ │ │ │ + } │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addControls │ │ │ │ │ - * Add all of the passed over controls to the map. │ │ │ │ │ - * You can pass over an optional second array │ │ │ │ │ - * with pixel-objects to position the controls. │ │ │ │ │ - * The indices of the two arrays should match and │ │ │ │ │ - * you can add null as pixel for those controls │ │ │ │ │ - * you want to be autopositioned. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * controls - {Array()} │ │ │ │ │ - * pixels - {Array()} │ │ │ │ │ + * APIMethod: getArea │ │ │ │ │ + * Calculate the area of this geometry. Note how this function is overridden │ │ │ │ │ + * in . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - addControls: function(controls, pixels) { │ │ │ │ │ - var pxs = (arguments.length === 1) ? [] : pixels; │ │ │ │ │ - for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ - var ctrl = controls[i]; │ │ │ │ │ - var px = (pxs[i]) ? pxs[i] : null; │ │ │ │ │ - this.addControl(ctrl, px); │ │ │ │ │ + getArea: function() { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + area += this.components[i].getArea(); │ │ │ │ │ } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addControlToMap │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getGeodesicArea │ │ │ │ │ + * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ - * control - {} │ │ │ │ │ - * px - {} │ │ │ │ │ + * Reference: │ │ │ │ │ + * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for │ │ │ │ │ + * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion │ │ │ │ │ + * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {float} The approximate geodesic area of the geometry in square meters. │ │ │ │ │ */ │ │ │ │ │ - addControlToMap: function(control, px) { │ │ │ │ │ - // If a control doesn't have a div at this point, it belongs in the │ │ │ │ │ - // viewport. │ │ │ │ │ - control.outsideViewport = (control.div != null); │ │ │ │ │ - │ │ │ │ │ - // If the map has a displayProjection, and the control doesn't, set │ │ │ │ │ - // the display projection. │ │ │ │ │ - if (this.displayProjection && !control.displayProjection) { │ │ │ │ │ - control.displayProjection = this.displayProjection; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - control.setMap(this); │ │ │ │ │ - var div = control.draw(px); │ │ │ │ │ - if (div) { │ │ │ │ │ - if (!control.outsideViewport) { │ │ │ │ │ - div.style.zIndex = this.Z_INDEX_BASE['Control'] + │ │ │ │ │ - this.controls.length; │ │ │ │ │ - this.viewPortDiv.appendChild(div); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (control.autoActivate) { │ │ │ │ │ - control.activate(); │ │ │ │ │ + getGeodesicArea: function(projection) { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + area += this.components[i].getGeodesicArea(projection); │ │ │ │ │ } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControl │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * │ │ │ │ │ + * Compute the centroid for this geometry collection. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * id - {String} ID of the control to return. │ │ │ │ │ - * │ │ │ │ │ + * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ + * returning an area weighted average of all geometries in this collection. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The control from the map's list of controls │ │ │ │ │ - * which has a matching 'id'. If none found, │ │ │ │ │ - * returns null. │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - getControl: function(id) { │ │ │ │ │ - var returnControl = null; │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - var control = this.controls[i]; │ │ │ │ │ - if (control.id == id) { │ │ │ │ │ - returnControl = control; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + getCentroid: function(weighted) { │ │ │ │ │ + if (!weighted) { │ │ │ │ │ + return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ + } │ │ │ │ │ + var len = this.components.length; │ │ │ │ │ + if (!len) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return returnControl; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeControl │ │ │ │ │ - * Remove a control from the map. Removes the control both from the map │ │ │ │ │ - * object's internal array of controls, as well as from the map's │ │ │ │ │ - * viewPort (assuming the control was not added outsideViewport) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control to remove. │ │ │ │ │ - */ │ │ │ │ │ - removeControl: function(control) { │ │ │ │ │ - //make sure control is non-null and actually part of our map │ │ │ │ │ - if ((control) && (control == this.getControl(control.id))) { │ │ │ │ │ - if (control.div && (control.div.parentNode == this.viewPortDiv)) { │ │ │ │ │ - this.viewPortDiv.removeChild(control.div); │ │ │ │ │ + var areas = []; │ │ │ │ │ + var centroids = []; │ │ │ │ │ + var areaSum = 0; │ │ │ │ │ + var minArea = Number.MAX_VALUE; │ │ │ │ │ + var component; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + component = this.components[i]; │ │ │ │ │ + var area = component.getArea(); │ │ │ │ │ + var centroid = component.getCentroid(true); │ │ │ │ │ + if (isNaN(area) || isNaN(centroid.x) || isNaN(centroid.y)) { │ │ │ │ │ + continue; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Util.removeItem(this.controls, control); │ │ │ │ │ + areas.push(area); │ │ │ │ │ + areaSum += area; │ │ │ │ │ + minArea = (area < minArea && area > 0) ? area : minArea; │ │ │ │ │ + centroids.push(centroid); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Popup Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Popups to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addPopup │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * popup - {} │ │ │ │ │ - * exclusive - {Boolean} If true, closes all other popups first │ │ │ │ │ - */ │ │ │ │ │ - addPopup: function(popup, exclusive) { │ │ │ │ │ - │ │ │ │ │ - if (exclusive) { │ │ │ │ │ - //remove all other popups from screen │ │ │ │ │ - for (var i = this.popups.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removePopup(this.popups[i]); │ │ │ │ │ + len = areas.length; │ │ │ │ │ + if (areaSum === 0) { │ │ │ │ │ + // all the components in this collection have 0 area │ │ │ │ │ + // probably a collection of points -- weight all the points the same │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + areas[i] = 1; │ │ │ │ │ + } │ │ │ │ │ + areaSum = areas.length; │ │ │ │ │ + } else { │ │ │ │ │ + // normalize all the areas where the smallest area will get │ │ │ │ │ + // a value of 1 │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + areas[i] /= minArea; │ │ │ │ │ } │ │ │ │ │ + areaSum /= minArea; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - popup.map = this; │ │ │ │ │ - this.popups.push(popup); │ │ │ │ │ - var popupDiv = popup.draw(); │ │ │ │ │ - if (popupDiv) { │ │ │ │ │ - popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + │ │ │ │ │ - this.popups.length; │ │ │ │ │ - this.layerContainerDiv.appendChild(popupDiv); │ │ │ │ │ + var xSum = 0, │ │ │ │ │ + ySum = 0, │ │ │ │ │ + centroid, area; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + centroid = centroids[i]; │ │ │ │ │ + area = areas[i]; │ │ │ │ │ + xSum += centroid.x * area; │ │ │ │ │ + ySum += centroid.y * area; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removePopup │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * popup - {} │ │ │ │ │ - */ │ │ │ │ │ - removePopup: function(popup) { │ │ │ │ │ - OpenLayers.Util.removeItem(this.popups, popup); │ │ │ │ │ - if (popup.div) { │ │ │ │ │ - try { │ │ │ │ │ - this.layerContainerDiv.removeChild(popup.div); │ │ │ │ │ - } catch (e) {} // Popups sometimes apparently get disconnected │ │ │ │ │ - // from the layerContainerDiv, and cause complaints. │ │ │ │ │ - } │ │ │ │ │ - popup.map = null; │ │ │ │ │ + return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Container Div Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with the access to */ │ │ │ │ │ - /* and maintenance of the size of the container div */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getSize │ │ │ │ │ + * APIMethod: getGeodesicLength │ │ │ │ │ + * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ + * │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An object that represents the │ │ │ │ │ - * size, in pixels, of the div into which OpenLayers │ │ │ │ │ - * has been loaded. │ │ │ │ │ - * Note - A clone() of this locally cached variable is │ │ │ │ │ - * returned, so as not to allow users to modify it. │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - getSize: function() { │ │ │ │ │ - var size = null; │ │ │ │ │ - if (this.size != null) { │ │ │ │ │ - size = this.size.clone(); │ │ │ │ │ + getGeodesicLength: function(projection) { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i].getGeodesicLength(projection); │ │ │ │ │ } │ │ │ │ │ - return size; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: updateSize │ │ │ │ │ - * This function should be called by any external code which dynamically │ │ │ │ │ - * changes the size of the map div (because mozilla wont let us catch │ │ │ │ │ - * the "onresize" for an element) │ │ │ │ │ + * APIMethod: move │ │ │ │ │ + * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ + * This modifies the position of the geometry and clears the cached │ │ │ │ │ + * bounds. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ + * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ */ │ │ │ │ │ - updateSize: function() { │ │ │ │ │ - // the div might have moved on the page, also │ │ │ │ │ - var newSize = this.getCurrentSize(); │ │ │ │ │ - if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) { │ │ │ │ │ - this.events.clearMouseCache(); │ │ │ │ │ - var oldSize = this.getSize(); │ │ │ │ │ - if (oldSize == null) { │ │ │ │ │ - this.size = oldSize = newSize; │ │ │ │ │ - } │ │ │ │ │ - if (!newSize.equals(oldSize)) { │ │ │ │ │ - │ │ │ │ │ - // store the new size │ │ │ │ │ - this.size = newSize; │ │ │ │ │ - │ │ │ │ │ - //notify layers of mapresize │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - this.layers[i].onMapResize(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - │ │ │ │ │ - if (this.baseLayer != null && center != null) { │ │ │ │ │ - var zoom = this.getZoom(); │ │ │ │ │ - this.zoom = null; │ │ │ │ │ - this.setCenter(center, zoom); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + this.components[i].move(x, y); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("updatesize"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentSize │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A new object with the dimensions │ │ │ │ │ - * of the map div │ │ │ │ │ - */ │ │ │ │ │ - getCurrentSize: function() { │ │ │ │ │ - │ │ │ │ │ - var size = new OpenLayers.Size(this.div.clientWidth, │ │ │ │ │ - this.div.clientHeight); │ │ │ │ │ - │ │ │ │ │ - if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ - size.w = this.div.offsetWidth; │ │ │ │ │ - size.h = this.div.offsetHeight; │ │ │ │ │ - } │ │ │ │ │ - if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ - size.w = parseInt(this.div.style.width); │ │ │ │ │ - size.h = parseInt(this.div.style.height); │ │ │ │ │ - } │ │ │ │ │ - return size; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a geometry around some origin │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * center - {} Default is this.getCenter() │ │ │ │ │ - * resolution - {float} Default is this.getResolution() │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A bounds based on resolution, center, and │ │ │ │ │ - * current mapsize. │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - calculateBounds: function(center, resolution) { │ │ │ │ │ - │ │ │ │ │ - var extent = null; │ │ │ │ │ - │ │ │ │ │ - if (center == null) { │ │ │ │ │ - center = this.getCachedCenter(); │ │ │ │ │ - } │ │ │ │ │ - if (resolution == null) { │ │ │ │ │ - resolution = this.getResolution(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if ((center != null) && (resolution != null)) { │ │ │ │ │ - var halfWDeg = (this.size.w * resolution) / 2; │ │ │ │ │ - var halfHDeg = (this.size.h * resolution) / 2; │ │ │ │ │ - │ │ │ │ │ - extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ - center.lat - halfHDeg, │ │ │ │ │ - center.lon + halfWDeg, │ │ │ │ │ - center.lat + halfHDeg); │ │ │ │ │ + rotate: function(angle, origin) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + this.components[i].rotate(angle, origin); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return extent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Zoom, Center, Pan Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions handle the validation, */ │ │ │ │ │ - /* getting and setting of the Zoom Level and Center */ │ │ │ │ │ - /* as well as the panning of the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCenter │ │ │ │ │ + * APIMethod: resize │ │ │ │ │ + * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ + * a uniform scaling to a geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scale - {Float} Factor by which to scale the geometry. A scale of 2 │ │ │ │ │ + * doubles the size of the geometry in each dimension │ │ │ │ │ + * (lines, for example, will be twice as long, and polygons │ │ │ │ │ + * will have four times the area). │ │ │ │ │ + * origin - {} Point of origin for resizing │ │ │ │ │ + * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - getCenter: function() { │ │ │ │ │ - var center = null; │ │ │ │ │ - var cachedCenter = this.getCachedCenter(); │ │ │ │ │ - if (cachedCenter) { │ │ │ │ │ - center = cachedCenter.clone(); │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ + this.components[i].resize(scale, origin, ratio); │ │ │ │ │ } │ │ │ │ │ - return center; │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCachedCenter │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getCachedCenter: function() { │ │ │ │ │ - if (!this.center && this.size) { │ │ │ │ │ - this.center = this.getLonLatFromViewPortPx({ │ │ │ │ │ - x: this.size.w / 2, │ │ │ │ │ - y: this.size.h / 2 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return this.center; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoom │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ - getZoom: function() { │ │ │ │ │ - return this.zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: pan │ │ │ │ │ - * Allows user to pan by a value of screen pixels │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Integer} │ │ │ │ │ - * dy - {Integer} │ │ │ │ │ - * options - {Object} Options to configure panning: │ │ │ │ │ - * - *animate* {Boolean} Use panTo instead of setCenter. Default is true. │ │ │ │ │ - * - *dragging* {Boolean} Call setCenter with dragging true. Default is │ │ │ │ │ - * false. │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and y1 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - pan: function(dx, dy, options) { │ │ │ │ │ - options = OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ - animate: true, │ │ │ │ │ - dragging: false │ │ │ │ │ - }); │ │ │ │ │ - if (options.dragging) { │ │ │ │ │ - if (dx != 0 || dy != 0) { │ │ │ │ │ - this.moveByPx(dx, dy); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // getCenter │ │ │ │ │ - var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter()); │ │ │ │ │ - │ │ │ │ │ - // adjust │ │ │ │ │ - var newCenterPx = centerPx.add(dx, dy); │ │ │ │ │ - │ │ │ │ │ - if (this.dragging || !newCenterPx.equals(centerPx)) { │ │ │ │ │ - var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); │ │ │ │ │ - if (options.animate) { │ │ │ │ │ - this.panTo(newCenterLonLat); │ │ │ │ │ - } else { │ │ │ │ │ - this.moveTo(newCenterLonLat); │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.events.triggerEvent("moveend"); │ │ │ │ │ - } │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var result, best, distance; │ │ │ │ │ + var min = Number.POSITIVE_INFINITY; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + result = this.components[i].distanceTo(geometry, options); │ │ │ │ │ + distance = details ? result.distance : result; │ │ │ │ │ + if (distance < min) { │ │ │ │ │ + min = distance; │ │ │ │ │ + best = result; │ │ │ │ │ + if (min == 0) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: panTo │ │ │ │ │ - * Allows user to pan to a new lonlat │ │ │ │ │ - * If the new lonlat is in the current extent the map will slide smoothly │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + * geometry - {} The geometry to test. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - panTo: function(lonlat) { │ │ │ │ │ - if (this.panTween && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - │ │ │ │ │ - // center will not change, don't do nothing │ │ │ │ │ - if (lonlat.equals(center)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var from = this.getPixelFromLonLat(center); │ │ │ │ │ - var to = this.getPixelFromLonLat(lonlat); │ │ │ │ │ - var vector = { │ │ │ │ │ - x: to.x - from.x, │ │ │ │ │ - y: to.y - from.y │ │ │ │ │ - }; │ │ │ │ │ - var last = { │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - this.panTween.start({ │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }, vector, this.panDuration, { │ │ │ │ │ - callbacks: { │ │ │ │ │ - eachStep: OpenLayers.Function.bind(function(px) { │ │ │ │ │ - var x = px.x - last.x, │ │ │ │ │ - y = px.y - last.y; │ │ │ │ │ - this.moveByPx(x, y); │ │ │ │ │ - last.x = Math.round(px.x); │ │ │ │ │ - last.y = Math.round(px.y); │ │ │ │ │ - }, this), │ │ │ │ │ - done: OpenLayers.Function.bind(function(px) { │ │ │ │ │ - this.moveTo(lonlat); │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.events.triggerEvent("moveend"); │ │ │ │ │ - }, this) │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ + equals: function(geometry) { │ │ │ │ │ + var equivalent = true; │ │ │ │ │ + if (!geometry || !geometry.CLASS_NAME || │ │ │ │ │ + (this.CLASS_NAME != geometry.CLASS_NAME)) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ + } else if (!(OpenLayers.Util.isArray(geometry.components)) || │ │ │ │ │ + (geometry.components.length != this.components.length)) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ } else { │ │ │ │ │ - this.setCenter(lonlat); │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + if (!this.components[i].equals(geometry.components[i])) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return equivalent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setCenter │ │ │ │ │ - * Set the map center (and optionally, the zoom level). │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Reproject the components geometry from source to dest. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {|Array} The new center location. │ │ │ │ │ - * If provided as array, the first value is the x coordinate, │ │ │ │ │ - * and the 2nd value is the y coordinate. │ │ │ │ │ - * zoom - {Integer} Optional zoom level. │ │ │ │ │ - * dragging - {Boolean} Specifies whether or not to trigger │ │ │ │ │ - * movestart/end events │ │ │ │ │ - * forceZoomChange - {Boolean} Specifies whether or not to trigger zoom │ │ │ │ │ - * change events (needed on baseLayer change) │ │ │ │ │ - * │ │ │ │ │ - * TBD: reconsider forceZoomChange in 3.0 │ │ │ │ │ - */ │ │ │ │ │ - setCenter: function(lonlat, zoom, dragging, forceZoomChange) { │ │ │ │ │ - if (this.panTween) { │ │ │ │ │ - this.panTween.stop(); │ │ │ │ │ - } │ │ │ │ │ - if (this.zoomTween) { │ │ │ │ │ - this.zoomTween.stop(); │ │ │ │ │ - } │ │ │ │ │ - this.moveTo(lonlat, zoom, { │ │ │ │ │ - 'dragging': dragging, │ │ │ │ │ - 'forceZoomChange': forceZoomChange │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Drag the map by pixels. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} │ │ │ │ │ - * dy - {Number} │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - var hw = this.size.w / 2; │ │ │ │ │ - var hh = this.size.h / 2; │ │ │ │ │ - var x = hw + dx; │ │ │ │ │ - var y = hh + dy; │ │ │ │ │ - var wrapDateLine = this.baseLayer.wrapDateLine; │ │ │ │ │ - var xRestriction = 0; │ │ │ │ │ - var yRestriction = 0; │ │ │ │ │ - if (this.restrictedExtent) { │ │ │ │ │ - xRestriction = hw; │ │ │ │ │ - yRestriction = hh; │ │ │ │ │ - // wrapping the date line makes no sense for restricted extents │ │ │ │ │ - wrapDateLine = false; │ │ │ │ │ - } │ │ │ │ │ - dx = wrapDateLine || │ │ │ │ │ - x <= this.maxPx.x - xRestriction && │ │ │ │ │ - x >= this.minPx.x + xRestriction ? Math.round(dx) : 0; │ │ │ │ │ - dy = y <= this.maxPx.y - yRestriction && │ │ │ │ │ - y >= this.minPx.y + yRestriction ? Math.round(dy) : 0; │ │ │ │ │ - if (dx || dy) { │ │ │ │ │ - if (!this.dragging) { │ │ │ │ │ - this.dragging = true; │ │ │ │ │ - this.events.triggerEvent("movestart"); │ │ │ │ │ - } │ │ │ │ │ - this.center = null; │ │ │ │ │ - if (dx) { │ │ │ │ │ - this.layerContainerOriginPx.x -= dx; │ │ │ │ │ - this.minPx.x -= dx; │ │ │ │ │ - this.maxPx.x -= dx; │ │ │ │ │ - } │ │ │ │ │ - if (dy) { │ │ │ │ │ - this.layerContainerOriginPx.y -= dy; │ │ │ │ │ - this.minPx.y -= dy; │ │ │ │ │ - this.maxPx.y -= dy; │ │ │ │ │ - } │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - var layer, i, len; │ │ │ │ │ - for (i = 0, len = this.layers.length; i < len; ++i) { │ │ │ │ │ - layer = this.layers[i]; │ │ │ │ │ - if (layer.visibility && │ │ │ │ │ - (layer === this.baseLayer || layer.inRange)) { │ │ │ │ │ - layer.moveByPx(dx, dy); │ │ │ │ │ - layer.events.triggerEvent("move"); │ │ │ │ │ - } │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if (source && dest) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + var component = this.components[i]; │ │ │ │ │ + component.transform(source, dest); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("move"); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: adjustZoom │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoom - {Number} The zoom level to adjust │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Integer} Adjusted zoom level that shows a map not wider than its │ │ │ │ │ - * 's maxExtent. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - adjustZoom: function(zoom) { │ │ │ │ │ - if (this.baseLayer && this.baseLayer.wrapDateLine) { │ │ │ │ │ - var resolution, resolutions = this.baseLayer.resolutions, │ │ │ │ │ - maxResolution = this.getMaxExtent().getWidth() / this.size.w; │ │ │ │ │ - if (this.getResolutionForZoom(zoom) > maxResolution) { │ │ │ │ │ - if (this.fractionalZoom) { │ │ │ │ │ - zoom = this.getZoomForResolution(maxResolution); │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = zoom | 0, ii = resolutions.length; i < ii; ++i) { │ │ │ │ │ - if (resolutions[i] <= maxResolution) { │ │ │ │ │ - zoom = i; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + intersect = geometry.intersects(this.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getMinZoom │ │ │ │ │ - * Returns the minimum zoom level for the current map view. If the base │ │ │ │ │ - * layer is configured with set to true, this will be the │ │ │ │ │ - * first zoom level that shows no more than one world width in the current │ │ │ │ │ - * map viewport. Components that rely on this value (e.g. zoom sliders) │ │ │ │ │ - * should also listen to the map's "updatesize" event and call this method │ │ │ │ │ - * in the "updatesize" listener. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} Minimum zoom level that shows a map not wider than its │ │ │ │ │ - * 's maxExtent. This is an Integer value, unless the map is │ │ │ │ │ - * configured with set to true. │ │ │ │ │ - */ │ │ │ │ │ - getMinZoom: function() { │ │ │ │ │ - return this.adjustZoom(0); │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * zoom - {Integer} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(lonlat, zoom, options) { │ │ │ │ │ - if (lonlat != null && !(lonlat instanceof OpenLayers.LonLat)) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lonlat); │ │ │ │ │ - } │ │ │ │ │ - if (!options) { │ │ │ │ │ - options = {}; │ │ │ │ │ - } │ │ │ │ │ - if (zoom != null) { │ │ │ │ │ - zoom = parseFloat(zoom); │ │ │ │ │ - if (!this.fractionalZoom) { │ │ │ │ │ - zoom = Math.round(zoom); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var requestedZoom = zoom; │ │ │ │ │ - zoom = this.adjustZoom(zoom); │ │ │ │ │ - if (zoom !== requestedZoom) { │ │ │ │ │ - // zoom was adjusted, so keep old lonlat to avoid panning │ │ │ │ │ - lonlat = this.getCenter(); │ │ │ │ │ - } │ │ │ │ │ - // dragging is false by default │ │ │ │ │ - var dragging = options.dragging || this.dragging; │ │ │ │ │ - // forceZoomChange is false by default │ │ │ │ │ - var forceZoomChange = options.forceZoomChange; │ │ │ │ │ - │ │ │ │ │ - if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) { │ │ │ │ │ - lonlat = this.maxExtent.getCenterLonLat(); │ │ │ │ │ - this.center = lonlat.clone(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.restrictedExtent != null) { │ │ │ │ │ - // In 3.0, decide if we want to change interpretation of maxExtent. │ │ │ │ │ - if (lonlat == null) { │ │ │ │ │ - lonlat = this.center; │ │ │ │ │ - } │ │ │ │ │ - if (zoom == null) { │ │ │ │ │ - zoom = this.getZoom(); │ │ │ │ │ - } │ │ │ │ │ - var resolution = this.getResolutionForZoom(zoom); │ │ │ │ │ - var extent = this.calculateBounds(lonlat, resolution); │ │ │ │ │ - if (!this.restrictedExtent.containsBounds(extent)) { │ │ │ │ │ - var maxCenter = this.restrictedExtent.getCenterLonLat(); │ │ │ │ │ - if (extent.getWidth() > this.restrictedExtent.getWidth()) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(maxCenter.lon, lonlat.lat); │ │ │ │ │ - } else if (extent.left < this.restrictedExtent.left) { │ │ │ │ │ - lonlat = lonlat.add(this.restrictedExtent.left - │ │ │ │ │ - extent.left, 0); │ │ │ │ │ - } else if (extent.right > this.restrictedExtent.right) { │ │ │ │ │ - lonlat = lonlat.add(this.restrictedExtent.right - │ │ │ │ │ - extent.right, 0); │ │ │ │ │ - } │ │ │ │ │ - if (extent.getHeight() > this.restrictedExtent.getHeight()) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lonlat.lon, maxCenter.lat); │ │ │ │ │ - } else if (extent.bottom < this.restrictedExtent.bottom) { │ │ │ │ │ - lonlat = lonlat.add(0, this.restrictedExtent.bottom - │ │ │ │ │ - extent.bottom); │ │ │ │ │ - } else if (extent.top > this.restrictedExtent.top) { │ │ │ │ │ - lonlat = lonlat.add(0, this.restrictedExtent.top - │ │ │ │ │ - extent.top); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + var vertices = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + Array.prototype.push.apply( │ │ │ │ │ + vertices, this.components[i].getVertices(nodes) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return vertices; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var zoomChanged = forceZoomChange || ( │ │ │ │ │ - (this.isValidZoomLevel(zoom)) && │ │ │ │ │ - (zoom != this.getZoom())); │ │ │ │ │ │ │ │ │ │ - var centerChanged = (this.isValidLonLat(lonlat)) && │ │ │ │ │ - (!lonlat.equals(this.center)); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // if neither center nor zoom will change, no need to do anything │ │ │ │ │ - if (zoomChanged || centerChanged || dragging) { │ │ │ │ │ - dragging || this.events.triggerEvent("movestart", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - }); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - if (centerChanged) { │ │ │ │ │ - if (!zoomChanged && this.center) { │ │ │ │ │ - // if zoom hasnt changed, just slide layerContainer │ │ │ │ │ - // (must be done before setting this.center to new value) │ │ │ │ │ - this.centerLayerContainer(lonlat); │ │ │ │ │ - } │ │ │ │ │ - this.center = lonlat.clone(); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - var res = zoomChanged ? │ │ │ │ │ - this.getResolutionForZoom(zoom) : this.getResolution(); │ │ │ │ │ - // (re)set the layerContainerDiv's location │ │ │ │ │ - if (zoomChanged || this.layerContainerOrigin == null) { │ │ │ │ │ - this.layerContainerOrigin = this.getCachedCenter(); │ │ │ │ │ - this.layerContainerOriginPx.x = 0; │ │ │ │ │ - this.layerContainerOriginPx.y = 0; │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - var maxExtent = this.getMaxExtent({ │ │ │ │ │ - restricted: true │ │ │ │ │ - }); │ │ │ │ │ - var maxExtentCenter = maxExtent.getCenterLonLat(); │ │ │ │ │ - var lonDelta = this.center.lon - maxExtentCenter.lon; │ │ │ │ │ - var latDelta = maxExtentCenter.lat - this.center.lat; │ │ │ │ │ - var extentWidth = Math.round(maxExtent.getWidth() / res); │ │ │ │ │ - var extentHeight = Math.round(maxExtent.getHeight() / res); │ │ │ │ │ - this.minPx = { │ │ │ │ │ - x: (this.size.w - extentWidth) / 2 - lonDelta / res, │ │ │ │ │ - y: (this.size.h - extentHeight) / 2 - latDelta / res │ │ │ │ │ - }; │ │ │ │ │ - this.maxPx = { │ │ │ │ │ - x: this.minPx.x + Math.round(maxExtent.getWidth() / res), │ │ │ │ │ - y: this.minPx.y + Math.round(maxExtent.getHeight() / res) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * MultiPoint is a collection of Points. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.MultiPoint = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ - if (zoomChanged) { │ │ │ │ │ - this.zoom = zoom; │ │ │ │ │ - this.resolution = res; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null value means the │ │ │ │ │ + * component types are not restricted. │ │ │ │ │ + */ │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ - var bounds = this.getExtent(); │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * Create a new MultiPoint Geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - //send the move call to the baselayer and all the overlays │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addPoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be added │ │ │ │ │ + * index - {Integer} Optional index │ │ │ │ │ + */ │ │ │ │ │ + addPoint: function(point, index) { │ │ │ │ │ + this.addComponent(point, index); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.baseLayer.visibility) { │ │ │ │ │ - this.baseLayer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ - options.dragging || this.baseLayer.events.triggerEvent( │ │ │ │ │ - "moveend", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removePoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be removed │ │ │ │ │ + */ │ │ │ │ │ + removePoint: function(point) { │ │ │ │ │ + this.removeComponent(point); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - bounds = this.baseLayer.getExtent(); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Curve.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer !== this.baseLayer && !layer.isBaseLayer) { │ │ │ │ │ - var inRange = layer.calculateInRange(); │ │ │ │ │ - if (layer.inRange != inRange) { │ │ │ │ │ - // the inRange property has changed. If the layer is │ │ │ │ │ - // no longer in range, we turn it off right away. If │ │ │ │ │ - // the layer is no longer out of range, the moveTo │ │ │ │ │ - // call below will turn on the layer. │ │ │ │ │ - layer.inRange = inRange; │ │ │ │ │ - if (!inRange) { │ │ │ │ │ - layer.display(false); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: layer, │ │ │ │ │ - property: "visibility" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (inRange && layer.visibility) { │ │ │ │ │ - layer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ - options.dragging || layer.events.triggerEvent( │ │ │ │ │ - "moveend", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - this.events.triggerEvent("move"); │ │ │ │ │ - dragging || this.events.triggerEvent("moveend"); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (zoomChanged) { │ │ │ │ │ - //redraw popups │ │ │ │ │ - for (var i = 0, len = this.popups.length; i < len; i++) { │ │ │ │ │ - this.popups[i].updatePosition(); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("zoomend"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Curve │ │ │ │ │ + * A Curve is a MultiPoint, whose points are assumed to be connected. To │ │ │ │ │ + * this end, we provide a "getLength()" function, which iterates through │ │ │ │ │ + * the points, summing the distances between them. │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: centerLayerContainer │ │ │ │ │ - * This function takes care to recenter the layerContainerDiv. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null │ │ │ │ │ + * value means the component types are not restricted. │ │ │ │ │ */ │ │ │ │ │ - centerLayerContainer: function(lonlat) { │ │ │ │ │ - var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin); │ │ │ │ │ - var newPx = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ - │ │ │ │ │ - if ((originPx != null) && (newPx != null)) { │ │ │ │ │ - var oldLeft = this.layerContainerOriginPx.x; │ │ │ │ │ - var oldTop = this.layerContainerOriginPx.y; │ │ │ │ │ - var newLeft = Math.round(originPx.x - newPx.x); │ │ │ │ │ - var newTop = Math.round(originPx.y - newPx.y); │ │ │ │ │ - this.applyTransform( │ │ │ │ │ - (this.layerContainerOriginPx.x = newLeft), │ │ │ │ │ - (this.layerContainerOriginPx.y = newTop)); │ │ │ │ │ - var dx = oldLeft - newLeft; │ │ │ │ │ - var dy = oldTop - newTop; │ │ │ │ │ - this.minPx.x -= dx; │ │ │ │ │ - this.maxPx.x -= dx; │ │ │ │ │ - this.minPx.y -= dy; │ │ │ │ │ - this.maxPx.y -= dy; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isValidZoomLevel │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoomLevel - {Integer} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the zoom level passed in is non-null and │ │ │ │ │ - * within the min/max range of zoom levels. │ │ │ │ │ + * point - {Array()} │ │ │ │ │ */ │ │ │ │ │ - isValidZoomLevel: function(zoomLevel) { │ │ │ │ │ - return ((zoomLevel != null) && │ │ │ │ │ - (zoomLevel >= 0) && │ │ │ │ │ - (zoomLevel < this.getNumZoomLevels())); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isValidLonLat │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the lonlat passed in is non-null and within │ │ │ │ │ - * the maxExtent bounds │ │ │ │ │ + * {Float} The length of the curve │ │ │ │ │ */ │ │ │ │ │ - isValidLonLat: function(lonlat) { │ │ │ │ │ - var valid = false; │ │ │ │ │ - if (lonlat != null) { │ │ │ │ │ - var maxExtent = this.getMaxExtent(); │ │ │ │ │ - var worldBounds = this.baseLayer.wrapDateLine && maxExtent; │ │ │ │ │ - valid = maxExtent.containsLonLat(lonlat, { │ │ │ │ │ - worldBounds: worldBounds │ │ │ │ │ - }); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + if (this.components && (this.components.length > 1)) { │ │ │ │ │ + for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i - 1].distanceTo(this.components[i]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return valid; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Layer Options */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Accessor functions to Layer Options parameters */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getProjection │ │ │ │ │ - * This method returns a string representing the projection. In │ │ │ │ │ - * the case of projection support, this will be the srsCode which │ │ │ │ │ - * is loaded -- otherwise it will simply be the string value that │ │ │ │ │ - * was passed to the projection at startup. │ │ │ │ │ + * APIMethod: getGeodesicLength │ │ │ │ │ + * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ * │ │ │ │ │ - * FIXME: In 3.0, we will remove getProjectionObject, and instead │ │ │ │ │ - * return a Projection object from this function. │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The Projection string from the base layer or null. │ │ │ │ │ - */ │ │ │ │ │ - getProjection: function() { │ │ │ │ │ - var projection = this.getProjectionObject(); │ │ │ │ │ - return projection ? projection.getCode() : null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getProjectionObject │ │ │ │ │ - * Returns the projection obect from the baselayer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The Projection of the base layer. │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - getProjectionObject: function() { │ │ │ │ │ - var projection = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - projection = this.baseLayer.projection; │ │ │ │ │ + getGeodesicLength: function(projection) { │ │ │ │ │ + var geom = this; // so we can work with a clone if needed │ │ │ │ │ + if (projection) { │ │ │ │ │ + var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + if (!gg.equals(projection)) { │ │ │ │ │ + geom = this.clone().transform(projection, gg); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return projection; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getMaxResolution │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The Map's Maximum Resolution │ │ │ │ │ - */ │ │ │ │ │ - getMaxResolution: function() { │ │ │ │ │ - var maxResolution = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - maxResolution = this.baseLayer.maxResolution; │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + if (geom.components && (geom.components.length > 1)) { │ │ │ │ │ + var p1, p2; │ │ │ │ │ + for (var i = 1, len = geom.components.length; i < len; i++) { │ │ │ │ │ + p1 = geom.components[i - 1]; │ │ │ │ │ + p2 = geom.components[i]; │ │ │ │ │ + // this returns km and requires lon/lat properties │ │ │ │ │ + length += OpenLayers.Util.distVincenty({ │ │ │ │ │ + lon: p1.x, │ │ │ │ │ + lat: p1.y │ │ │ │ │ + }, { │ │ │ │ │ + lon: p2.x, │ │ │ │ │ + lat: p2.y │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return maxResolution; │ │ │ │ │ + // convert to m │ │ │ │ │ + return length * 1000; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/LineString.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.LineString │ │ │ │ │ + * A LineString is a Curve which, once two points have been added to it, can │ │ │ │ │ + * never be less than two points long. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getMaxExtent │ │ │ │ │ + * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ + * Create a new LineString geometry │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Allowed Options: │ │ │ │ │ - * restricted - {Boolean} If true, returns restricted extent (if it is │ │ │ │ │ - * available.) │ │ │ │ │ + * points - {Array()} An array of points used to │ │ │ │ │ + * generate the linestring │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The maxExtent property as set on the current │ │ │ │ │ - * baselayer, unless the 'restricted' option is set, in which case │ │ │ │ │ - * the 'restrictedExtent' option from the map is returned (if it │ │ │ │ │ - * is set). │ │ │ │ │ */ │ │ │ │ │ - getMaxExtent: function(options) { │ │ │ │ │ - var maxExtent = null; │ │ │ │ │ - if (options && options.restricted && this.restrictedExtent) { │ │ │ │ │ - maxExtent = this.restrictedExtent; │ │ │ │ │ - } else if (this.baseLayer != null) { │ │ │ │ │ - maxExtent = this.baseLayer.maxExtent; │ │ │ │ │ - } │ │ │ │ │ - return maxExtent; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getNumZoomLevels │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The total number of zoom levels that can be displayed by the │ │ │ │ │ - * current baseLayer. │ │ │ │ │ + * APIMethod: removeComponent │ │ │ │ │ + * Only allows removal of a point if there are three or more points in │ │ │ │ │ + * the linestring. (otherwise the result would be just a single point) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} The point to be removed │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - getNumZoomLevels: function() { │ │ │ │ │ - var numZoomLevels = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - numZoomLevels = this.baseLayer.numZoomLevels; │ │ │ │ │ + removeComponent: function(point) { │ │ │ │ │ + var removed = this.components && (this.components.length > 2); │ │ │ │ │ + if (removed) { │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ } │ │ │ │ │ - return numZoomLevels; │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions, all publicly exposed */ │ │ │ │ │ - /* in the API?, are all merely wrappers to the */ │ │ │ │ │ - /* the same calls on whatever layer is set as */ │ │ │ │ │ - /* the current base layer */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Test for instersection between two geometries. This is a cheapo │ │ │ │ │ + * implementation of the Bently-Ottmann algorigithm. It doesn't │ │ │ │ │ + * really keep track of a sweep line data structure. It is closer │ │ │ │ │ + * to the brute force method, except that segments are sorted and │ │ │ │ │ + * potential intersections are only calculated when bounding boxes │ │ │ │ │ + * intersect. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Boolean} The input geometry intersects this geometry. │ │ │ │ │ */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - var extent = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - extent = this.baseLayer.getExtent(); │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + var type = geometry.CLASS_NAME; │ │ │ │ │ + if (type == "OpenLayers.Geometry.LineString" || │ │ │ │ │ + type == "OpenLayers.Geometry.LinearRing" || │ │ │ │ │ + type == "OpenLayers.Geometry.Point") { │ │ │ │ │ + var segs1 = this.getSortedSegments(); │ │ │ │ │ + var segs2; │ │ │ │ │ + if (type == "OpenLayers.Geometry.Point") { │ │ │ │ │ + segs2 = [{ │ │ │ │ │ + x1: geometry.x, │ │ │ │ │ + y1: geometry.y, │ │ │ │ │ + x2: geometry.x, │ │ │ │ │ + y2: geometry.y │ │ │ │ │ + }]; │ │ │ │ │ + } else { │ │ │ │ │ + segs2 = geometry.getSortedSegments(); │ │ │ │ │ + } │ │ │ │ │ + var seg1, seg1x1, seg1x2, seg1y1, seg1y2, │ │ │ │ │ + seg2, seg2y1, seg2y2; │ │ │ │ │ + // sweep right │ │ │ │ │ + outer: for (var i = 0, len = segs1.length; i < len; ++i) { │ │ │ │ │ + seg1 = segs1[i]; │ │ │ │ │ + seg1x1 = seg1.x1; │ │ │ │ │ + seg1x2 = seg1.x2; │ │ │ │ │ + seg1y1 = seg1.y1; │ │ │ │ │ + seg1y2 = seg1.y2; │ │ │ │ │ + inner: for (var j = 0, jlen = segs2.length; j < jlen; ++j) { │ │ │ │ │ + seg2 = segs2[j]; │ │ │ │ │ + if (seg2.x1 > seg1x2) { │ │ │ │ │ + // seg1 still left of seg2 │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + if (seg2.x2 < seg1x1) { │ │ │ │ │ + // seg2 still left of seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + seg2y1 = seg2.y1; │ │ │ │ │ + seg2y2 = seg2.y2; │ │ │ │ │ + if (Math.min(seg2y1, seg2y2) > Math.max(seg1y1, seg1y2)) { │ │ │ │ │ + // seg2 above seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (Math.max(seg2y1, seg2y2) < Math.min(seg1y1, seg1y2)) { │ │ │ │ │ + // seg2 below seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Geometry.segmentsIntersect(seg1, seg2)) { │ │ │ │ │ + intersect = true; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ } │ │ │ │ │ - return extent; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ - * │ │ │ │ │ + * Method: getSortedSegments │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The current resolution of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Array} An array of segment objects. Segment objects have properties │ │ │ │ │ + * x1, y1, x2, and y2. The start point is represented by x1 and y1. │ │ │ │ │ + * The end point is represented by x2 and y2. Start and end are │ │ │ │ │ + * ordered so that x1 < x2. │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var resolution = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - resolution = this.baseLayer.getResolution(); │ │ │ │ │ - } else if (this.allOverlays === true && this.layers.length > 0) { │ │ │ │ │ - // while adding the 1st layer to the map in allOverlays mode, │ │ │ │ │ - // this.baseLayer is not set yet when we need the resolution │ │ │ │ │ - // for calculateInRange. │ │ │ │ │ - resolution = this.layers[0].getResolution(); │ │ │ │ │ + getSortedSegments: function() { │ │ │ │ │ + var numSeg = this.components.length - 1; │ │ │ │ │ + var segments = new Array(numSeg), │ │ │ │ │ + point1, point2; │ │ │ │ │ + for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ + point1 = this.components[i]; │ │ │ │ │ + point2 = this.components[i + 1]; │ │ │ │ │ + if (point1.x < point2.x) { │ │ │ │ │ + segments[i] = { │ │ │ │ │ + x1: point1.x, │ │ │ │ │ + y1: point1.y, │ │ │ │ │ + x2: point2.x, │ │ │ │ │ + y2: point2.y │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + segments[i] = { │ │ │ │ │ + x1: point2.x, │ │ │ │ │ + y1: point2.y, │ │ │ │ │ + x2: point1.x, │ │ │ │ │ + y2: point1.y │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getUnits │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The current units of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getUnits: function() { │ │ │ │ │ - var units = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - units = this.baseLayer.units; │ │ │ │ │ + // more efficient to define this somewhere static │ │ │ │ │ + function byX1(seg1, seg2) { │ │ │ │ │ + return seg1.x1 - seg2.x1; │ │ │ │ │ } │ │ │ │ │ - return units; │ │ │ │ │ + return segments.sort(byX1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getScale │ │ │ │ │ - * │ │ │ │ │ + * Method: splitWithSegment │ │ │ │ │ + * Split this geometry with the given segment. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * seg - {Object} An object with x1, y1, x2, and y2 properties referencing │ │ │ │ │ + * segment endpoint coordinates. │ │ │ │ │ + * options - {Object} Properties of this object will be used to determine │ │ │ │ │ + * how the split is conducted. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ + * true. If false, a vertex on the source segment must be within the │ │ │ │ │ + * tolerance distance of the intersection to be considered a split. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ + * within the tolerance distance of one of the source segment's │ │ │ │ │ + * endpoints will be assumed to occur at the endpoint. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The current scale denominator of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Object} An object with *lines* and *points* properties. If the given │ │ │ │ │ + * segment intersects this linestring, the lines array will reference │ │ │ │ │ + * geometries that result from the split. The points array will contain │ │ │ │ │ + * all intersection points. Intersection points are sorted along the │ │ │ │ │ + * segment (in order from x1,y1 to x2,y2). │ │ │ │ │ */ │ │ │ │ │ - getScale: function() { │ │ │ │ │ - var scale = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - var res = this.getResolution(); │ │ │ │ │ - var units = this.baseLayer.units; │ │ │ │ │ - scale = OpenLayers.Util.getScaleFromResolution(res, units); │ │ │ │ │ + splitWithSegment: function(seg, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var tolerance = options && options.tolerance; │ │ │ │ │ + var lines = []; │ │ │ │ │ + var verts = this.getVertices(); │ │ │ │ │ + var points = []; │ │ │ │ │ + var intersections = []; │ │ │ │ │ + var split = false; │ │ │ │ │ + var vert1, vert2, point; │ │ │ │ │ + var node, vertex, target; │ │ │ │ │ + var interOptions = { │ │ │ │ │ + point: true, │ │ │ │ │ + tolerance: tolerance │ │ │ │ │ + }; │ │ │ │ │ + var result = null; │ │ │ │ │ + for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ + vert1 = verts[i]; │ │ │ │ │ + points.push(vert1.clone()); │ │ │ │ │ + vert2 = verts[i + 1]; │ │ │ │ │ + target = { │ │ │ │ │ + x1: vert1.x, │ │ │ │ │ + y1: vert1.y, │ │ │ │ │ + x2: vert2.x, │ │ │ │ │ + y2: vert2.y │ │ │ │ │ + }; │ │ │ │ │ + point = OpenLayers.Geometry.segmentsIntersect( │ │ │ │ │ + seg, target, interOptions │ │ │ │ │ + ); │ │ │ │ │ + if (point instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + if ((point.x === seg.x1 && point.y === seg.y1) || │ │ │ │ │ + (point.x === seg.x2 && point.y === seg.y2) || │ │ │ │ │ + point.equals(vert1) || point.equals(vert2)) { │ │ │ │ │ + vertex = true; │ │ │ │ │ + } else { │ │ │ │ │ + vertex = false; │ │ │ │ │ + } │ │ │ │ │ + if (vertex || edge) { │ │ │ │ │ + // push intersections different than the previous │ │ │ │ │ + if (!point.equals(intersections[intersections.length - 1])) { │ │ │ │ │ + intersections.push(point.clone()); │ │ │ │ │ + } │ │ │ │ │ + if (i === 0) { │ │ │ │ │ + if (point.equals(vert1)) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (point.equals(vert2)) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + split = true; │ │ │ │ │ + if (!point.equals(vert1)) { │ │ │ │ │ + points.push(point); │ │ │ │ │ + } │ │ │ │ │ + lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + points = [point.clone()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return scale; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForExtent │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} A suitable zoom level for the specified bounds. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForExtent: function(bounds, closest) { │ │ │ │ │ - var zoom = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - zoom = this.baseLayer.getZoomForExtent(bounds, closest); │ │ │ │ │ + if (split) { │ │ │ │ │ + points.push(vert2.clone()); │ │ │ │ │ + lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} A suitable resolution for the specified zoom. If no baselayer │ │ │ │ │ - * is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getResolutionForZoom: function(zoom) { │ │ │ │ │ - var resolution = null; │ │ │ │ │ - if (this.baseLayer) { │ │ │ │ │ - resolution = this.baseLayer.getResolutionForZoom(zoom); │ │ │ │ │ + if (intersections.length > 0) { │ │ │ │ │ + // sort intersections along segment │ │ │ │ │ + var xDir = seg.x1 < seg.x2 ? 1 : -1; │ │ │ │ │ + var yDir = seg.y1 < seg.y2 ? 1 : -1; │ │ │ │ │ + result = { │ │ │ │ │ + lines: lines, │ │ │ │ │ + points: intersections.sort(function(p1, p2) { │ │ │ │ │ + return (xDir * p1.x - xDir * p2.x) || (yDir * p1.y - yDir * p2.y); │ │ │ │ │ + }) │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getZoomForResolution │ │ │ │ │ + * Method: split │ │ │ │ │ + * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * resolution - {Float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ - * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ - * resolution is actually smaller than we would have desired (if this │ │ │ │ │ - * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ - * the returned zoom index might not actually contain the entire │ │ │ │ │ - * extent specified... but it'll be close). │ │ │ │ │ - * Default is false. │ │ │ │ │ + * target - {} The target geometry. │ │ │ │ │ + * options - {Object} Properties of this object will be used to determine │ │ │ │ │ + * how the split is conducted. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ + * geometry. Default is false. │ │ │ │ │ + * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ + * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ + * distance of the intersection to be considered a split. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ + * within the tolerance distance of an existing vertex on the source │ │ │ │ │ + * will be assumed to occur at the vertex. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Integer} A suitable zoom level for the specified resolution. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForResolution: function(resolution, closest) { │ │ │ │ │ - var zoom = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - zoom = this.baseLayer.getZoomForResolution(resolution, closest); │ │ │ │ │ - } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Zooming Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions, all publicly exposed */ │ │ │ │ │ - /* in the API, are all merely wrappers to the */ │ │ │ │ │ - /* the setCenter() function */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomTo │ │ │ │ │ - * Zoom to a specific zoom level. Zooming will be animated unless the map │ │ │ │ │ - * is configured with {zoomMethod: null}. To zoom without animation, use │ │ │ │ │ - * without a lonlat argument. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zoom - {Integer} │ │ │ │ │ + * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ + * result from splitting the target with the source geometry. The │ │ │ │ │ + * source and target geometry will remain unmodified. If no split │ │ │ │ │ + * results, null will be returned. If mutual is true and a split │ │ │ │ │ + * results, return will be an array of two arrays - the first will be │ │ │ │ │ + * all geometries that result from splitting the source geometry and │ │ │ │ │ + * the second will be all geometries that result from splitting the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - zoomTo: function(zoom, xy) { │ │ │ │ │ - // non-API arguments: │ │ │ │ │ - // xy - {} optional zoom origin │ │ │ │ │ - │ │ │ │ │ - var map = this; │ │ │ │ │ - if (map.isValidZoomLevel(zoom)) { │ │ │ │ │ - if (map.baseLayer.wrapDateLine) { │ │ │ │ │ - zoom = map.adjustZoom(zoom); │ │ │ │ │ - } │ │ │ │ │ - if (map.zoomTween) { │ │ │ │ │ - var currentRes = map.getResolution(), │ │ │ │ │ - targetRes = map.getResolutionForZoom(zoom), │ │ │ │ │ - start = { │ │ │ │ │ - scale: 1 │ │ │ │ │ - }, │ │ │ │ │ - end = { │ │ │ │ │ - scale: currentRes / targetRes │ │ │ │ │ - }; │ │ │ │ │ - if (map.zoomTween.playing && map.zoomTween.duration < 3 * map.zoomDuration) { │ │ │ │ │ - // update the end scale, and reuse the running zoomTween │ │ │ │ │ - map.zoomTween.finish = { │ │ │ │ │ - scale: map.zoomTween.finish.scale * end.scale │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - if (!xy) { │ │ │ │ │ - var size = map.getSize(); │ │ │ │ │ - xy = { │ │ │ │ │ - x: size.w / 2, │ │ │ │ │ - y: size.h / 2 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - map.zoomTween.start(start, end, map.zoomDuration, { │ │ │ │ │ - minFrameRate: 50, // don't spend much time zooming │ │ │ │ │ - callbacks: { │ │ │ │ │ - eachStep: function(data) { │ │ │ │ │ - var containerOrigin = map.layerContainerOriginPx, │ │ │ │ │ - scale = data.scale, │ │ │ │ │ - dx = ((scale - 1) * (containerOrigin.x - xy.x)) | 0, │ │ │ │ │ - dy = ((scale - 1) * (containerOrigin.y - xy.y)) | 0; │ │ │ │ │ - map.applyTransform(containerOrigin.x + dx, containerOrigin.y + dy, scale); │ │ │ │ │ - }, │ │ │ │ │ - done: function(data) { │ │ │ │ │ - map.applyTransform(); │ │ │ │ │ - var resolution = map.getResolution() / data.scale, │ │ │ │ │ - zoom = map.getZoomForResolution(resolution, true) │ │ │ │ │ - map.moveTo(map.getZoomTargetCenter(xy, resolution), zoom, true); │ │ │ │ │ + split: function(target, options) { │ │ │ │ │ + var results = null; │ │ │ │ │ + var mutual = options && options.mutual; │ │ │ │ │ + var sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ + if (target instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ + var verts = this.getVertices(); │ │ │ │ │ + var vert1, vert2, seg, splits, lines, point; │ │ │ │ │ + var points = []; │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ + vert1 = verts[i]; │ │ │ │ │ + vert2 = verts[i + 1]; │ │ │ │ │ + seg = { │ │ │ │ │ + x1: vert1.x, │ │ │ │ │ + y1: vert1.y, │ │ │ │ │ + x2: vert2.x, │ │ │ │ │ + y2: vert2.y │ │ │ │ │ + }; │ │ │ │ │ + targetParts = targetParts || [target]; │ │ │ │ │ + if (mutual) { │ │ │ │ │ + points.push(vert1.clone()); │ │ │ │ │ + } │ │ │ │ │ + for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ + splits = targetParts[j].splitWithSegment(seg, options); │ │ │ │ │ + if (splits) { │ │ │ │ │ + // splice in new features │ │ │ │ │ + lines = splits.lines; │ │ │ │ │ + if (lines.length > 0) { │ │ │ │ │ + lines.unshift(j, 1); │ │ │ │ │ + Array.prototype.splice.apply(targetParts, lines); │ │ │ │ │ + j += lines.length - 2; │ │ │ │ │ + } │ │ │ │ │ + if (mutual) { │ │ │ │ │ + for (var k = 0, len = splits.points.length; k < len; ++k) { │ │ │ │ │ + point = splits.points[k]; │ │ │ │ │ + if (!point.equals(vert1)) { │ │ │ │ │ + points.push(point); │ │ │ │ │ + sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + if (point.equals(vert2)) { │ │ │ │ │ + points = []; │ │ │ │ │ + } else { │ │ │ │ │ + points = [point.clone()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - var center = xy ? │ │ │ │ │ - map.getZoomTargetCenter(xy, map.getResolutionForZoom(zoom)) : │ │ │ │ │ - null; │ │ │ │ │ - map.setCenter(center, zoom); │ │ │ │ │ } │ │ │ │ │ + if (mutual && sourceParts.length > 0 && points.length > 0) { │ │ │ │ │ + points.push(vert2.clone()); │ │ │ │ │ + sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + results = target.splitWith(this, options); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomIn │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomIn: function() { │ │ │ │ │ - this.zoomTo(this.getZoom() + 1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomOut │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomOut: function() { │ │ │ │ │ - this.zoomTo(this.getZoom() - 1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToExtent │ │ │ │ │ - * Zoom to the passed in bounds, recenter │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomToExtent: function(bounds, closest) { │ │ │ │ │ - if (!(bounds instanceof OpenLayers.Bounds)) { │ │ │ │ │ - bounds = new OpenLayers.Bounds(bounds); │ │ │ │ │ + if (targetParts && targetParts.length > 1) { │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + targetParts = []; │ │ │ │ │ } │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - if (this.baseLayer.wrapDateLine) { │ │ │ │ │ - var maxExtent = this.getMaxExtent(); │ │ │ │ │ - │ │ │ │ │ - //fix straddling bounds (in the case of a bbox that straddles the │ │ │ │ │ - // dateline, it's left and right boundaries will appear backwards. │ │ │ │ │ - // we fix this by allowing a right value that is greater than the │ │ │ │ │ - // max value at the dateline -- this allows us to pass a valid │ │ │ │ │ - // bounds to calculate zoom) │ │ │ │ │ - // │ │ │ │ │ - bounds = bounds.clone(); │ │ │ │ │ - while (bounds.right < bounds.left) { │ │ │ │ │ - bounds.right += maxExtent.getWidth(); │ │ │ │ │ + if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (targetSplit || sourceSplit) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + results = [sourceParts, targetParts]; │ │ │ │ │ + } else { │ │ │ │ │ + results = targetParts; │ │ │ │ │ } │ │ │ │ │ - //if the bounds was straddling (see above), then the center point │ │ │ │ │ - // we got from it was wrong. So we take our new bounds and ask it │ │ │ │ │ - // for the center. │ │ │ │ │ - // │ │ │ │ │ - center = bounds.getCenterLonLat().wrapDateLine(maxExtent); │ │ │ │ │ } │ │ │ │ │ - this.setCenter(center, this.getZoomForExtent(bounds, closest)); │ │ │ │ │ + return results; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToMaxExtent │ │ │ │ │ - * Zoom to the full extent and recenter. │ │ │ │ │ + /** │ │ │ │ │ + * Method: splitWith │ │ │ │ │ + * Split this geometry (the target) with the given geometry (the source). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Allowed Options: │ │ │ │ │ - * restricted - {Boolean} True to zoom to restricted extent if it is │ │ │ │ │ - * set. Defaults to true. │ │ │ │ │ - */ │ │ │ │ │ - zoomToMaxExtent: function(options) { │ │ │ │ │ - //restricted is true by default │ │ │ │ │ - var restricted = (options) ? options.restricted : true; │ │ │ │ │ - │ │ │ │ │ - var maxExtent = this.getMaxExtent({ │ │ │ │ │ - 'restricted': restricted │ │ │ │ │ - }); │ │ │ │ │ - this.zoomToExtent(maxExtent); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToScale │ │ │ │ │ - * Zoom to a specified scale │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified scale. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * geometry - {} A geometry used to split this │ │ │ │ │ + * geometry (the source). │ │ │ │ │ + * options - {Object} Properties of this object will be used to determine │ │ │ │ │ + * how the split is conducted. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ + * geometry. Default is false. │ │ │ │ │ + * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ + * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ + * distance of the intersection to be considered a split. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ + * within the tolerance distance of an existing vertex on the source │ │ │ │ │ + * will be assumed to occur at the vertex. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ + * result from splitting the target with the source geometry. The │ │ │ │ │ + * source and target geometry will remain unmodified. If no split │ │ │ │ │ + * results, null will be returned. If mutual is true and a split │ │ │ │ │ + * results, return will be an array of two arrays - the first will be │ │ │ │ │ + * all geometries that result from splitting the source geometry and │ │ │ │ │ + * the second will be all geometries that result from splitting the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - zoomToScale: function(scale, closest) { │ │ │ │ │ - var res = OpenLayers.Util.getResolutionFromScale(scale, │ │ │ │ │ - this.baseLayer.units); │ │ │ │ │ - │ │ │ │ │ - var halfWDeg = (this.size.w * res) / 2; │ │ │ │ │ - var halfHDeg = (this.size.h * res) / 2; │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ + splitWith: function(geometry, options) { │ │ │ │ │ + return geometry.split(this, options); │ │ │ │ │ │ │ │ │ │ - var extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ - center.lat - halfHDeg, │ │ │ │ │ - center.lon + halfWDeg, │ │ │ │ │ - center.lat + halfHDeg); │ │ │ │ │ - this.zoomToExtent(extent, closest); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Translation Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions translate between */ │ │ │ │ │ - /* LonLat, LayerPx, and ViewPortPx */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: LonLat <-> ViewPortPx │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromViewPortPx │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ - * an object with a 'x' │ │ │ │ │ - * and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ - * port , translated into lon/lat │ │ │ │ │ - * by the current base layer. │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + var vertices; │ │ │ │ │ + if (nodes === true) { │ │ │ │ │ + vertices = [ │ │ │ │ │ + this.components[0], │ │ │ │ │ + this.components[this.components.length - 1] │ │ │ │ │ + ]; │ │ │ │ │ + } else if (nodes === false) { │ │ │ │ │ + vertices = this.components.slice(1, this.components.length - 1); │ │ │ │ │ + } else { │ │ │ │ │ + vertices = this.components.slice(); │ │ │ │ │ } │ │ │ │ │ - return lonlat; │ │ │ │ │ + return vertices; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * , translated into view port │ │ │ │ │ - * pixels by the current base layer. │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ - var px = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - px = this.baseLayer.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var result, best = {}; │ │ │ │ │ + var min = Number.POSITIVE_INFINITY; │ │ │ │ │ + if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + var segs = this.getSortedSegments(); │ │ │ │ │ + var x = geometry.x; │ │ │ │ │ + var y = geometry.y; │ │ │ │ │ + var seg; │ │ │ │ │ + for (var i = 0, len = segs.length; i < len; ++i) { │ │ │ │ │ + seg = segs[i]; │ │ │ │ │ + result = OpenLayers.Geometry.distanceToSegment(geometry, seg); │ │ │ │ │ + if (result.distance < min) { │ │ │ │ │ + min = result.distance; │ │ │ │ │ + best = result; │ │ │ │ │ + if (min === 0) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // if distance increases and we cross y0 to the right of x0, no need to keep looking. │ │ │ │ │ + if (seg.x2 > x && ((y > seg.y1 && y < seg.y2) || (y < seg.y1 && y > seg.y2))) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: best.distance, │ │ │ │ │ + x0: best.x, │ │ │ │ │ + y0: best.y, │ │ │ │ │ + x1: x, │ │ │ │ │ + y1: y │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + best = best.distance; │ │ │ │ │ + } │ │ │ │ │ + } else if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ + var segs0 = this.getSortedSegments(); │ │ │ │ │ + var segs1 = geometry.getSortedSegments(); │ │ │ │ │ + var seg0, seg1, intersection, x0, y0; │ │ │ │ │ + var len1 = segs1.length; │ │ │ │ │ + var interOptions = { │ │ │ │ │ + point: true │ │ │ │ │ + }; │ │ │ │ │ + outer: for (var i = 0, len = segs0.length; i < len; ++i) { │ │ │ │ │ + seg0 = segs0[i]; │ │ │ │ │ + x0 = seg0.x1; │ │ │ │ │ + y0 = seg0.y1; │ │ │ │ │ + for (var j = 0; j < len1; ++j) { │ │ │ │ │ + seg1 = segs1[j]; │ │ │ │ │ + intersection = OpenLayers.Geometry.segmentsIntersect(seg0, seg1, interOptions); │ │ │ │ │ + if (intersection) { │ │ │ │ │ + min = 0; │ │ │ │ │ + best = { │ │ │ │ │ + distance: 0, │ │ │ │ │ + x0: intersection.x, │ │ │ │ │ + y0: intersection.y, │ │ │ │ │ + x1: intersection.x, │ │ │ │ │ + y1: intersection.y │ │ │ │ │ + }; │ │ │ │ │ + break outer; │ │ │ │ │ + } else { │ │ │ │ │ + result = OpenLayers.Geometry.distanceToSegment({ │ │ │ │ │ + x: x0, │ │ │ │ │ + y: y0 │ │ │ │ │ + }, seg1); │ │ │ │ │ + if (result.distance < min) { │ │ │ │ │ + min = result.distance; │ │ │ │ │ + best = { │ │ │ │ │ + distance: min, │ │ │ │ │ + x0: x0, │ │ │ │ │ + y0: y0, │ │ │ │ │ + x1: result.x, │ │ │ │ │ + y1: result.y │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!details) { │ │ │ │ │ + best = best.distance; │ │ │ │ │ + } │ │ │ │ │ + if (min !== 0) { │ │ │ │ │ + // check the final vertex in this line's sorted segments │ │ │ │ │ + if (seg0) { │ │ │ │ │ + result = geometry.distanceTo( │ │ │ │ │ + new OpenLayers.Geometry.Point(seg0.x2, seg0.y2), │ │ │ │ │ + options │ │ │ │ │ + ); │ │ │ │ │ + var dist = details ? result.distance : result; │ │ │ │ │ + if (dist < min) { │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: min, │ │ │ │ │ + x0: result.x1, │ │ │ │ │ + y0: result.y1, │ │ │ │ │ + x1: result.x0, │ │ │ │ │ + y1: result.y0 │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + best = dist; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + best = geometry.distanceTo(this, options); │ │ │ │ │ + // swap since target comes from this line │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: best.distance, │ │ │ │ │ + x0: best.x1, │ │ │ │ │ + y0: best.y1, │ │ │ │ │ + x1: best.x0, │ │ │ │ │ + y1: best.y0 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return px; │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getZoomTargetCenter │ │ │ │ │ + * APIMethod: simplify │ │ │ │ │ + * This function will return a simplified LineString. │ │ │ │ │ + * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ + * │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The zoom origin pixel location on the screen │ │ │ │ │ - * resolution - {Float} The resolution we want to get the center for │ │ │ │ │ + * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The location of the map center after the │ │ │ │ │ - * transformation described by the origin xy and the target resolution. │ │ │ │ │ + * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ */ │ │ │ │ │ - getZoomTargetCenter: function(xy, resolution) { │ │ │ │ │ - var lonlat = null, │ │ │ │ │ - size = this.getSize(), │ │ │ │ │ - deltaX = size.w / 2 - xy.x, │ │ │ │ │ - deltaY = xy.y - size.h / 2, │ │ │ │ │ - zoomPoint = this.getLonLatFromPixel(xy); │ │ │ │ │ - if (zoomPoint) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat( │ │ │ │ │ - zoomPoint.lon + deltaX * resolution, │ │ │ │ │ - zoomPoint.lat + deltaY * resolution │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return lonlat; │ │ │ │ │ - }, │ │ │ │ │ + simplify: function(tolerance) { │ │ │ │ │ + if (this && this !== null) { │ │ │ │ │ + var points = this.getVertices(); │ │ │ │ │ + if (points.length < 3) { │ │ │ │ │ + return this; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // CONVENIENCE TRANSLATION FUNCTIONS FOR API │ │ │ │ │ - // │ │ │ │ │ + var compareNumbers = function(a, b) { │ │ │ │ │ + return (a - b); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLonLatFromPixel │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} An OpenLayers.Pixel or an object with │ │ │ │ │ - * a 'x' and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat corresponding to the given │ │ │ │ │ - * OpenLayers.Pixel, translated into lon/lat by the │ │ │ │ │ - * current base layer │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromPixel: function(px) { │ │ │ │ │ - return this.getLonLatFromViewPortPx(px); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Private function doing the Douglas-Peucker reduction │ │ │ │ │ + */ │ │ │ │ │ + var douglasPeuckerReduction = function(points, firstPoint, lastPoint, tolerance) { │ │ │ │ │ + var maxDistance = 0; │ │ │ │ │ + var indexFarthest = 0; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getPixelFromLonLat │ │ │ │ │ - * Returns a pixel location given a map location. The map location is │ │ │ │ │ - * translated to an integer pixel location (in viewport pixel │ │ │ │ │ - * coordinates) by the current base layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} A map location. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel corresponding to the │ │ │ │ │ - * translated into view port pixels by the current │ │ │ │ │ - * base layer. │ │ │ │ │ - */ │ │ │ │ │ - getPixelFromLonLat: function(lonlat) { │ │ │ │ │ - var px = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ - px.x = Math.round(px.x); │ │ │ │ │ - px.y = Math.round(px.y); │ │ │ │ │ - return px; │ │ │ │ │ - }, │ │ │ │ │ + for (var index = firstPoint, distance; index < lastPoint; index++) { │ │ │ │ │ + distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]); │ │ │ │ │ + if (distance > maxDistance) { │ │ │ │ │ + maxDistance = distance; │ │ │ │ │ + indexFarthest = index; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getGeodesicPixelSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} The pixel to get the geodesic length for. If │ │ │ │ │ - * not provided, the center pixel of the map viewport will be used. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The geodesic size of the pixel in kilometers. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicPixelSize: function(px) { │ │ │ │ │ - var lonlat = px ? this.getLonLatFromPixel(px) : ( │ │ │ │ │ - this.getCachedCenter() || new OpenLayers.LonLat(0, 0)); │ │ │ │ │ - var res = this.getResolution(); │ │ │ │ │ - var left = lonlat.add(-res / 2, 0); │ │ │ │ │ - var right = lonlat.add(res / 2, 0); │ │ │ │ │ - var bottom = lonlat.add(0, -res / 2); │ │ │ │ │ - var top = lonlat.add(0, res / 2); │ │ │ │ │ - var dest = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - var source = this.getProjectionObject() || dest; │ │ │ │ │ - if (!source.equals(dest)) { │ │ │ │ │ - left.transform(source, dest); │ │ │ │ │ - right.transform(source, dest); │ │ │ │ │ - bottom.transform(source, dest); │ │ │ │ │ - top.transform(source, dest); │ │ │ │ │ - } │ │ │ │ │ + if (maxDistance > tolerance && indexFarthest != firstPoint) { │ │ │ │ │ + //Add the largest point that exceeds the tolerance │ │ │ │ │ + pointIndexsToKeep.push(indexFarthest); │ │ │ │ │ + douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance); │ │ │ │ │ + douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - return new OpenLayers.Size( │ │ │ │ │ - OpenLayers.Util.distVincenty(left, right), │ │ │ │ │ - OpenLayers.Util.distVincenty(bottom, top) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Private function calculating the perpendicular distance │ │ │ │ │ + * TODO: check whether OpenLayers.Geometry.LineString::distanceTo() is faster or slower │ │ │ │ │ + */ │ │ │ │ │ + var perpendicularDistance = function(point1, point2, point) { │ │ │ │ │ + //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)| *Area of triangle │ │ │ │ │ + //Base = v((x1-x2)²+(x1-x2)²) *Base of Triangle* │ │ │ │ │ + //Area = .5*Base*H *Solve for height │ │ │ │ │ + //Height = Area/.5/Base │ │ │ │ │ │ │ │ │ │ + var area = Math.abs(0.5 * (point1.x * point2.y + point2.x * point.y + point.x * point1.y - point2.x * point1.y - point.x * point2.y - point1.x * point.y)); │ │ │ │ │ + var bottom = Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)); │ │ │ │ │ + var height = area / bottom * 2; │ │ │ │ │ │ │ │ │ │ + return height; │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: ViewPortPx <-> LayerPx │ │ │ │ │ - // │ │ │ │ │ + var firstPoint = 0; │ │ │ │ │ + var lastPoint = points.length - 1; │ │ │ │ │ + var pointIndexsToKeep = []; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLayerPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layerPx - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Layer Pixel translated into ViewPort Pixel │ │ │ │ │ - * coordinates │ │ │ │ │ - */ │ │ │ │ │ - getViewPortPxFromLayerPx: function(layerPx) { │ │ │ │ │ - var viewPortPx = null; │ │ │ │ │ - if (layerPx != null) { │ │ │ │ │ - var dX = this.layerContainerOriginPx.x; │ │ │ │ │ - var dY = this.layerContainerOriginPx.y; │ │ │ │ │ - viewPortPx = layerPx.add(dX, dY); │ │ │ │ │ - } │ │ │ │ │ - return viewPortPx; │ │ │ │ │ - }, │ │ │ │ │ + //Add the first and last index to the keepers │ │ │ │ │ + pointIndexsToKeep.push(firstPoint); │ │ │ │ │ + pointIndexsToKeep.push(lastPoint); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerPxFromViewPortPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} ViewPort Pixel translated into Layer Pixel │ │ │ │ │ - * coordinates │ │ │ │ │ - */ │ │ │ │ │ - getLayerPxFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var layerPx = null; │ │ │ │ │ - if (viewPortPx != null) { │ │ │ │ │ - var dX = -this.layerContainerOriginPx.x; │ │ │ │ │ - var dY = -this.layerContainerOriginPx.y; │ │ │ │ │ - layerPx = viewPortPx.add(dX, dY); │ │ │ │ │ - if (isNaN(layerPx.x) || isNaN(layerPx.y)) { │ │ │ │ │ - layerPx = null; │ │ │ │ │ + //The first and the last point cannot be the same │ │ │ │ │ + while (points[firstPoint].equals(points[lastPoint])) { │ │ │ │ │ + lastPoint--; │ │ │ │ │ + //Addition: the first point not equal to first point in the LineString is kept as well │ │ │ │ │ + pointIndexsToKeep.push(lastPoint); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - return layerPx; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: LonLat <-> LayerPx │ │ │ │ │ - // │ │ │ │ │ + douglasPeuckerReduction(points, firstPoint, lastPoint, tolerance); │ │ │ │ │ + var returnPoints = []; │ │ │ │ │ + pointIndexsToKeep.sort(compareNumbers); │ │ │ │ │ + for (var index = 0; index < pointIndexsToKeep.length; index++) { │ │ │ │ │ + returnPoints.push(points[pointIndexsToKeep[index]]); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.LineString(returnPoints); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getLonLatFromLayerPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromLayerPx: function(px) { │ │ │ │ │ - //adjust for displacement of layerContainerDiv │ │ │ │ │ - px = this.getViewPortPxFromLayerPx(px); │ │ │ │ │ - return this.getLonLatFromViewPortPx(px); │ │ │ │ │ + } else { │ │ │ │ │ + return this; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerPxFromLonLat │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} lonlat │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * , translated into layer pixels │ │ │ │ │ - * by the current base layer │ │ │ │ │ - */ │ │ │ │ │ - getLayerPxFromLonLat: function(lonlat) { │ │ │ │ │ - //adjust for displacement of layerContainerDiv │ │ │ │ │ - var px = this.getPixelFromLonLat(lonlat); │ │ │ │ │ - return this.getLayerPxFromViewPortPx(px); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: applyTransform │ │ │ │ │ - * Applies the given transform to the . This method has │ │ │ │ │ - * a 2-stage fallback from translate3d/scale3d via translate/scale to plain │ │ │ │ │ - * style.left/style.top, in which case no scaling is supported. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Number} x parameter for the translation. Defaults to the x value of │ │ │ │ │ - * the map's │ │ │ │ │ - * y - {Number} y parameter for the translation. Defaults to the y value of │ │ │ │ │ - * the map's │ │ │ │ │ - * scale - {Number} scale. Defaults to 1 if not provided. │ │ │ │ │ - */ │ │ │ │ │ - applyTransform: function(x, y, scale) { │ │ │ │ │ - scale = scale || 1; │ │ │ │ │ - var origin = this.layerContainerOriginPx, │ │ │ │ │ - needTransform = scale !== 1; │ │ │ │ │ - x = x || origin.x; │ │ │ │ │ - y = y || origin.y; │ │ │ │ │ - │ │ │ │ │ - var style = this.layerContainerDiv.style, │ │ │ │ │ - transform = this.applyTransform.transform, │ │ │ │ │ - template = this.applyTransform.template; │ │ │ │ │ - │ │ │ │ │ - if (transform === undefined) { │ │ │ │ │ - transform = OpenLayers.Util.vendorPrefix.style('transform'); │ │ │ │ │ - this.applyTransform.transform = transform; │ │ │ │ │ - if (transform) { │ │ │ │ │ - // Try translate3d, but only if the viewPortDiv has a transform │ │ │ │ │ - // defined in a stylesheet │ │ │ │ │ - var computedStyle = OpenLayers.Element.getStyle(this.viewPortDiv, │ │ │ │ │ - OpenLayers.Util.vendorPrefix.css('transform')); │ │ │ │ │ - if (!computedStyle || computedStyle !== 'none') { │ │ │ │ │ - template = ['translate3d(', ',0) ', 'scale3d(', ',1)']; │ │ │ │ │ - style[transform] = [template[0], '0,0', template[1]].join(''); │ │ │ │ │ - } │ │ │ │ │ - // If no transform is defined in the stylesheet or translate3d │ │ │ │ │ - // does not stick, use translate and scale │ │ │ │ │ - if (!template || !~style[transform].indexOf(template[0])) { │ │ │ │ │ - template = ['translate(', ') ', 'scale(', ')']; │ │ │ │ │ - } │ │ │ │ │ - this.applyTransform.template = template; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // If we do 3d transforms, we always want to use them. If we do 2d │ │ │ │ │ - // transforms, we only use them when we need to. │ │ │ │ │ - if (transform !== null && (template[0] === 'translate3d(' || needTransform === true)) { │ │ │ │ │ - // Our 2d transforms are combined with style.left and style.top, so │ │ │ │ │ - // adjust x and y values and set the origin as left and top │ │ │ │ │ - if (needTransform === true && template[0] === 'translate(') { │ │ │ │ │ - x -= origin.x; │ │ │ │ │ - y -= origin.y; │ │ │ │ │ - style.left = origin.x + 'px'; │ │ │ │ │ - style.top = origin.y + 'px'; │ │ │ │ │ - } │ │ │ │ │ - style[transform] = [ │ │ │ │ │ - template[0], x, 'px,', y, 'px', template[1], │ │ │ │ │ - template[2], scale, ',', scale, template[3] │ │ │ │ │ - ].join(''); │ │ │ │ │ - } else { │ │ │ │ │ - style.left = x + 'px'; │ │ │ │ │ - style.top = y + 'px'; │ │ │ │ │ - // We previously might have had needTransform, so remove transform │ │ │ │ │ - if (transform !== null) { │ │ │ │ │ - style[transform] = ''; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Map" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: TILE_WIDTH │ │ │ │ │ - * {Integer} 256 Default tile width (unless otherwise specified) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: TILE_HEIGHT │ │ │ │ │ - * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Map.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: opacity │ │ │ │ │ - * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ - * is 1. │ │ │ │ │ - */ │ │ │ │ │ - opacity: 1, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: alwaysInRange │ │ │ │ │ - * {Boolean} If a layer's display should not be scale-based, this should │ │ │ │ │ - * be set to true. This will cause the layer, as an overlay, to always │ │ │ │ │ - * be 'active', by always returning true from the calculateInRange() │ │ │ │ │ - * function. │ │ │ │ │ - * │ │ │ │ │ - * If not explicitly specified for a layer, its value will be │ │ │ │ │ - * determined on startup in initResolutions() based on whether or not │ │ │ │ │ - * any scale-specific properties have been set as options on the │ │ │ │ │ - * layer. If no scale-specific options have been set on the layer, we │ │ │ │ │ - * assume that it should always be in range. │ │ │ │ │ - * │ │ │ │ │ - * See #987 for more info. │ │ │ │ │ - */ │ │ │ │ │ - alwaysInRange: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ - * {Array} The properties that are used for calculating resolutions │ │ │ │ │ - * information. │ │ │ │ │ - */ │ │ │ │ │ - RESOLUTION_PROPERTIES: [ │ │ │ │ │ - 'scales', 'resolutions', │ │ │ │ │ - 'maxScale', 'minScale', │ │ │ │ │ - 'maxResolution', 'minResolution', │ │ │ │ │ - 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ - ], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * layer.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to layer.events.object. │ │ │ │ │ - * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ - * │ │ │ │ │ - * Supported map event types: │ │ │ │ │ - * loadstart - Triggered when layer loading starts. When using a Vector │ │ │ │ │ - * layer with a Fixed or BBOX strategy, the event object includes │ │ │ │ │ - * a *filter* property holding the OpenLayers.Filter used when │ │ │ │ │ - * calling read on the protocol. │ │ │ │ │ - * loadend - Triggered when layer loading ends. When using a Vector layer │ │ │ │ │ - * with a Fixed or BBOX strategy, the event object includes a │ │ │ │ │ - * *response* property holding an OpenLayers.Protocol.Response object. │ │ │ │ │ - * visibilitychanged - Triggered when the layer's visibility property is │ │ │ │ │ - * changed, e.g. by turning the layer on or off in the layer switcher. │ │ │ │ │ - * Note that the actual visibility of the layer can also change if it │ │ │ │ │ - * gets out of range (see ). If you also want to catch │ │ │ │ │ - * these cases, register for the map's 'changelayer' event instead. │ │ │ │ │ - * move - Triggered when layer moves (triggered with every mousemove │ │ │ │ │ - * during a drag). │ │ │ │ │ - * moveend - Triggered when layer is done moving, object passed as │ │ │ │ │ - * argument has a zoomChanged boolean property which tells that the │ │ │ │ │ - * zoom has changed. │ │ │ │ │ - * added - Triggered after the layer is added to a map. Listeners will │ │ │ │ │ - * receive an object with a *map* property referencing the map and a │ │ │ │ │ - * *layer* property referencing the layer. │ │ │ │ │ - * removed - Triggered after the layer is removed from the map. Listeners │ │ │ │ │ - * will receive an object with a *map* property referencing the map and │ │ │ │ │ - * a *layer* property referencing the layer. │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: map │ │ │ │ │ - * {} This variable is set when the layer is added to │ │ │ │ │ - * the map, via the accessor function setMap(). │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ - * individually by all subclasses. Default is false │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: alpha │ │ │ │ │ - * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - alpha: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: visibility │ │ │ │ │ - * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - visibility: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: attribution │ │ │ │ │ - * {String} Attribution string, displayed when an │ │ │ │ │ - * has been added to the map. │ │ │ │ │ - */ │ │ │ │ │ - attribution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: inRange │ │ │ │ │ - * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ - * range. This is set in whenever the zoom │ │ │ │ │ - * changes. │ │ │ │ │ - */ │ │ │ │ │ - inRange: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Propery: imageSize │ │ │ │ │ - * {} For layers with a gutter, the image is larger than │ │ │ │ │ - * the tile by twice the gutter in each dimension. │ │ │ │ │ - */ │ │ │ │ │ - imageSize: null, │ │ │ │ │ - │ │ │ │ │ - // OPTIONS │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} An optional object whose properties will be set on the layer. │ │ │ │ │ - * Any of the layer properties can be set as a property of the options │ │ │ │ │ - * object and sent to the constructor when the layer is created. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: gutter │ │ │ │ │ - * {Integer} Determines the width (in pixels) of the gutter around image │ │ │ │ │ - * tiles to ignore. By setting this property to a non-zero value, │ │ │ │ │ - * images will be requested that are wider and taller than the tile │ │ │ │ │ - * size by a value of 2 x gutter. This allows artifacts of rendering │ │ │ │ │ - * at tile edges to be ignored. Set a gutter value that is equal to │ │ │ │ │ - * half the size of the widest symbol that needs to be displayed. │ │ │ │ │ - * Defaults to zero. Non-tiled layers always have zero gutter. │ │ │ │ │ - */ │ │ │ │ │ - gutter: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: projection │ │ │ │ │ - * {} or {} Specifies the projection of the layer. │ │ │ │ │ - * Can be set in the layer options. If not specified in the layer options, │ │ │ │ │ - * it is set to the default projection specified in the map, │ │ │ │ │ - * when the layer is added to the map. │ │ │ │ │ - * Projection along with default maxExtent and resolutions │ │ │ │ │ - * are set automatically with commercial baselayers in EPSG:3857, │ │ │ │ │ - * such as Google, Bing and OpenStreetMap, and do not need to be specified. │ │ │ │ │ - * Otherwise, if specifying projection, also set maxExtent, │ │ │ │ │ - * maxResolution or resolutions as appropriate. │ │ │ │ │ - * When using vector layers with strategies, layer projection should be set │ │ │ │ │ - * to the projection of the source data if that is different from the map default. │ │ │ │ │ - * │ │ │ │ │ - * Can be either a string or an object; │ │ │ │ │ - * if a string is passed, will be converted to an object when │ │ │ │ │ - * the layer is added to the map. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - projection: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: units │ │ │ │ │ - * {String} The layer map units. Defaults to null. Possible values │ │ │ │ │ - * are 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'. │ │ │ │ │ - * Normally taken from the projection. │ │ │ │ │ - * Only required if both map and layers do not define a projection, │ │ │ │ │ - * or if they define a projection which does not define units. │ │ │ │ │ - */ │ │ │ │ │ - units: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: scales │ │ │ │ │ - * {Array} An array of map scales in descending order. The values in the │ │ │ │ │ - * array correspond to the map scale denominator. Note that these │ │ │ │ │ - * values only make sense if the display (monitor) resolution of the │ │ │ │ │ - * client is correctly guessed by whomever is configuring the │ │ │ │ │ - * application. In addition, the units property must also be set. │ │ │ │ │ - * Use instead wherever possible. │ │ │ │ │ - */ │ │ │ │ │ - scales: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: resolutions │ │ │ │ │ - * {Array} A list of map resolutions (map units per pixel) in descending │ │ │ │ │ - * order. If this is not set in the layer constructor, it will be set │ │ │ │ │ - * based on other resolution related properties (maxExtent, │ │ │ │ │ - * maxResolution, maxScale, etc.). │ │ │ │ │ - */ │ │ │ │ │ - resolutions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The maximum extent for the layer. Defaults to null. │ │ │ │ │ - * │ │ │ │ │ - * The center of these bounds will not stray outside │ │ │ │ │ - * of the viewport extent during panning. In addition, if │ │ │ │ │ - * is set to false, data will not be │ │ │ │ │ - * requested that falls completely outside of these bounds. │ │ │ │ │ - */ │ │ │ │ │ - maxExtent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The minimum extent for the layer. Defaults to null. │ │ │ │ │ - */ │ │ │ │ │ - minExtent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxResolution │ │ │ │ │ - * {Float} Default max is 360 deg / 256 px, which corresponds to │ │ │ │ │ - * zoom level 0 on gmaps. Specify a different value in the layer │ │ │ │ │ - * options if you are not using the default │ │ │ │ │ - * and displaying the whole world. │ │ │ │ │ - */ │ │ │ │ │ - maxResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ - numZoomLevels: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minScale: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayOutsideMaxExtent │ │ │ │ │ - * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ - * extent for this layer. Defaults to false. │ │ │ │ │ - */ │ │ │ │ │ - displayOutsideMaxExtent: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: wrapDateLine │ │ │ │ │ - * {Boolean} Wraps the world at the international dateline, so the map can │ │ │ │ │ - * be panned infinitely in longitudinal direction. Only use this on the │ │ │ │ │ - * base layer, and only if the layer's maxExtent equals the world bounds. │ │ │ │ │ - * #487 for more info. │ │ │ │ │ - */ │ │ │ │ │ - wrapDateLine: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: metadata │ │ │ │ │ - * {Object} This object can be used to store additional information on a │ │ │ │ │ - * layer object. │ │ │ │ │ - */ │ │ │ │ │ - metadata: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The layer name │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - │ │ │ │ │ - this.metadata = {}; │ │ │ │ │ - │ │ │ │ │ - options = OpenLayers.Util.extend({}, options); │ │ │ │ │ - // make sure we respect alwaysInRange if set on the prototype │ │ │ │ │ - if (this.alwaysInRange != null) { │ │ │ │ │ - options.alwaysInRange = this.alwaysInRange; │ │ │ │ │ - } │ │ │ │ │ - this.addOptions(options); │ │ │ │ │ - │ │ │ │ │ - this.name = name; │ │ │ │ │ - │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ - this.div.style.width = "100%"; │ │ │ │ │ - this.div.style.height = "100%"; │ │ │ │ │ - this.div.dir = "ltr"; │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy is a destructor: this is to alleviate cyclic references which │ │ │ │ │ - * the Javascript garbage cleaner can not take care of on its own. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * setNewBaseLayer - {Boolean} Set a new base layer when this layer has │ │ │ │ │ - * been destroyed. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function(setNewBaseLayer) { │ │ │ │ │ - if (setNewBaseLayer == null) { │ │ │ │ │ - setNewBaseLayer = true; │ │ │ │ │ - } │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.removeLayer(this, setNewBaseLayer); │ │ │ │ │ - } │ │ │ │ │ - this.projection = null; │ │ │ │ │ - this.map = null; │ │ │ │ │ - this.name = null; │ │ │ │ │ - this.div = null; │ │ │ │ │ - this.options = null; │ │ │ │ │ - │ │ │ │ │ - if (this.events) { │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - this.events = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {} The layer to be cloned │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ - │ │ │ │ │ - // a cloned layer should never have its map property set │ │ │ │ │ - // because it has not been added to a map yet. │ │ │ │ │ - obj.map = null; │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getOptions │ │ │ │ │ - * Extracts an object from the layer with the properties that were set as │ │ │ │ │ - * options, but updates them with the values currently set on the │ │ │ │ │ - * instance. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} the of the layer, representing the current state. │ │ │ │ │ - */ │ │ │ │ │ - getOptions: function() { │ │ │ │ │ - var options = {}; │ │ │ │ │ - for (var o in this.options) { │ │ │ │ │ - options[o] = this[o]; │ │ │ │ │ - } │ │ │ │ │ - return options; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setName │ │ │ │ │ - * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ - * on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newName - {String} The new name. │ │ │ │ │ - */ │ │ │ │ │ - setName: function(newName) { │ │ │ │ │ - if (newName != this.name) { │ │ │ │ │ - this.name = newName; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "name" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addOptions │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newOptions - {Object} │ │ │ │ │ - * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ - * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ - * sure that it is displayed with a valid resolution, and a │ │ │ │ │ - * changebaselayer event will be triggered. │ │ │ │ │ - */ │ │ │ │ │ - addOptions: function(newOptions, reinitialize) { │ │ │ │ │ - │ │ │ │ │ - if (this.options == null) { │ │ │ │ │ - this.options = {}; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (newOptions) { │ │ │ │ │ - // make sure this.projection references a projection object │ │ │ │ │ - if (typeof newOptions.projection == "string") { │ │ │ │ │ - newOptions.projection = new OpenLayers.Projection(newOptions.projection); │ │ │ │ │ - } │ │ │ │ │ - if (newOptions.projection) { │ │ │ │ │ - // get maxResolution, units and maxExtent from projection defaults if │ │ │ │ │ - // they are not defined already │ │ │ │ │ - OpenLayers.Util.applyDefaults(newOptions, │ │ │ │ │ - OpenLayers.Projection.defaults[newOptions.projection.getCode()]); │ │ │ │ │ - } │ │ │ │ │ - // allow array for extents │ │ │ │ │ - if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent); │ │ │ │ │ - } │ │ │ │ │ - if (newOptions.minExtent && !(newOptions.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - newOptions.minExtent = new OpenLayers.Bounds(newOptions.minExtent); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // update our copy for clone │ │ │ │ │ - OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ - │ │ │ │ │ - // add new options to this │ │ │ │ │ - OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ - │ │ │ │ │ - // get the units from the projection, if we have a projection │ │ │ │ │ - // and it it has units │ │ │ │ │ - if (this.projection && this.projection.getUnits()) { │ │ │ │ │ - this.units = this.projection.getUnits(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // re-initialize resolutions if necessary, i.e. if any of the │ │ │ │ │ - // properties of the "properties" array defined below is set │ │ │ │ │ - // in the new options │ │ │ │ │ - if (this.map) { │ │ │ │ │ - // store current resolution so we can try to restore it later │ │ │ │ │ - var resolution = this.map.getResolution(); │ │ │ │ │ - var properties = this.RESOLUTION_PROPERTIES.concat( │ │ │ │ │ - ["projection", "units", "minExtent", "maxExtent"] │ │ │ │ │ - ); │ │ │ │ │ - for (var o in newOptions) { │ │ │ │ │ - if (newOptions.hasOwnProperty(o) && │ │ │ │ │ - OpenLayers.Util.indexOf(properties, o) >= 0) { │ │ │ │ │ - │ │ │ │ │ - this.initResolutions(); │ │ │ │ │ - if (reinitialize && this.map.baseLayer === this) { │ │ │ │ │ - // update map position, and restore previous resolution │ │ │ │ │ - this.map.setCenter(this.map.getCenter(), │ │ │ │ │ - this.map.getZoomForResolution(resolution), │ │ │ │ │ - false, true │ │ │ │ │ - ); │ │ │ │ │ - // trigger a changebaselayer event to make sure that │ │ │ │ │ - // all controls (especially │ │ │ │ │ - // OpenLayers.Control.PanZoomBar) get notified of the │ │ │ │ │ - // new options │ │ │ │ │ - this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: onMapResize │ │ │ │ │ - * This function can be implemented by subclasses │ │ │ │ │ - */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - //this function can be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ - */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - var redrawn = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - │ │ │ │ │ - // min/max Range may have changed │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - │ │ │ │ │ - // map's center might not yet be set │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return redrawn; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ - * do some init work in that case. │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - var display = this.visibility; │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - display = display && this.inRange; │ │ │ │ │ - } │ │ │ │ │ - this.display(display); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ - * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ - */ │ │ │ │ │ - moveByPx: function(dx, dy) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the layer. This is done through an accessor │ │ │ │ │ - * so that subclasses can override this and take special action once │ │ │ │ │ - * they have their map variable set. │ │ │ │ │ - * │ │ │ │ │ - * Here we take care to bring over any of the necessary default │ │ │ │ │ - * properties from the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - if (this.map == null) { │ │ │ │ │ - │ │ │ │ │ - this.map = map; │ │ │ │ │ - │ │ │ │ │ - // grab some essential layer data from the map if it hasn't already │ │ │ │ │ - // been set │ │ │ │ │ - this.maxExtent = this.maxExtent || this.map.maxExtent; │ │ │ │ │ - this.minExtent = this.minExtent || this.map.minExtent; │ │ │ │ │ - │ │ │ │ │ - this.projection = this.projection || this.map.projection; │ │ │ │ │ - if (typeof this.projection == "string") { │ │ │ │ │ - this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // Check the projection to see if we can get units -- if not, refer │ │ │ │ │ - // to properties. │ │ │ │ │ - this.units = this.projection.getUnits() || │ │ │ │ │ - this.units || this.map.units; │ │ │ │ │ - │ │ │ │ │ - this.initResolutions(); │ │ │ │ │ - │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ - this.div.style.display = show ? "" : "none"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // deal with gutters │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: afterAdd │ │ │ │ │ - * Called at the end of the map.addLayer sequence. At this point, the map │ │ │ │ │ - * will have a base layer. To be overridden by subclasses. │ │ │ │ │ - */ │ │ │ │ │ - afterAdd: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeMap │ │ │ │ │ - * Just as setMap() allows each layer the possibility to take a │ │ │ │ │ - * personalized action on being added to the map, removeMap() allows │ │ │ │ │ - * each layer to take a personalized action on being removed from it. │ │ │ │ │ - * For now, this will be mostly unused, except for the EventPane layer, │ │ │ │ │ - * which needs this hook so that it can remove the special invisible │ │ │ │ │ - * pane. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - //to be overridden by subclasses │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getImageSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} optional tile bounds, can be used │ │ │ │ │ - * by subclasses that have to deal with different tile sizes at the │ │ │ │ │ - * layer extent edges (e.g. Zoomify) │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The size that the image should be, taking into │ │ │ │ │ - * account gutters. │ │ │ │ │ - */ │ │ │ │ │ - getImageSize: function(bounds) { │ │ │ │ │ - return (this.imageSize || this.tileSize); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ - * or use by Tile.Image. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ - */ │ │ │ │ │ - setTileSize: function(size) { │ │ │ │ │ - var tileSize = (size) ? size : │ │ │ │ │ - ((this.tileSize) ? this.tileSize : │ │ │ │ │ - this.map.getTileSize()); │ │ │ │ │ - this.tileSize = tileSize; │ │ │ │ │ - if (this.gutter) { │ │ │ │ │ - // layers with gutters need non-null tile sizes │ │ │ │ │ - //if(tileSize == null) { │ │ │ │ │ - // OpenLayers.console.error("Error in layer.setMap() for " + │ │ │ │ │ - // this.name + ": layers with " + │ │ │ │ │ - // "gutters need non-null tile sizes"); │ │ │ │ │ - //} │ │ │ │ │ - this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter), │ │ │ │ │ - tileSize.h + (2 * this.gutter)); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVisibility │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ - */ │ │ │ │ │ - getVisibility: function() { │ │ │ │ │ - return this.visibility; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setVisibility │ │ │ │ │ - * Set the visibility flag for the layer and hide/show & redraw │ │ │ │ │ - * accordingly. Fire event unless otherwise specified │ │ │ │ │ - * │ │ │ │ │ - * Note that visibility is no longer simply whether or not the layer's │ │ │ │ │ - * style.display is set to "block". Now we store a 'visibility' state │ │ │ │ │ - * property on the layer class, this allows us to remember whether or │ │ │ │ │ - * not we *desire* for a layer to be visible. In the case where the │ │ │ │ │ - * map's resolution is out of the layer's range, this desire may be │ │ │ │ │ - * subverted. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * visibility - {Boolean} Whether or not to display the layer (if in range) │ │ │ │ │ - */ │ │ │ │ │ - setVisibility: function(visibility) { │ │ │ │ │ - if (visibility != this.visibility) { │ │ │ │ │ - this.visibility = visibility; │ │ │ │ │ - this.display(visibility); │ │ │ │ │ - this.redraw(); │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "visibility" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("visibilitychanged"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: display │ │ │ │ │ - * Hide or show the Layer. This is designed to be used internally, and │ │ │ │ │ - * is not generally the way to enable or disable the layer. For that, │ │ │ │ │ - * use the setVisibility function instead.. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - if (display != (this.div.style.display != "none")) { │ │ │ │ │ - this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: calculateInRange │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer is displayable at the current map's current │ │ │ │ │ - * resolution. Note that if 'alwaysInRange' is true for the layer, │ │ │ │ │ - * this function will always return true. │ │ │ │ │ - */ │ │ │ │ │ - calculateInRange: function() { │ │ │ │ │ - var inRange = false; │ │ │ │ │ - │ │ │ │ │ - if (this.alwaysInRange) { │ │ │ │ │ - inRange = true; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var resolution = this.map.getResolution(); │ │ │ │ │ - inRange = ((resolution >= this.minResolution) && │ │ │ │ │ - (resolution <= this.maxResolution)); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return inRange; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setIsBaseLayer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * isBaseLayer - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - setIsBaseLayer: function(isBaseLayer) { │ │ │ │ │ - if (isBaseLayer != this.isBaseLayer) { │ │ │ │ │ - this.isBaseLayer = isBaseLayer; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: initResolutions │ │ │ │ │ - * This method's responsibility is to set up the 'resolutions' array │ │ │ │ │ - * for the layer -- this array is what the layer will use to interface │ │ │ │ │ - * between the zoom levels of the map and the resolution display │ │ │ │ │ - * of the layer. │ │ │ │ │ - * │ │ │ │ │ - * The user has several options that determine how the array is set up. │ │ │ │ │ - * │ │ │ │ │ - * For a detailed explanation, see the following wiki from the │ │ │ │ │ - * openlayers.org homepage: │ │ │ │ │ - * http://trac.openlayers.org/wiki/SettingZoomLevels │ │ │ │ │ - */ │ │ │ │ │ - initResolutions: function() { │ │ │ │ │ - │ │ │ │ │ - // ok we want resolutions, here's our strategy: │ │ │ │ │ - // │ │ │ │ │ - // 1. if resolutions are defined in the layer config, use them │ │ │ │ │ - // 2. else, if scales are defined in the layer config then derive │ │ │ │ │ - // resolutions from these scales │ │ │ │ │ - // 3. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ - // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ - // layer config │ │ │ │ │ - // 4. if we still don't have resolutions, and if resolutions │ │ │ │ │ - // are defined in the same, use them │ │ │ │ │ - // 5. else, if scales are defined in the map then derive │ │ │ │ │ - // resolutions from these scales │ │ │ │ │ - // 6. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ - // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ - // map │ │ │ │ │ - // 7. hope for the best! │ │ │ │ │ - │ │ │ │ │ - var i, len, p; │ │ │ │ │ - var props = {}, │ │ │ │ │ - alwaysInRange = true; │ │ │ │ │ - │ │ │ │ │ - // get resolution data from layer config │ │ │ │ │ - // (we also set alwaysInRange in the layer as appropriate) │ │ │ │ │ - for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ - p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ - props[p] = this.options[p]; │ │ │ │ │ - if (alwaysInRange && this.options[p]) { │ │ │ │ │ - alwaysInRange = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.options.alwaysInRange == null) { │ │ │ │ │ - this.alwaysInRange = alwaysInRange; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if we don't have resolutions then attempt to derive them from scales │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.calculateResolutions(props); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if we couldn't calculate resolutions then we look at we have │ │ │ │ │ - // in the map │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ - p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ - props[p] = this.options[p] != null ? │ │ │ │ │ - this.options[p] : this.map[p]; │ │ │ │ │ - } │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ - } │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.calculateResolutions(props); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // ok, we new need to set properties in the instance │ │ │ │ │ - │ │ │ │ │ - // get maxResolution from the config if it's defined there │ │ │ │ │ - var maxResolution; │ │ │ │ │ - if (this.options.maxResolution && │ │ │ │ │ - this.options.maxResolution !== "auto") { │ │ │ │ │ - maxResolution = this.options.maxResolution; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.minScale) { │ │ │ │ │ - maxResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - this.options.minScale, this.units); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // get minResolution from the config if it's defined there │ │ │ │ │ - var minResolution; │ │ │ │ │ - if (this.options.minResolution && │ │ │ │ │ - this.options.minResolution !== "auto") { │ │ │ │ │ - minResolution = this.options.minResolution; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.maxScale) { │ │ │ │ │ - minResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - this.options.maxScale, this.units); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.resolutions) { │ │ │ │ │ - │ │ │ │ │ - //sort resolutions array descendingly │ │ │ │ │ - props.resolutions.sort(function(a, b) { │ │ │ │ │ - return (b - a); │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - // if we still don't have a maxResolution get it from the │ │ │ │ │ - // resolutions array │ │ │ │ │ - if (!maxResolution) { │ │ │ │ │ - maxResolution = props.resolutions[0]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if we still don't have a minResolution get it from the │ │ │ │ │ - // resolutions array │ │ │ │ │ - if (!minResolution) { │ │ │ │ │ - var lastIdx = props.resolutions.length - 1; │ │ │ │ │ - minResolution = props.resolutions[lastIdx]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.resolutions = props.resolutions; │ │ │ │ │ - if (this.resolutions) { │ │ │ │ │ - len = this.resolutions.length; │ │ │ │ │ - this.scales = new Array(len); │ │ │ │ │ - for (i = 0; i < len; i++) { │ │ │ │ │ - this.scales[i] = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - this.resolutions[i], this.units); │ │ │ │ │ - } │ │ │ │ │ - this.numZoomLevels = len; │ │ │ │ │ - } │ │ │ │ │ - this.minResolution = minResolution; │ │ │ │ │ - if (minResolution) { │ │ │ │ │ - this.maxScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - minResolution, this.units); │ │ │ │ │ - } │ │ │ │ │ - this.maxResolution = maxResolution; │ │ │ │ │ - if (maxResolution) { │ │ │ │ │ - this.minScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - maxResolution, this.units); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: resolutionsFromScales │ │ │ │ │ - * Derive resolutions from scales. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scales - {Array(Number)} Scales │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {Array(Number)} Resolutions │ │ │ │ │ - */ │ │ │ │ │ - resolutionsFromScales: function(scales) { │ │ │ │ │ - if (scales == null) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var resolutions, i, len; │ │ │ │ │ - len = scales.length; │ │ │ │ │ - resolutions = new Array(len); │ │ │ │ │ - for (i = 0; i < len; i++) { │ │ │ │ │ - resolutions[i] = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - scales[i], this.units); │ │ │ │ │ - } │ │ │ │ │ - return resolutions; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateResolutions │ │ │ │ │ - * Calculate resolutions based on the provided properties. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * props - {Object} Properties │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array({Number})} Array of resolutions. │ │ │ │ │ - */ │ │ │ │ │ - calculateResolutions: function(props) { │ │ │ │ │ - │ │ │ │ │ - var viewSize, wRes, hRes; │ │ │ │ │ - │ │ │ │ │ - // determine maxResolution │ │ │ │ │ - var maxResolution = props.maxResolution; │ │ │ │ │ - if (props.minScale != null) { │ │ │ │ │ - maxResolution = │ │ │ │ │ - OpenLayers.Util.getResolutionFromScale(props.minScale, │ │ │ │ │ - this.units); │ │ │ │ │ - } else if (maxResolution == "auto" && this.maxExtent != null) { │ │ │ │ │ - viewSize = this.map.getSize(); │ │ │ │ │ - wRes = this.maxExtent.getWidth() / viewSize.w; │ │ │ │ │ - hRes = this.maxExtent.getHeight() / viewSize.h; │ │ │ │ │ - maxResolution = Math.max(wRes, hRes); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // determine minResolution │ │ │ │ │ - var minResolution = props.minResolution; │ │ │ │ │ - if (props.maxScale != null) { │ │ │ │ │ - minResolution = │ │ │ │ │ - OpenLayers.Util.getResolutionFromScale(props.maxScale, │ │ │ │ │ - this.units); │ │ │ │ │ - } else if (props.minResolution == "auto" && this.minExtent != null) { │ │ │ │ │ - viewSize = this.map.getSize(); │ │ │ │ │ - wRes = this.minExtent.getWidth() / viewSize.w; │ │ │ │ │ - hRes = this.minExtent.getHeight() / viewSize.h; │ │ │ │ │ - minResolution = Math.max(wRes, hRes); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (typeof maxResolution !== "number" && │ │ │ │ │ - typeof minResolution !== "number" && │ │ │ │ │ - this.maxExtent != null) { │ │ │ │ │ - // maxResolution for default grid sets assumes that at zoom │ │ │ │ │ - // level zero, the whole world fits on one tile. │ │ │ │ │ - var tileSize = this.map.getTileSize(); │ │ │ │ │ - maxResolution = Math.max( │ │ │ │ │ - this.maxExtent.getWidth() / tileSize.w, │ │ │ │ │ - this.maxExtent.getHeight() / tileSize.h │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // determine numZoomLevels │ │ │ │ │ - var maxZoomLevel = props.maxZoomLevel; │ │ │ │ │ - var numZoomLevels = props.numZoomLevels; │ │ │ │ │ - if (typeof minResolution === "number" && │ │ │ │ │ - typeof maxResolution === "number" && numZoomLevels === undefined) { │ │ │ │ │ - var ratio = maxResolution / minResolution; │ │ │ │ │ - numZoomLevels = Math.floor(Math.log(ratio) / Math.log(2)) + 1; │ │ │ │ │ - } else if (numZoomLevels === undefined && maxZoomLevel != null) { │ │ │ │ │ - numZoomLevels = maxZoomLevel + 1; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // are we able to calculate resolutions? │ │ │ │ │ - if (typeof numZoomLevels !== "number" || numZoomLevels <= 0 || │ │ │ │ │ - (typeof maxResolution !== "number" && │ │ │ │ │ - typeof minResolution !== "number")) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // now we have numZoomLevels and at least one of maxResolution │ │ │ │ │ - // or minResolution, we can populate the resolutions array │ │ │ │ │ - │ │ │ │ │ - var resolutions = new Array(numZoomLevels); │ │ │ │ │ - var base = 2; │ │ │ │ │ - if (typeof minResolution == "number" && │ │ │ │ │ - typeof maxResolution == "number") { │ │ │ │ │ - // if maxResolution and minResolution are set, we calculate │ │ │ │ │ - // the base for exponential scaling that starts at │ │ │ │ │ - // maxResolution and ends at minResolution in numZoomLevels │ │ │ │ │ - // steps. │ │ │ │ │ - base = Math.pow( │ │ │ │ │ - (maxResolution / minResolution), │ │ │ │ │ - (1 / (numZoomLevels - 1)) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var i; │ │ │ │ │ - if (typeof maxResolution === "number") { │ │ │ │ │ - for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ - resolutions[i] = maxResolution / Math.pow(base, i); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ - resolutions[numZoomLevels - 1 - i] = │ │ │ │ │ - minResolution * Math.pow(base, i); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return resolutions; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ - * resolutions array, indexed by current zoom level. │ │ │ │ │ - */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var zoom = this.map.getZoom(); │ │ │ │ │ - return this.getResolutionForZoom(zoom); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ - */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ - // means it will user map's current center & resolution │ │ │ │ │ - // │ │ │ │ │ - return this.map.calculateBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForExtent │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * extent - {} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ - * for the passed-in extent. We do this by calculating the ideal │ │ │ │ │ - * resolution for the given extent (based on the map size) and then │ │ │ │ │ - * calling getZoomForResolution(), passing along the 'closest' │ │ │ │ │ - * parameter. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForExtent: function(extent, closest) { │ │ │ │ │ - var viewSize = this.map.getSize(); │ │ │ │ │ - var idealResolution = Math.max(extent.getWidth() / viewSize.w, │ │ │ │ │ - extent.getHeight() / viewSize.h); │ │ │ │ │ - │ │ │ │ │ - return this.getZoomForResolution(idealResolution, closest); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ - * This function is to be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getDataExtent: function() { │ │ │ │ │ - //to be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ - */ │ │ │ │ │ - getResolutionForZoom: function(zoom) { │ │ │ │ │ - zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1)); │ │ │ │ │ - var resolution; │ │ │ │ │ - if (this.map.fractionalZoom) { │ │ │ │ │ - var low = Math.floor(zoom); │ │ │ │ │ - var high = Math.ceil(zoom); │ │ │ │ │ - resolution = this.resolutions[low] - │ │ │ │ │ - ((zoom - low) * (this.resolutions[low] - this.resolutions[high])); │ │ │ │ │ - } else { │ │ │ │ │ - resolution = this.resolutions[Math.round(zoom)]; │ │ │ │ │ - } │ │ │ │ │ - return resolution; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForResolution │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resolution - {Float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ - * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ - * resolution is actually smaller than we would have desired (if this │ │ │ │ │ - * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ - * the returned zoom index might not actually contain the entire │ │ │ │ │ - * extent specified... but it'll be close). │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ - * that corresponds to the best fit resolution given the passed in │ │ │ │ │ - * value and the 'closest' specification. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForResolution: function(resolution, closest) { │ │ │ │ │ - var zoom, i, len; │ │ │ │ │ - if (this.map.fractionalZoom) { │ │ │ │ │ - var lowZoom = 0; │ │ │ │ │ - var highZoom = this.resolutions.length - 1; │ │ │ │ │ - var highRes = this.resolutions[lowZoom]; │ │ │ │ │ - var lowRes = this.resolutions[highZoom]; │ │ │ │ │ - var res; │ │ │ │ │ - for (i = 0, len = this.resolutions.length; i < len; ++i) { │ │ │ │ │ - res = this.resolutions[i]; │ │ │ │ │ - if (res >= resolution) { │ │ │ │ │ - highRes = res; │ │ │ │ │ - lowZoom = i; │ │ │ │ │ - } │ │ │ │ │ - if (res <= resolution) { │ │ │ │ │ - lowRes = res; │ │ │ │ │ - highZoom = i; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var dRes = highRes - lowRes; │ │ │ │ │ - if (dRes > 0) { │ │ │ │ │ - zoom = lowZoom + ((highRes - resolution) / dRes); │ │ │ │ │ - } else { │ │ │ │ │ - zoom = lowZoom; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - var diff; │ │ │ │ │ - var minDiff = Number.POSITIVE_INFINITY; │ │ │ │ │ - for (i = 0, len = this.resolutions.length; i < len; i++) { │ │ │ │ │ - if (closest) { │ │ │ │ │ - diff = Math.abs(this.resolutions[i] - resolution); │ │ │ │ │ - if (diff > minDiff) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - minDiff = diff; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.resolutions[i] < resolution) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - zoom = Math.max(0, i - 1); │ │ │ │ │ - } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLonLatFromViewPortPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ - * an object with a 'x' │ │ │ │ │ - * and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in │ │ │ │ │ - * view port , translated into lon/lat by the layer. │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - var map = this.map; │ │ │ │ │ - if (viewPortPx != null && map.minPx) { │ │ │ │ │ - var res = map.getResolution(); │ │ │ │ │ - var maxExtent = map.getMaxExtent({ │ │ │ │ │ - restricted: true │ │ │ │ │ - }); │ │ │ │ │ - var lon = (viewPortPx.x - map.minPx.x) * res + maxExtent.left; │ │ │ │ │ - var lat = (map.minPx.y - viewPortPx.y) * res + maxExtent.top; │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ - │ │ │ │ │ - if (this.wrapDateLine) { │ │ │ │ │ - lonlat = lonlat.wrapDateLine(this.maxExtent); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return lonlat; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ - * Returns a pixel location given a map location. This method will return │ │ │ │ │ - * fractional pixel values. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} An OpenLayers.LonLat or │ │ │ │ │ - * an object with a 'lon' │ │ │ │ │ - * and 'lat' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An which is the passed-in │ │ │ │ │ - * lonlat translated into view port pixels. │ │ │ │ │ - */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat, resolution) { │ │ │ │ │ - var px = null; │ │ │ │ │ - if (lonlat != null) { │ │ │ │ │ - resolution = resolution || this.map.getResolution(); │ │ │ │ │ - var extent = this.map.calculateBounds(null, resolution); │ │ │ │ │ - px = new OpenLayers.Pixel( │ │ │ │ │ - (1 / resolution * (lonlat.lon - extent.left)), │ │ │ │ │ - (1 / resolution * (extent.top - lonlat.lat)) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return px; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setOpacity │ │ │ │ │ - * Sets the opacity for the entire layer (all images) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {Float} │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - if (opacity != this.opacity) { │ │ │ │ │ - this.opacity = opacity; │ │ │ │ │ - var childNodes = this.div.childNodes; │ │ │ │ │ - for (var i = 0, len = childNodes.length; i < len; ++i) { │ │ │ │ │ - var element = childNodes[i].firstChild || childNodes[i]; │ │ │ │ │ - var lastChild = childNodes[i].lastChild; │ │ │ │ │ - //TODO de-uglify this │ │ │ │ │ - if (lastChild && lastChild.nodeName.toLowerCase() === "iframe") { │ │ │ │ │ - element = lastChild.parentNode; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.modifyDOMElement(element, null, null, null, │ │ │ │ │ - null, null, null, opacity); │ │ │ │ │ - } │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "opacity" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getZIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} the z-index of this layer │ │ │ │ │ - */ │ │ │ │ │ - getZIndex: function() { │ │ │ │ │ - return this.div.style.zIndex; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setZIndex │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zIndex - {Integer} │ │ │ │ │ - */ │ │ │ │ │ - setZIndex: function(zIndex) { │ │ │ │ │ - this.div.style.zIndex = zIndex; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: adjustBounds │ │ │ │ │ - * This function will take a bounds, and if wrapDateLine option is set │ │ │ │ │ - * on the layer, it will return a bounds which is wrapped around the │ │ │ │ │ - * world. We do not wrap for bounds which *cross* the │ │ │ │ │ - * maxExtent.left/right, only bounds which are entirely to the left │ │ │ │ │ - * or entirely to the right. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - adjustBounds: function(bounds) { │ │ │ │ │ - │ │ │ │ │ - if (this.gutter) { │ │ │ │ │ - // Adjust the extent of a bounds in map units by the │ │ │ │ │ - // layer's gutter in pixels. │ │ │ │ │ - var mapGutter = this.gutter * this.map.getResolution(); │ │ │ │ │ - bounds = new OpenLayers.Bounds(bounds.left - mapGutter, │ │ │ │ │ - bounds.bottom - mapGutter, │ │ │ │ │ - bounds.right + mapGutter, │ │ │ │ │ - bounds.top + mapGutter); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.wrapDateLine) { │ │ │ │ │ - // wrap around the date line, within the limits of rounding error │ │ │ │ │ - var wrappingOptions = { │ │ │ │ │ - 'rightTolerance': this.getResolution(), │ │ │ │ │ - 'leftTolerance': this.getResolution() │ │ │ │ │ - }; │ │ │ │ │ - bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions); │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - return bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control │ │ │ │ │ - * Controls affect the display or behavior of the map. They allow everything │ │ │ │ │ - * from panning and zooming to displaying a scale indicator. Controls by │ │ │ │ │ - * default are added to the map they are contained within however it is │ │ │ │ │ - * possible to add a control to an external div by passing the div in the │ │ │ │ │ - * options parameter. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * The following example shows how to add many of the common controls │ │ │ │ │ - * to a map. │ │ │ │ │ - * │ │ │ │ │ - * > var map = new OpenLayers.Map('map', { controls: [] }); │ │ │ │ │ - * > │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.PanZoomBar()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.Permalink()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.Permalink('permalink')); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.MousePosition()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.OverviewMap()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.KeyboardDefaults()); │ │ │ │ │ - * │ │ │ │ │ - * The next code fragment is a quick example of how to intercept │ │ │ │ │ - * shift-mouse click to display the extent of the bounding box │ │ │ │ │ - * dragged out by the user. Usually controls are not created │ │ │ │ │ - * in exactly this manner. See the source for a more complete │ │ │ │ │ - * example: │ │ │ │ │ - * │ │ │ │ │ - * > var control = new OpenLayers.Control(); │ │ │ │ │ - * > OpenLayers.Util.extend(control, { │ │ │ │ │ - * > draw: function () { │ │ │ │ │ - * > // this Handler.Box will intercept the shift-mousedown │ │ │ │ │ - * > // before Control.MouseDefault gets to see it │ │ │ │ │ - * > this.box = new OpenLayers.Handler.Box( control, │ │ │ │ │ - * > {"done": this.notice}, │ │ │ │ │ - * > {keyMask: OpenLayers.Handler.MOD_SHIFT}); │ │ │ │ │ - * > this.box.activate(); │ │ │ │ │ - * > }, │ │ │ │ │ - * > │ │ │ │ │ - * > notice: function (bounds) { │ │ │ │ │ - * > OpenLayers.Console.userError(bounds); │ │ │ │ │ - * > } │ │ │ │ │ - * > }); │ │ │ │ │ - * > map.addControl(control); │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} this gets set in the addControl() function in │ │ │ │ │ - * OpenLayers.Map │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} The element that contains the control, if not present the │ │ │ │ │ - * control is placed inside the map. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {Number} Controls can have a 'type'. The type determines the type of │ │ │ │ │ - * interactions which are possible with them when they are placed in an │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - type: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: allowSelection │ │ │ │ │ - * {Boolean} By default, controls do not allow selection, because │ │ │ │ │ - * it may interfere with map dragging. If this is true, OpenLayers │ │ │ │ │ - * will not prevent selection of the control. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - allowSelection: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: displayClass │ │ │ │ │ - * {string} This property is used for CSS related to the drawing of the │ │ │ │ │ - * Control. │ │ │ │ │ - */ │ │ │ │ │ - displayClass: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: title │ │ │ │ │ - * {string} This property is used for showing a tooltip over the │ │ │ │ │ - * Control. │ │ │ │ │ - */ │ │ │ │ │ - title: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * false. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: active │ │ │ │ │ - * {Boolean} The control is active (read-only). Use and │ │ │ │ │ - * to change control state. │ │ │ │ │ - */ │ │ │ │ │ - active: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ - */ │ │ │ │ │ - handlerOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {} null │ │ │ │ │ - */ │ │ │ │ │ - handler: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to control.events.object (a reference │ │ │ │ │ - * to the control). │ │ │ │ │ - * element - {DOMElement} A reference to control.events.element (which │ │ │ │ │ - * will be null unless documented otherwise). │ │ │ │ │ - * │ │ │ │ │ - * Supported map event types: │ │ │ │ │ - * activate - Triggered when activated. │ │ │ │ │ - * deactivate - Triggered when deactivated. │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control │ │ │ │ │ - * Create an OpenLayers Control. The options passed as a parameter │ │ │ │ │ - * directly extend the control. For example passing the following: │ │ │ │ │ - * │ │ │ │ │ - * > var control = new OpenLayers.Control({div: myDiv}); │ │ │ │ │ - * │ │ │ │ │ - * Overrides the default div attribute value of null. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - // We do this before the extend so that instances can override │ │ │ │ │ - // className in options. │ │ │ │ │ - this.displayClass = │ │ │ │ │ - this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, ""); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events(this); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.events) { │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - │ │ │ │ │ - // eliminate circular references │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers) { │ │ │ │ │ - for (var key in this.handlers) { │ │ │ │ │ - if (this.handlers.hasOwnProperty(key) && │ │ │ │ │ - typeof this.handlers[key].destroy == "function") { │ │ │ │ │ - this.handlers[key].destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.handlers = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.removeControl(this); │ │ │ │ │ - this.map = null; │ │ │ │ │ - } │ │ │ │ │ - this.div = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. This is done through an accessor │ │ │ │ │ - * so that subclasses can override this and take special action once │ │ │ │ │ - * they have their map variable set. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * The draw method is called when the control is ready to be displayed │ │ │ │ │ - * on the page. If a div has not been created one is created. Controls │ │ │ │ │ - * with a visual component will almost always want to override this method │ │ │ │ │ - * to customize the look of control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} The top-left pixel position of the control │ │ │ │ │ - * or null. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - if (this.div == null) { │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ - this.div.className = this.displayClass; │ │ │ │ │ - if (!this.allowSelection) { │ │ │ │ │ - this.div.className += " olControlNoSelect"; │ │ │ │ │ - this.div.setAttribute("unselectable", "on", 0); │ │ │ │ │ - this.div.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ - if (this.title != "") { │ │ │ │ │ - this.div.title = this.title; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.position = px.clone(); │ │ │ │ │ - } │ │ │ │ │ - this.moveTo(this.position); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ - * coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Explicitly activates a control and it's associated │ │ │ │ │ - * handler if one has been set. Controls can be │ │ │ │ │ - * deactivated by calling the deactivate() method. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the control was successfully activated or │ │ │ │ │ - * false if the control was already active. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.activate(); │ │ │ │ │ - } │ │ │ │ │ - this.active = true; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, │ │ │ │ │ - this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("activate"); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivates a control and it's associated handler if any. The exact │ │ │ │ │ - * effect of this depends on the control itself. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the control was effectively deactivated or false │ │ │ │ │ - * if the control was already inactive. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - this.active = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, │ │ │ │ │ - this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("deactivate"); │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_BUTTON │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_BUTTON = 1; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_TOGGLE │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_TOGGLE = 2; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_TOOL │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_TOOL = 3; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry │ │ │ │ │ - * A Geometry is a description of a geographic object. Create an instance of │ │ │ │ │ - * this class with the constructor. This is a base class, │ │ │ │ │ - * typical geometry types are described by subclasses of this class. │ │ │ │ │ - * │ │ │ │ │ - * Note that if you use the method, you must │ │ │ │ │ - * explicitly include the OpenLayers.Format.WKT in your build. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique identifier for this geometry. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: parent │ │ │ │ │ - * {}This is set when a Geometry is added as component │ │ │ │ │ - * of another geometry │ │ │ │ │ - */ │ │ │ │ │ - parent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The bounds of this geometry │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry │ │ │ │ │ - * Creates a geometry object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function() { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this geometry. Does not set any non-standard │ │ │ │ │ - * properties of the cloned geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this geometry. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Geometry(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBounds │ │ │ │ │ - * Set the bounds for this Geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - setBounds: function(bounds) { │ │ │ │ │ - if (bounds) { │ │ │ │ │ - this.bounds = bounds.clone(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearBounds │ │ │ │ │ - * Nullify this components bounds and that of its parent as well. │ │ │ │ │ - */ │ │ │ │ │ - clearBounds: function() { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - if (this.parent) { │ │ │ │ │ - this.parent.clearBounds(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extendBounds │ │ │ │ │ - * Extend the existing bounds to include the new bounds. │ │ │ │ │ - * If geometry's bounds is not yet set, then set a new Bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newBounds - {} │ │ │ │ │ - */ │ │ │ │ │ - extendBounds: function(newBounds) { │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if (!bounds) { │ │ │ │ │ - this.setBounds(newBounds); │ │ │ │ │ - } else { │ │ │ │ │ - this.bounds.extend(newBounds); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getBounds │ │ │ │ │ - * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ - * is calculated again, this makes queries faster. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getBounds: function() { │ │ │ │ │ - if (this.bounds == null) { │ │ │ │ │ - this.calculateBounds(); │ │ │ │ │ - } │ │ │ │ │ - return this.bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds for the geometry. │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - // │ │ │ │ │ - // This should be overridden by subclasses. │ │ │ │ │ - // │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options depend on the specific geometry type. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: atPoint │ │ │ │ │ - * Note - This is only an approximation based on the bounds of the │ │ │ │ │ - * geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ - * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the geometry is at the specified location │ │ │ │ │ - */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ - │ │ │ │ │ - var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ - var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ - │ │ │ │ │ - var toleranceBounds = │ │ │ │ │ - new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ - this.bounds.bottom - dY, │ │ │ │ │ - this.bounds.right + dX, │ │ │ │ │ - this.bounds.top + dY); │ │ │ │ │ - │ │ │ │ │ - atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ - } │ │ │ │ │ - return atPoint; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getLength │ │ │ │ │ - * Calculate the length of this geometry. This method is defined in │ │ │ │ │ - * subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - //to be overridden by geometries that actually have a length │ │ │ │ │ - // │ │ │ │ │ - return 0.0; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getArea │ │ │ │ │ - * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The area of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - //to be overridden by geometries that actually have an area │ │ │ │ │ - // │ │ │ │ │ - return 0.0; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toString │ │ │ │ │ - * Returns a text representation of the geometry. If the WKT format is │ │ │ │ │ - * included in a build, this will be the Well-Known Text │ │ │ │ │ - * representation. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} String representation of this geometry. │ │ │ │ │ - */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - var string; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ - string = OpenLayers.Format.WKT.prototype.write( │ │ │ │ │ - new OpenLayers.Feature.Vector(this) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - string = Object.prototype.toString.call(this); │ │ │ │ │ - } │ │ │ │ │ - return string; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.fromWKT │ │ │ │ │ - * Generate a geometry given a Well-Known Text string. For this method to │ │ │ │ │ - * work, you must include the OpenLayers.Format.WKT in your build │ │ │ │ │ - * explicitly. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * wkt - {String} A string representing the geometry in Well-Known Text. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry of the appropriate class. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.fromWKT = function(wkt) { │ │ │ │ │ - var geom; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ - var format = OpenLayers.Geometry.fromWKT.format; │ │ │ │ │ - if (!format) { │ │ │ │ │ - format = new OpenLayers.Format.WKT(); │ │ │ │ │ - OpenLayers.Geometry.fromWKT.format = format; │ │ │ │ │ - } │ │ │ │ │ - var result = format.read(wkt); │ │ │ │ │ - if (result instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - geom = result.geometry; │ │ │ │ │ - } else if (OpenLayers.Util.isArray(result)) { │ │ │ │ │ - var len = result.length; │ │ │ │ │ - var components = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - components[i] = result[i].geometry; │ │ │ │ │ - } │ │ │ │ │ - geom = new OpenLayers.Geometry.Collection(components); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return geom; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Method: OpenLayers.Geometry.segmentsIntersect │ │ │ │ │ - * Determine whether two line segments intersect. Optionally calculates │ │ │ │ │ - * and returns the intersection point. This function is optimized for │ │ │ │ │ - * cases where seg1.x2 >= seg2.x1 || seg2.x2 >= seg1.x1. In those │ │ │ │ │ - * obvious cases where there is no intersection, the function should │ │ │ │ │ - * not be called. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * seg1 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ - * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ - * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ - * seg2 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ - * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ - * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ - * options - {Object} Optional properties for calculating the intersection. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * point - {Boolean} Return the intersection point. If false, the actual │ │ │ │ │ - * intersection point will not be calculated. If true and the segments │ │ │ │ │ - * intersect, the intersection point will be returned. If true and │ │ │ │ │ - * the segments do not intersect, false will be returned. If true and │ │ │ │ │ - * the segments are coincident, true will be returned. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, if the segments are │ │ │ │ │ - * within the tolerance distance, this will be considered an intersection. │ │ │ │ │ - * In addition, if the point option is true and the calculated intersection │ │ │ │ │ - * is within the tolerance distance of an end point, the endpoint will be │ │ │ │ │ - * returned instead of the calculated intersection. Further, if the │ │ │ │ │ - * intersection is within the tolerance of endpoints on both segments, or │ │ │ │ │ - * if two segment endpoints are within the tolerance distance of eachother │ │ │ │ │ - * (but no intersection is otherwise calculated), an endpoint on the │ │ │ │ │ - * first segment provided will be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean | } The two segments intersect. │ │ │ │ │ - * If the point argument is true, the return will be the intersection │ │ │ │ │ - * point or false if none exists. If point is true and the segments │ │ │ │ │ - * are coincident, return will be true (and the instersection is equal │ │ │ │ │ - * to the shorter segment). │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.segmentsIntersect = function(seg1, seg2, options) { │ │ │ │ │ - var point = options && options.point; │ │ │ │ │ - var tolerance = options && options.tolerance; │ │ │ │ │ - var intersection = false; │ │ │ │ │ - var x11_21 = seg1.x1 - seg2.x1; │ │ │ │ │ - var y11_21 = seg1.y1 - seg2.y1; │ │ │ │ │ - var x12_11 = seg1.x2 - seg1.x1; │ │ │ │ │ - var y12_11 = seg1.y2 - seg1.y1; │ │ │ │ │ - var y22_21 = seg2.y2 - seg2.y1; │ │ │ │ │ - var x22_21 = seg2.x2 - seg2.x1; │ │ │ │ │ - var d = (y22_21 * x12_11) - (x22_21 * y12_11); │ │ │ │ │ - var n1 = (x22_21 * y11_21) - (y22_21 * x11_21); │ │ │ │ │ - var n2 = (x12_11 * y11_21) - (y12_11 * x11_21); │ │ │ │ │ - if (d == 0) { │ │ │ │ │ - // parallel │ │ │ │ │ - if (n1 == 0 && n2 == 0) { │ │ │ │ │ - // coincident │ │ │ │ │ - intersection = true; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - var along1 = n1 / d; │ │ │ │ │ - var along2 = n2 / d; │ │ │ │ │ - if (along1 >= 0 && along1 <= 1 && along2 >= 0 && along2 <= 1) { │ │ │ │ │ - // intersect │ │ │ │ │ - if (!point) { │ │ │ │ │ - intersection = true; │ │ │ │ │ - } else { │ │ │ │ │ - // calculate the intersection point │ │ │ │ │ - var x = seg1.x1 + (along1 * x12_11); │ │ │ │ │ - var y = seg1.y1 + (along1 * y12_11); │ │ │ │ │ - intersection = new OpenLayers.Geometry.Point(x, y); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (tolerance) { │ │ │ │ │ - var dist; │ │ │ │ │ - if (intersection) { │ │ │ │ │ - if (point) { │ │ │ │ │ - var segs = [seg1, seg2]; │ │ │ │ │ - var seg, x, y; │ │ │ │ │ - // check segment endpoints for proximity to intersection │ │ │ │ │ - // set intersection to first endpoint within the tolerance │ │ │ │ │ - outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ - seg = segs[i]; │ │ │ │ │ - for (var j = 1; j < 3; ++j) { │ │ │ │ │ - x = seg["x" + j]; │ │ │ │ │ - y = seg["y" + j]; │ │ │ │ │ - dist = Math.sqrt( │ │ │ │ │ - Math.pow(x - intersection.x, 2) + │ │ │ │ │ - Math.pow(y - intersection.y, 2) │ │ │ │ │ - ); │ │ │ │ │ - if (dist < tolerance) { │ │ │ │ │ - intersection.x = x; │ │ │ │ │ - intersection.y = y; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // no calculated intersection, but segments could be within │ │ │ │ │ - // the tolerance of one another │ │ │ │ │ - var segs = [seg1, seg2]; │ │ │ │ │ - var source, target, x, y, p, result; │ │ │ │ │ - // check segment endpoints for proximity to intersection │ │ │ │ │ - // set intersection to first endpoint within the tolerance │ │ │ │ │ - outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ - source = segs[i]; │ │ │ │ │ - target = segs[(i + 1) % 2]; │ │ │ │ │ - for (var j = 1; j < 3; ++j) { │ │ │ │ │ - p = { │ │ │ │ │ - x: source["x" + j], │ │ │ │ │ - y: source["y" + j] │ │ │ │ │ - }; │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment(p, target); │ │ │ │ │ - if (result.distance < tolerance) { │ │ │ │ │ - if (point) { │ │ │ │ │ - intersection = new OpenLayers.Geometry.Point(p.x, p.y); │ │ │ │ │ - } else { │ │ │ │ │ - intersection = true; │ │ │ │ │ - } │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return intersection; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.distanceToSegment │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Object} An object with x and y properties representing the │ │ │ │ │ - * point coordinates. │ │ │ │ │ - * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ - * representing endpoint coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with distance, along, x, and y properties. The distance │ │ │ │ │ - * will be the shortest distance between the input point and segment. │ │ │ │ │ - * The x and y properties represent the coordinates along the segment │ │ │ │ │ - * where the shortest distance meets the segment. The along attribute │ │ │ │ │ - * describes how far between the two segment points the given point is. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.distanceToSegment = function(point, segment) { │ │ │ │ │ - var result = OpenLayers.Geometry.distanceSquaredToSegment(point, segment); │ │ │ │ │ - result.distance = Math.sqrt(result.distance); │ │ │ │ │ - return result; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.distanceSquaredToSegment │ │ │ │ │ - * │ │ │ │ │ - * Usually the distanceToSegment function should be used. This variant however │ │ │ │ │ - * can be used for comparisons where the exact distance is not important. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Object} An object with x and y properties representing the │ │ │ │ │ - * point coordinates. │ │ │ │ │ - * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ - * representing endpoint coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with squared distance, along, x, and y properties. │ │ │ │ │ - * The distance will be the shortest distance between the input point and │ │ │ │ │ - * segment. The x and y properties represent the coordinates along the │ │ │ │ │ - * segment where the shortest distance meets the segment. The along │ │ │ │ │ - * attribute describes how far between the two segment points the given │ │ │ │ │ - * point is. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.distanceSquaredToSegment = function(point, segment) { │ │ │ │ │ - var x0 = point.x; │ │ │ │ │ - var y0 = point.y; │ │ │ │ │ - var x1 = segment.x1; │ │ │ │ │ - var y1 = segment.y1; │ │ │ │ │ - var x2 = segment.x2; │ │ │ │ │ - var y2 = segment.y2; │ │ │ │ │ - var dx = x2 - x1; │ │ │ │ │ - var dy = y2 - y1; │ │ │ │ │ - var along = ((dx * (x0 - x1)) + (dy * (y0 - y1))) / │ │ │ │ │ - (Math.pow(dx, 2) + Math.pow(dy, 2)); │ │ │ │ │ - var x, y; │ │ │ │ │ - if (along <= 0.0) { │ │ │ │ │ - x = x1; │ │ │ │ │ - y = y1; │ │ │ │ │ - } else if (along >= 1.0) { │ │ │ │ │ - x = x2; │ │ │ │ │ - y = y2; │ │ │ │ │ - } else { │ │ │ │ │ - x = x1 + along * dx; │ │ │ │ │ - y = y1 + along * dy; │ │ │ │ │ - } │ │ │ │ │ - return { │ │ │ │ │ - distance: Math.pow(x - x0, 2) + Math.pow(y - y0, 2), │ │ │ │ │ - x: x, │ │ │ │ │ - y: y, │ │ │ │ │ - along: along │ │ │ │ │ - }; │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Protocol.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Protocol │ │ │ │ │ - * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the protocol subclasses instead. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {} The format used by this protocol. │ │ │ │ │ - */ │ │ │ │ │ - format: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: autoDestroy │ │ │ │ │ - * {Boolean} The creator of the protocol can set autoDestroy to false │ │ │ │ │ - * to fully control when the protocol is destroyed. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultFilter │ │ │ │ │ - * {} Optional default filter to read requests │ │ │ │ │ - */ │ │ │ │ │ - defaultFilter: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Protocol │ │ │ │ │ - * Abstract class for vector protocols. Create instances of a subclass. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mergeWithDefaultFilter │ │ │ │ │ - * Merge filter passed to the read method with the default one │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} │ │ │ │ │ - */ │ │ │ │ │ - mergeWithDefaultFilter: function(filter) { │ │ │ │ │ - var merged; │ │ │ │ │ - if (filter && this.defaultFilter) { │ │ │ │ │ - merged = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.AND, │ │ │ │ │ - filters: [this.defaultFilter, filter] │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - merged = filter || this.defaultFilter || undefined; │ │ │ │ │ - } │ │ │ │ │ - return merged; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up the protocol. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.options = null; │ │ │ │ │ - this.format = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Construct a request for reading new features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An │ │ │ │ │ - * object, the same object will be passed to the callback function passed │ │ │ │ │ - * if one exists in the options object. │ │ │ │ │ - */ │ │ │ │ │ - read: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.filter = this.mergeWithDefaultFilter(options.filter); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: create │ │ │ │ │ - * Construct a request for writing newly created features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array({})} or │ │ │ │ │ - * {} │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An │ │ │ │ │ - * object, the same object will be passed to the callback function passed │ │ │ │ │ - * if one exists in the options object. │ │ │ │ │ - */ │ │ │ │ │ - create: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: update │ │ │ │ │ - * Construct a request updating modified features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array({})} or │ │ │ │ │ - * {} │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An │ │ │ │ │ - * object, the same object will be passed to the callback function passed │ │ │ │ │ - * if one exists in the options object. │ │ │ │ │ - */ │ │ │ │ │ - update: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: delete │ │ │ │ │ - * Construct a request deleting a removed feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An │ │ │ │ │ - * object, the same object will be passed to the callback function passed │ │ │ │ │ - * if one exists in the options object. │ │ │ │ │ - */ │ │ │ │ │ - "delete": function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: commit │ │ │ │ │ - * Go over the features and for each take action │ │ │ │ │ - * based on the feature state. Possible actions are create, │ │ │ │ │ - * update and delete. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array({})} │ │ │ │ │ - * options - {Object} Object whose possible keys are "create", "update", │ │ │ │ │ - * "delete", "callback" and "scope", the values referenced by the │ │ │ │ │ - * first three are objects as passed to the "create", "update", and │ │ │ │ │ - * "delete" methods, the value referenced by the "callback" key is │ │ │ │ │ - * a function which is called when the commit operation is complete │ │ │ │ │ - * using the scope referenced by the "scope" key. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array({})} An array of │ │ │ │ │ - * objects. │ │ │ │ │ - */ │ │ │ │ │ - commit: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: abort │ │ │ │ │ - * Abort an ongoing request. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * response - {} │ │ │ │ │ - */ │ │ │ │ │ - abort: function(response) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createCallback │ │ │ │ │ - * Returns a function that applies the given public method with resp and │ │ │ │ │ - * options arguments. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * method - {Function} The method to be applied by the callback. │ │ │ │ │ - * response - {} The protocol response object. │ │ │ │ │ - * options - {Object} Options sent to the protocol method │ │ │ │ │ - */ │ │ │ │ │ - createCallback: function(method, response, options) { │ │ │ │ │ - return OpenLayers.Function.bind(function() { │ │ │ │ │ - method.apply(this, [response, options]); │ │ │ │ │ - }, this); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Protocol" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Protocol.Response │ │ │ │ │ - * Protocols return Response objects to their users. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Protocol.Response = OpenLayers.Class({ │ │ │ │ │ - /** │ │ │ │ │ - * Property: code │ │ │ │ │ - * {Number} - OpenLayers.Protocol.Response.SUCCESS or │ │ │ │ │ - * OpenLayers.Protocol.Response.FAILURE │ │ │ │ │ - */ │ │ │ │ │ - code: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: requestType │ │ │ │ │ - * {String} The type of request this response corresponds to. Either │ │ │ │ │ - * "create", "read", "update" or "delete". │ │ │ │ │ - */ │ │ │ │ │ - requestType: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ - * false otherwise, defaults to true. │ │ │ │ │ - */ │ │ │ │ │ - last: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: features │ │ │ │ │ - * {Array({})} or {} │ │ │ │ │ - * The features returned in the response by the server. Depending on the │ │ │ │ │ - * protocol's read payload, either features or data will be populated. │ │ │ │ │ - */ │ │ │ │ │ - features: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: data │ │ │ │ │ - * {Object} │ │ │ │ │ - * The data returned in the response by the server. Depending on the │ │ │ │ │ - * protocol's read payload, either features or data will be populated. │ │ │ │ │ - */ │ │ │ │ │ - data: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: reqFeatures │ │ │ │ │ - * {Array({})} or {} │ │ │ │ │ - * The features provided by the user and placed in the request by the │ │ │ │ │ - * protocol. │ │ │ │ │ - */ │ │ │ │ │ - reqFeatures: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: priv │ │ │ │ │ - */ │ │ │ │ │ - priv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: error │ │ │ │ │ - * {Object} The error object in case a service exception was encountered. │ │ │ │ │ - */ │ │ │ │ │ - error: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: success │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} - true on success, false otherwise │ │ │ │ │ - */ │ │ │ │ │ - success: function() { │ │ │ │ │ - return this.code > 0; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Protocol.Response" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Protocol.Response.SUCCESS = 1; │ │ │ │ │ -OpenLayers.Protocol.Response.FAILURE = 0; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Icon.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Icon │ │ │ │ │ - * │ │ │ │ │ - * The icon represents a graphical icon on the screen. Typically used in │ │ │ │ │ - * conjunction with a to represent markers on a screen. │ │ │ │ │ - * │ │ │ │ │ - * An icon has a url, size and position. It also contains an offset which │ │ │ │ │ - * allows the center point to be represented correctly. This can be │ │ │ │ │ - * provided either as a fixed offset or a function provided to calculate │ │ │ │ │ - * the desired offset. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} image url │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: offset │ │ │ │ │ - * {|Object} distance in pixels to offset the │ │ │ │ │ - * image when being rendered. An OpenLayers.Pixel or an object │ │ │ │ │ - * with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - offset: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: calculateOffset │ │ │ │ │ - * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ - */ │ │ │ │ │ - calculateOffset: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - imageDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ - * with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - px: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Icon │ │ │ │ │ - * Creates an icon, which is an image tag in a div. │ │ │ │ │ - * │ │ │ │ │ - * url - {String} │ │ │ │ │ - * size - {|Object} An OpenLayers.Size or an │ │ │ │ │ - * object with a 'w' and 'h' │ │ │ │ │ - * properties. │ │ │ │ │ - * offset - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ - * object with a 'x' and 'y' │ │ │ │ │ - * properties. │ │ │ │ │ - * calculateOffset - {Function} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(url, size, offset, calculateOffset) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - this.size = size || { │ │ │ │ │ - w: 20, │ │ │ │ │ - h: 20 │ │ │ │ │ - }; │ │ │ │ │ - this.offset = offset || { │ │ │ │ │ - x: -(this.size.w / 2), │ │ │ │ │ - y: -(this.size.h / 2) │ │ │ │ │ - }; │ │ │ │ │ - this.calculateOffset = calculateOffset; │ │ │ │ │ - │ │ │ │ │ - var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ - this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Nullify references and remove event listeners to prevent circular │ │ │ │ │ - * references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // erase any drawn elements │ │ │ │ │ - this.erase(); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ - this.imageDiv.innerHTML = ""; │ │ │ │ │ - this.imageDiv = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A fresh copy of the icon. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Icon(this.url, │ │ │ │ │ - this.size, │ │ │ │ │ - this.offset, │ │ │ │ │ - this.calculateOffset); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(size) { │ │ │ │ │ - if (size != null) { │ │ │ │ │ - this.size = size; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} │ │ │ │ │ - */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - if (url != null) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Move the div to the given pixel. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ - * object with a 'x' and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image of this icon set at the location passed-in │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - this.size, │ │ │ │ │ - this.url, │ │ │ │ │ - "absolute"); │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - return this.imageDiv; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erase the underlying image element. │ │ │ │ │ - */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ - OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the icon's opacity │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ - null, null, null, null, opacity); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * move icon to passed in px. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - //if no px passed in, use stored location │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.px = px; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.imageDiv != null) { │ │ │ │ │ - if (this.px == null) { │ │ │ │ │ - this.display(false); │ │ │ │ │ - } else { │ │ │ │ │ - if (this.calculateOffset) { │ │ │ │ │ - this.offset = this.calculateOffset(this.size); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { │ │ │ │ │ - x: this.px.x + this.offset.x, │ │ │ │ │ - y: this.px.y + this.offset.y │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ - */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - // nodeType 11 for ie, whose nodes *always* have a parentNode │ │ │ │ │ - // (of type document fragment) │ │ │ │ │ - var isDrawn = (this.imageDiv && this.imageDiv.parentNode && │ │ │ │ │ - (this.imageDiv.parentNode.nodeType != 11)); │ │ │ │ │ - │ │ │ │ │ - return isDrawn; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Feature.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Feature │ │ │ │ │ - * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ - * class specifically combines a marker and a lonlat. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: data │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - data: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: marker │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - marker: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: popupClass │ │ │ │ │ - * {} The class which will be used to instantiate │ │ │ │ │ - * a new Popup. Default is . │ │ │ │ │ - */ │ │ │ │ │ - popupClass: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: popup │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - popup: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature │ │ │ │ │ - * Constructor for features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * data - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, lonlat, data) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ - this.data = (data != null) ? data : {}; │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - //remove the popup from the map │ │ │ │ │ - if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ - if (this.popup != null) { │ │ │ │ │ - this.layer.map.removePopup(this.popup); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // remove the marker from the layer │ │ │ │ │ - if (this.layer != null && this.marker != null) { │ │ │ │ │ - this.layer.removeMarker(this.marker); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.data = null; │ │ │ │ │ - if (this.marker != null) { │ │ │ │ │ - this.destroyMarker(this.marker); │ │ │ │ │ - this.marker = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.popup != null) { │ │ │ │ │ - this.destroyPopup(this.popup); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ - * (based on its 'lonlat' property) │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ - var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Marker Object created from the 'lonlat' and 'icon' properties │ │ │ │ │ - * set in this.data. If no 'lonlat' is set, returns null. If no │ │ │ │ │ - * 'icon' is set, OpenLayers.Marker() will load the default image. │ │ │ │ │ - * │ │ │ │ │ - * Note - this.marker is set to return value │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ - } │ │ │ │ │ - return this.marker; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * Destroys marker. │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ - */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - this.marker.destroy(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * Creates a popup object created from the 'lonlat', 'popupSize', │ │ │ │ │ - * and 'popupContentHTML' properties set in this.data. It uses │ │ │ │ │ - * this.marker.icon as default anchor. │ │ │ │ │ - * │ │ │ │ │ - * If no 'lonlat' is set, returns null. │ │ │ │ │ - * If no this.marker has been created, no anchor is sent. │ │ │ │ │ - * │ │ │ │ │ - * Note - the returned popup object is 'owned' by the feature, so you │ │ │ │ │ - * cannot use the popup's destroy method to discard the popup. │ │ │ │ │ - * Instead, you must use the feature's destroyPopup │ │ │ │ │ - * │ │ │ │ │ - * Note - this.popup is set to return value │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * closeBox - {Boolean} create popup with closebox or not │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Returns the created popup, which is also set │ │ │ │ │ - * as 'popup' property of this feature. Will be of whatever type │ │ │ │ │ - * specified by this feature's 'popupClass' property, but must be │ │ │ │ │ - * of type . │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - createPopup: function(closeBox) { │ │ │ │ │ - │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - if (!this.popup) { │ │ │ │ │ - var anchor = (this.marker) ? this.marker.icon : null; │ │ │ │ │ - var popupClass = this.popupClass ? │ │ │ │ │ - this.popupClass : OpenLayers.Popup.Anchored; │ │ │ │ │ - this.popup = new popupClass(this.id + "_popup", │ │ │ │ │ - this.lonlat, │ │ │ │ │ - this.data.popupSize, │ │ │ │ │ - this.data.popupContentHTML, │ │ │ │ │ - anchor, │ │ │ │ │ - closeBox); │ │ │ │ │ - } │ │ │ │ │ - if (this.data.overflow != null) { │ │ │ │ │ - this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.popup.feature = this; │ │ │ │ │ - } │ │ │ │ │ - return this.popup; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * Destroys the popup created via createPopup. │ │ │ │ │ - * │ │ │ │ │ - * As with the marker, if user overrides the createPopup() function, s/he │ │ │ │ │ - * should also be able to override the destruction │ │ │ │ │ - */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - if (this.popup) { │ │ │ │ │ - this.popup.feature = null; │ │ │ │ │ - this.popup.destroy(); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Feature/Vector.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -// TRASH THIS │ │ │ │ │ -OpenLayers.State = { │ │ │ │ │ - /** states */ │ │ │ │ │ - UNKNOWN: 'Unknown', │ │ │ │ │ - INSERT: 'Insert', │ │ │ │ │ - UPDATE: 'Update', │ │ │ │ │ - DELETE: 'Delete' │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Feature.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Feature.Vector │ │ │ │ │ - * Vector features use the OpenLayers.Geometry classes as geometry description. │ │ │ │ │ - * They have an 'attributes' property, which is the data object, and a 'style' │ │ │ │ │ - * property, the default values of which are defined in the │ │ │ │ │ - * objects. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: fid │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - fid: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometry │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - geometry: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: attributes │ │ │ │ │ - * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ - * describe the feature. │ │ │ │ │ - */ │ │ │ │ │ - attributes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The box bounding that feature's geometry, that │ │ │ │ │ - * property can be set by an object when │ │ │ │ │ - * deserializing the feature, so in most cases it represents an │ │ │ │ │ - * information set by the server. │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: state │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - state: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - style: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} If this property is set it will be taken into account by │ │ │ │ │ - * {} when upadting or deleting the feature. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: renderIntent │ │ │ │ │ - * {String} rendering intent currently being used │ │ │ │ │ - */ │ │ │ │ │ - renderIntent: "default", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: modified │ │ │ │ │ - * {Object} An object with the originals of the geometry and attributes of │ │ │ │ │ - * the feature, if they were changed. Currently this property is only read │ │ │ │ │ - * by , and written by │ │ │ │ │ - * , which sets the geometry property. │ │ │ │ │ - * Applications can set the originals of modified attributes in the │ │ │ │ │ - * attributes property. Note that applications have to check if this │ │ │ │ │ - * object and the attributes property is already created before using it. │ │ │ │ │ - * After a change made with ModifyFeature, this object could look like │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * geometry: >Object │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * When an application has made changes to feature attributes, it could │ │ │ │ │ - * have set the attributes to something like this: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * attributes: { │ │ │ │ │ - * myAttribute: "original" │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Note that only checks for truthy values in │ │ │ │ │ - * *modified.geometry* and the attribute names in *modified.attributes*, │ │ │ │ │ - * but it is recommended to set the original values (and not just true) as │ │ │ │ │ - * attribute value, so applications could use this information to undo │ │ │ │ │ - * changes. │ │ │ │ │ - */ │ │ │ │ │ - modified: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature.Vector │ │ │ │ │ - * Create a vector feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The geometry that this feature │ │ │ │ │ - * represents. │ │ │ │ │ - * attributes - {Object} An optional object that will be mapped to the │ │ │ │ │ - * property. │ │ │ │ │ - * style - {Object} An optional style object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(geometry, attributes, style) { │ │ │ │ │ - OpenLayers.Feature.prototype.initialize.apply(this, │ │ │ │ │ - [null, null, attributes]); │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.geometry = geometry ? geometry : null; │ │ │ │ │ - this.state = null; │ │ │ │ │ - this.attributes = {}; │ │ │ │ │ - if (attributes) { │ │ │ │ │ - this.attributes = OpenLayers.Util.extend(this.attributes, │ │ │ │ │ - attributes); │ │ │ │ │ - } │ │ │ │ │ - this.style = style ? style : null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.layer) { │ │ │ │ │ - this.layer.removeFeatures(this); │ │ │ │ │ - this.layer = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.geometry = null; │ │ │ │ │ - this.modified = null; │ │ │ │ │ - OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ - * properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this vector feature. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - this.geometry ? this.geometry.clone() : null, │ │ │ │ │ - this.attributes, │ │ │ │ │ - this.style); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * Determine whether the feature is within the map viewport. This method │ │ │ │ │ - * tests for an intersection between the geometry and the viewport │ │ │ │ │ - * bounds. If a more effecient but less precise geometry bounds │ │ │ │ │ - * intersection is desired, call the method with the boundsOnly │ │ │ │ │ - * parameter true. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * boundsOnly - {Boolean} Only test whether a feature's bounds intersects │ │ │ │ │ - * the viewport bounds. Default is false. If false, the feature's │ │ │ │ │ - * geometry must intersect the viewport for onScreen to return true. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ - * based on its bounds if boundsOnly is true). │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function(boundsOnly) { │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.layer && this.layer.map) { │ │ │ │ │ - var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ - if (boundsOnly) { │ │ │ │ │ - var featureBounds = this.geometry.getBounds(); │ │ │ │ │ - onScreen = screenBounds.intersectsBounds(featureBounds); │ │ │ │ │ - } else { │ │ │ │ │ - var screenPoly = screenBounds.toGeometry(); │ │ │ │ │ - onScreen = screenPoly.intersects(this.geometry); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getVisibility │ │ │ │ │ - * Determine whether the feature is displayed or not. It may not displayed │ │ │ │ │ - * because: │ │ │ │ │ - * - its style display property is set to 'none', │ │ │ │ │ - * - it doesn't belong to any layer, │ │ │ │ │ - * - the styleMap creates a symbolizer with display property set to 'none' │ │ │ │ │ - * for it, │ │ │ │ │ - * - the layer which it belongs to is not visible. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The feature is currently displayed. │ │ │ │ │ - */ │ │ │ │ │ - getVisibility: function() { │ │ │ │ │ - return !(this.style && this.style.display == 'none' || │ │ │ │ │ - !this.layer || │ │ │ │ │ - this.layer && this.layer.styleMap && │ │ │ │ │ - this.layer.styleMap.createSymbolizer(this, this.renderIntent).display == 'none' || │ │ │ │ │ - this.layer && !this.layer.getVisibility()); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create markers │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ - */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * delete markers │ │ │ │ │ - * │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ - */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - // pass │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create popups │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ - */ │ │ │ │ │ - createPopup: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: atPoint │ │ │ │ │ - * Determins whether the feature intersects with the specified location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ - * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ - */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - if (this.geometry) { │ │ │ │ │ - atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ - toleranceLat); │ │ │ │ │ - } │ │ │ │ │ - return atPoint; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * delete popups │ │ │ │ │ - */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - // pass │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Moves the feature and redraws it at its new location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * location - { or } the │ │ │ │ │ - * location to which to move the feature. │ │ │ │ │ - */ │ │ │ │ │ - move: function(location) { │ │ │ │ │ - │ │ │ │ │ - if (!this.layer || !this.geometry.move) { │ │ │ │ │ - //do nothing if no layer or immoveable geometry │ │ │ │ │ - return undefined; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var pixel; │ │ │ │ │ - if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ - pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ - } else { │ │ │ │ │ - pixel = location; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat()); │ │ │ │ │ - var res = this.layer.map.getResolution(); │ │ │ │ │ - this.geometry.move(res * (pixel.x - lastPixel.x), │ │ │ │ │ - res * (lastPixel.y - pixel.y)); │ │ │ │ │ - this.layer.drawFeature(this); │ │ │ │ │ - return lastPixel; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toState │ │ │ │ │ - * Sets the new state │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * state - {String} │ │ │ │ │ - */ │ │ │ │ │ - toState: function(state) { │ │ │ │ │ - if (state == OpenLayers.State.UPDATE) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - case OpenLayers.State.DELETE: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.UPDATE: │ │ │ │ │ - case OpenLayers.State.INSERT: │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.DELETE) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.INSERT: │ │ │ │ │ - // the feature should be destroyed │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.DELETE: │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - case OpenLayers.State.UPDATE: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.UNKNOWN) { │ │ │ │ │ - this.state = state; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature.Vector" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Feature.Vector.style │ │ │ │ │ - * OpenLayers features can have a number of style attributes. The 'default' │ │ │ │ │ - * style will typically be used if no other style is specified. These │ │ │ │ │ - * styles correspond for the most part, to the styling properties defined │ │ │ │ │ - * by the SVG standard. │ │ │ │ │ - * Information on fill properties: http://www.w3.org/TR/SVG/painting.html#FillProperties │ │ │ │ │ - * Information on stroke properties: http://www.w3.org/TR/SVG/painting.html#StrokeProperties │ │ │ │ │ - * │ │ │ │ │ - * Symbolizer properties: │ │ │ │ │ - * fill - {Boolean} Set to false if no fill is desired. │ │ │ │ │ - * fillColor - {String} Hex fill color. Default is "#ee9900". │ │ │ │ │ - * fillOpacity - {Number} Fill opacity (0-1). Default is 0.4 │ │ │ │ │ - * stroke - {Boolean} Set to false if no stroke is desired. │ │ │ │ │ - * strokeColor - {String} Hex stroke color. Default is "#ee9900". │ │ │ │ │ - * strokeOpacity - {Number} Stroke opacity (0-1). Default is 1. │ │ │ │ │ - * strokeWidth - {Number} Pixel stroke width. Default is 1. │ │ │ │ │ - * strokeLinecap - {String} Stroke cap type. Default is "round". [butt | round | square] │ │ │ │ │ - * strokeDashstyle - {String} Stroke dash style. Default is "solid". [dot | dash | dashdot | longdash | longdashdot | solid] │ │ │ │ │ - * graphic - {Boolean} Set to false if no graphic is desired. │ │ │ │ │ - * pointRadius - {Number} Pixel point radius. Default is 6. │ │ │ │ │ - * pointerEvents - {String} Default is "visiblePainted". │ │ │ │ │ - * cursor - {String} Default is "". │ │ │ │ │ - * externalGraphic - {String} Url to an external graphic that will be used for rendering points. │ │ │ │ │ - * graphicWidth - {Number} Pixel width for sizing an external graphic. │ │ │ │ │ - * graphicHeight - {Number} Pixel height for sizing an external graphic. │ │ │ │ │ - * graphicOpacity - {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ - * graphicXOffset - {Number} Pixel offset along the positive x axis for displacing an external graphic. │ │ │ │ │ - * graphicYOffset - {Number} Pixel offset along the positive y axis for displacing an external graphic. │ │ │ │ │ - * rotation - {Number} For point symbolizers, this is the rotation of a graphic in the clockwise direction about its center point (or any point off center as specified by graphicXOffset and graphicYOffset). │ │ │ │ │ - * graphicZIndex - {Number} The integer z-index value to use in rendering. │ │ │ │ │ - * graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default), │ │ │ │ │ - * "square", "star", "x", "cross", "triangle". │ │ │ │ │ - * graphicTitle - {String} Tooltip when hovering over a feature. *deprecated*, use title instead │ │ │ │ │ - * title - {String} Tooltip when hovering over a feature. Not supported by the canvas renderer. │ │ │ │ │ - * backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic. │ │ │ │ │ - * backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic. │ │ │ │ │ - * backgroundXOffset - {Number} The x offset (in pixels) for the background graphic. │ │ │ │ │ - * backgroundYOffset - {Number} The y offset (in pixels) for the background graphic. │ │ │ │ │ - * backgroundHeight - {Number} The height of the background graphic. If not provided, the graphicHeight will be used. │ │ │ │ │ - * backgroundWidth - {Number} The width of the background width. If not provided, the graphicWidth will be used. │ │ │ │ │ - * label - {String} The text for an optional label. For browsers that use the canvas renderer, this requires either │ │ │ │ │ - * fillText or mozDrawText to be available. │ │ │ │ │ - * labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string │ │ │ │ │ - * composed of two characters. The first character is for the horizontal alignment, the second for the vertical │ │ │ │ │ - * alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical │ │ │ │ │ - * alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". Default is "cm". │ │ │ │ │ - * labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ - * labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ - * labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * labelOutlineColor - {String} The color of the label outline. Default is 'white'. Only supported by the canvas & SVG renderers. │ │ │ │ │ - * labelOutlineWidth - {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the SVG renderers. │ │ │ │ │ - * labelOutlineOpacity - {Number} The opacity (0-1) of the label outline. Default is fontOpacity. Only supported by the canvas & SVG renderers. │ │ │ │ │ - * fontColor - {String} The font color for the label, to be provided like CSS. │ │ │ │ │ - * fontOpacity - {Number} Opacity (0-1) for the label │ │ │ │ │ - * fontFamily - {String} The font family for the label, to be provided like in CSS. │ │ │ │ │ - * fontSize - {String} The font size for the label, to be provided like in CSS. │ │ │ │ │ - * fontStyle - {String} The font style for the label, to be provided like in CSS. │ │ │ │ │ - * fontWeight - {String} The font weight for the label, to be provided like in CSS. │ │ │ │ │ - * display - {String} Symbolizers will have no effect if display is set to "none". All other values have no effect. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature.Vector.style = { │ │ │ │ │ - 'default': { │ │ │ │ │ - fillColor: "#ee9900", │ │ │ │ │ - fillOpacity: 0.4, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "#ee9900", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "inherit", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - }, │ │ │ │ │ - 'select': { │ │ │ │ │ - fillColor: "blue", │ │ │ │ │ - fillOpacity: 0.4, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "blue", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeWidth: 2, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "pointer", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - 'temporary': { │ │ │ │ │ - fillColor: "#66cccc", │ │ │ │ │ - fillOpacity: 0.2, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "#66cccc", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeWidth: 2, │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "inherit", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - 'delete': { │ │ │ │ │ - display: "none" │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Style.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Style │ │ │ │ │ - * This class represents a UserStyle obtained │ │ │ │ │ - * from a SLD, containing styling rules. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: title │ │ │ │ │ - * {String} Title of this style (set if included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - title: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this style (set if abstract is included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - description: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {} name of the layer that this style belongs to, usually │ │ │ │ │ - * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ - */ │ │ │ │ │ - layerName: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isDefault │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isDefault: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: rules │ │ │ │ │ - * {Array()} │ │ │ │ │ - */ │ │ │ │ │ - rules: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: context │ │ │ │ │ - * {Object} An optional object with properties that symbolizers' property │ │ │ │ │ - * values should be evaluated against. If no context is specified, │ │ │ │ │ - * feature.attributes will be used │ │ │ │ │ - */ │ │ │ │ │ - context: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultStyle │ │ │ │ │ - * {Object} hash of style properties to use as default for merging │ │ │ │ │ - * rule-based style symbolizers onto. If no rules are defined, │ │ │ │ │ - * createSymbolizer will return this style. If is set to │ │ │ │ │ - * true, the defaultStyle will only be taken into account if there are │ │ │ │ │ - * rules defined. │ │ │ │ │ - */ │ │ │ │ │ - defaultStyle: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultsPerSymbolizer │ │ │ │ │ - * {Boolean} If set to true, the will extend the symbolizer │ │ │ │ │ - * of every rule. Properties of the will also be used to set │ │ │ │ │ - * missing symbolizer properties if the symbolizer has stroke, fill or │ │ │ │ │ - * graphic set to true. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - defaultsPerSymbolizer: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: propertyStyles │ │ │ │ │ - * {Hash of Boolean} cache of style properties that need to be parsed for │ │ │ │ │ - * propertyNames. Property names are keys, values won't be used. │ │ │ │ │ - */ │ │ │ │ │ - propertyStyles: null, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Style │ │ │ │ │ - * Creates a UserStyle. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * style - {Object} Optional hash of style properties that will be │ │ │ │ │ - * used as default style for this style object. This style │ │ │ │ │ - * applies if no rules are specified. Symbolizers defined in │ │ │ │ │ - * rules will extend this default style. │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * style. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * rules - {Array()} List of rules to be added to the │ │ │ │ │ - * style. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(style, options) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.rules = []; │ │ │ │ │ - if (options && options.rules) { │ │ │ │ │ - this.addRules(options.rules); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // use the default style from OpenLayers.Feature.Vector if no style │ │ │ │ │ - // was given in the constructor │ │ │ │ │ - this.setDefaultStyle(style || │ │ │ │ │ - OpenLayers.Feature.Vector.style["default"]); │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ - this.rules[i].destroy(); │ │ │ │ │ - this.rules[i] = null; │ │ │ │ │ - } │ │ │ │ │ - this.rules = null; │ │ │ │ │ - this.defaultStyle = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createSymbolizer │ │ │ │ │ - * creates a style by applying all feature-dependent rules to the base │ │ │ │ │ - * style. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} feature to evaluate rules for │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} symbolizer hash │ │ │ │ │ - */ │ │ │ │ │ - createSymbolizer: function(feature) { │ │ │ │ │ - var style = this.defaultsPerSymbolizer ? {} : this.createLiterals( │ │ │ │ │ - OpenLayers.Util.extend({}, this.defaultStyle), feature); │ │ │ │ │ - │ │ │ │ │ - var rules = this.rules; │ │ │ │ │ - │ │ │ │ │ - var rule, context; │ │ │ │ │ - var elseRules = []; │ │ │ │ │ - var appliedRules = false; │ │ │ │ │ - for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ - rule = rules[i]; │ │ │ │ │ - // does the rule apply? │ │ │ │ │ - var applies = rule.evaluate(feature); │ │ │ │ │ - │ │ │ │ │ - if (applies) { │ │ │ │ │ - if (rule instanceof OpenLayers.Rule && rule.elseFilter) { │ │ │ │ │ - elseRules.push(rule); │ │ │ │ │ - } else { │ │ │ │ │ - appliedRules = true; │ │ │ │ │ - this.applySymbolizer(rule, style, feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if no other rules apply, apply the rules with else filters │ │ │ │ │ - if (appliedRules == false && elseRules.length > 0) { │ │ │ │ │ - appliedRules = true; │ │ │ │ │ - for (var i = 0, len = elseRules.length; i < len; i++) { │ │ │ │ │ - this.applySymbolizer(elseRules[i], style, feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // don't display if there were rules but none applied │ │ │ │ │ - if (rules.length > 0 && appliedRules == false) { │ │ │ │ │ - style.display = "none"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (style.label != null && typeof style.label !== "string") { │ │ │ │ │ - style.label = String(style.label); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return style; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: applySymbolizer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * rule - {} │ │ │ │ │ - * style - {Object} │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A style with new symbolizer applied. │ │ │ │ │ - */ │ │ │ │ │ - applySymbolizer: function(rule, style, feature) { │ │ │ │ │ - var symbolizerPrefix = feature.geometry ? │ │ │ │ │ - this.getSymbolizerPrefix(feature.geometry) : │ │ │ │ │ - OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; │ │ │ │ │ - │ │ │ │ │ - var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; │ │ │ │ │ - │ │ │ │ │ - if (this.defaultsPerSymbolizer === true) { │ │ │ │ │ - var defaults = this.defaultStyle; │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - pointRadius: defaults.pointRadius │ │ │ │ │ - }); │ │ │ │ │ - if (symbolizer.stroke === true || symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - strokeWidth: defaults.strokeWidth, │ │ │ │ │ - strokeColor: defaults.strokeColor, │ │ │ │ │ - strokeOpacity: defaults.strokeOpacity, │ │ │ │ │ - strokeDashstyle: defaults.strokeDashstyle, │ │ │ │ │ - strokeLinecap: defaults.strokeLinecap │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fill === true || symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - fillColor: defaults.fillColor, │ │ │ │ │ - fillOpacity: defaults.fillOpacity │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - pointRadius: this.defaultStyle.pointRadius, │ │ │ │ │ - externalGraphic: this.defaultStyle.externalGraphic, │ │ │ │ │ - graphicName: this.defaultStyle.graphicName, │ │ │ │ │ - graphicOpacity: this.defaultStyle.graphicOpacity, │ │ │ │ │ - graphicWidth: this.defaultStyle.graphicWidth, │ │ │ │ │ - graphicHeight: this.defaultStyle.graphicHeight, │ │ │ │ │ - graphicXOffset: this.defaultStyle.graphicXOffset, │ │ │ │ │ - graphicYOffset: this.defaultStyle.graphicYOffset │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // merge the style with the current style │ │ │ │ │ - return this.createLiterals( │ │ │ │ │ - OpenLayers.Util.extend(style, symbolizer), feature); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createLiterals │ │ │ │ │ - * creates literals for all style properties that have an entry in │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * style - {Object} style to create literals for. Will be modified │ │ │ │ │ - * inline. │ │ │ │ │ - * feature - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} the modified style │ │ │ │ │ - */ │ │ │ │ │ - createLiterals: function(style, feature) { │ │ │ │ │ - var context = OpenLayers.Util.extend({}, feature.attributes || feature.data); │ │ │ │ │ - OpenLayers.Util.extend(context, this.context); │ │ │ │ │ - │ │ │ │ │ - for (var i in this.propertyStyles) { │ │ │ │ │ - style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); │ │ │ │ │ - } │ │ │ │ │ - return style; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: findPropertyStyles │ │ │ │ │ - * Looks into all rules for this style and the defaultStyle to collect │ │ │ │ │ - * all the style hash property names containing ${...} strings that have │ │ │ │ │ - * to be replaced using the createLiteral method before returning them. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} hash of property names that need createLiteral parsing. The │ │ │ │ │ - * name of the property is the key, and the value is true; │ │ │ │ │ - */ │ │ │ │ │ - findPropertyStyles: function() { │ │ │ │ │ - var propertyStyles = {}; │ │ │ │ │ - │ │ │ │ │ - // check the default style │ │ │ │ │ - var style = this.defaultStyle; │ │ │ │ │ - this.addPropertyStyles(propertyStyles, style); │ │ │ │ │ - │ │ │ │ │ - // walk through all rules to check for properties in their symbolizer │ │ │ │ │ - var rules = this.rules; │ │ │ │ │ - var symbolizer, value; │ │ │ │ │ - for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ - symbolizer = rules[i].symbolizer; │ │ │ │ │ - for (var key in symbolizer) { │ │ │ │ │ - value = symbolizer[key]; │ │ │ │ │ - if (typeof value == "object") { │ │ │ │ │ - // symbolizer key is "Point", "Line" or "Polygon" │ │ │ │ │ - this.addPropertyStyles(propertyStyles, value); │ │ │ │ │ - } else { │ │ │ │ │ - // symbolizer is a hash of style properties │ │ │ │ │ - this.addPropertyStyles(propertyStyles, symbolizer); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return propertyStyles; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addPropertyStyles │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * propertyStyles - {Object} hash to add new property styles to. Will be │ │ │ │ │ - * modified inline │ │ │ │ │ - * symbolizer - {Object} search this symbolizer for property styles │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} propertyStyles hash │ │ │ │ │ - */ │ │ │ │ │ - addPropertyStyles: function(propertyStyles, symbolizer) { │ │ │ │ │ - var property; │ │ │ │ │ - for (var key in symbolizer) { │ │ │ │ │ - property = symbolizer[key]; │ │ │ │ │ - if (typeof property == "string" && │ │ │ │ │ - property.match(/\$\{\w+\}/)) { │ │ │ │ │ - propertyStyles[key] = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return propertyStyles; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addRules │ │ │ │ │ - * Adds rules to this style. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * rules - {Array()} │ │ │ │ │ - */ │ │ │ │ │ - addRules: function(rules) { │ │ │ │ │ - Array.prototype.push.apply(this.rules, rules); │ │ │ │ │ - this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setDefaultStyle │ │ │ │ │ - * Sets the default style for this style object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * style - {Object} Hash of style properties │ │ │ │ │ - */ │ │ │ │ │ - setDefaultStyle: function(style) { │ │ │ │ │ - this.defaultStyle = style; │ │ │ │ │ - this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSymbolizerPrefix │ │ │ │ │ - * Returns the correct symbolizer prefix according to the │ │ │ │ │ - * geometry type of the passed geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} key of the according symbolizer │ │ │ │ │ - */ │ │ │ │ │ - getSymbolizerPrefix: function(geometry) { │ │ │ │ │ - var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ - for (var i = 0, len = prefixes.length; i < len; i++) { │ │ │ │ │ - if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) { │ │ │ │ │ - return prefixes[i]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this style. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this style. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ - // clone rules │ │ │ │ │ - if (this.rules) { │ │ │ │ │ - options.rules = []; │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ - options.rules.push(this.rules[i].clone()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // clone context │ │ │ │ │ - options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ - //clone default style │ │ │ │ │ - var defaultStyle = OpenLayers.Util.extend({}, this.defaultStyle); │ │ │ │ │ - return new OpenLayers.Style(defaultStyle, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Style" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: createLiteral │ │ │ │ │ - * converts a style value holding a combination of PropertyName and Literal │ │ │ │ │ - * into a Literal, taking the property values from the passed features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * value - {String} value to parse. If this string contains a construct like │ │ │ │ │ - * "foo ${bar}", then "foo " will be taken as literal, and "${bar}" │ │ │ │ │ - * will be replaced by the value of the "bar" attribute of the passed │ │ │ │ │ - * feature. │ │ │ │ │ - * context - {Object} context to take attribute values from │ │ │ │ │ - * feature - {} optional feature to pass to │ │ │ │ │ - * for evaluating functions in the │ │ │ │ │ - * context. │ │ │ │ │ - * property - {String} optional, name of the property for which the literal is │ │ │ │ │ - * being created for evaluating functions in the context. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} the parsed value. In the example of the value parameter above, the │ │ │ │ │ - * result would be "foo valueOfBar", assuming that the passed feature has an │ │ │ │ │ - * attribute named "bar" with the value "valueOfBar". │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style.createLiteral = function(value, context, feature, property) { │ │ │ │ │ - if (typeof value == "string" && value.indexOf("${") != -1) { │ │ │ │ │ - value = OpenLayers.String.format(value, context, [feature, property]); │ │ │ │ │ - value = (isNaN(value) || !value) ? value : parseFloat(value); │ │ │ │ │ - } │ │ │ │ │ - return value; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES │ │ │ │ │ - * {Array} prefixes of the sld symbolizers. These are the │ │ │ │ │ - * same as the main geometry types │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon', 'Text', │ │ │ │ │ - 'Raster' │ │ │ │ │ -]; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Rule.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Rule │ │ │ │ │ - * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} name of this rule │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: title │ │ │ │ │ - * {String} Title of this rule (set if included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - title: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - description: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: context │ │ │ │ │ - * {Object} An optional object with properties that the rule should be │ │ │ │ │ - * evaluated against. If no context is specified, feature.attributes will │ │ │ │ │ - * be used. │ │ │ │ │ - */ │ │ │ │ │ - context: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} Optional filter for the rule. │ │ │ │ │ - */ │ │ │ │ │ - filter: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: elseFilter │ │ │ │ │ - * {Boolean} Determines whether this rule is only to be applied only if │ │ │ │ │ - * no other rules match (ElseFilter according to the SLD specification). │ │ │ │ │ - * Default is false. For instances of OpenLayers.Rule, if elseFilter is │ │ │ │ │ - * false, the rule will always apply. For subclasses, the else property is │ │ │ │ │ - * ignored. │ │ │ │ │ - */ │ │ │ │ │ - elseFilter: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: symbolizer │ │ │ │ │ - * {Object} Symbolizer or hash of symbolizers for this rule. If hash of │ │ │ │ │ - * symbolizers, keys are one or more of ["Point", "Line", "Polygon"]. The │ │ │ │ │ - * latter if useful if it is required to style e.g. vertices of a line │ │ │ │ │ - * with a point symbolizer. Note, however, that this is not implemented │ │ │ │ │ - * yet in OpenLayers, but it is the way how symbolizers are defined in │ │ │ │ │ - * SLD. │ │ │ │ │ - */ │ │ │ │ │ - symbolizer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: symbolizers │ │ │ │ │ - * {Array} Collection of symbolizers associated with this rule. If │ │ │ │ │ - * provided at construction, the symbolizers array has precedence │ │ │ │ │ - * over the deprecated symbolizer property. Note that multiple │ │ │ │ │ - * symbolizers are not currently supported by the vector renderers. │ │ │ │ │ - * Rules with multiple symbolizers are currently only useful for │ │ │ │ │ - * maintaining elements in an SLD document. │ │ │ │ │ - */ │ │ │ │ │ - symbolizers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minScaleDenominator │ │ │ │ │ - * {Number} or {String} minimum scale at which to draw the feature. │ │ │ │ │ - * In the case of a String, this can be a combination of text and │ │ │ │ │ - * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ - */ │ │ │ │ │ - minScaleDenominator: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxScaleDenominator │ │ │ │ │ - * {Number} or {String} maximum scale at which to draw the feature. │ │ │ │ │ - * In the case of a String, this can be a combination of text and │ │ │ │ │ - * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ - */ │ │ │ │ │ - maxScaleDenominator: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Rule │ │ │ │ │ - * Creates a Rule. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.symbolizer = {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - delete this.symbolizer; │ │ │ │ │ - } │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i in this.symbolizer) { │ │ │ │ │ - this.symbolizer[i] = null; │ │ │ │ │ - } │ │ │ │ │ - this.symbolizer = null; │ │ │ │ │ - delete this.symbolizers; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * evaluates this rule for a specific feature │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} feature to apply the rule to. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the rule applies, false if it does not. │ │ │ │ │ - * This rule is the default rule and always returns true. │ │ │ │ │ - */ │ │ │ │ │ - evaluate: function(feature) { │ │ │ │ │ - var context = this.getContext(feature); │ │ │ │ │ - var applies = true; │ │ │ │ │ - │ │ │ │ │ - if (this.minScaleDenominator || this.maxScaleDenominator) { │ │ │ │ │ - var scale = feature.layer.map.getScale(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // check if within minScale/maxScale bounds │ │ │ │ │ - if (this.minScaleDenominator) { │ │ │ │ │ - applies = scale >= OpenLayers.Style.createLiteral( │ │ │ │ │ - this.minScaleDenominator, context); │ │ │ │ │ - } │ │ │ │ │ - if (applies && this.maxScaleDenominator) { │ │ │ │ │ - applies = scale < OpenLayers.Style.createLiteral( │ │ │ │ │ - this.maxScaleDenominator, context); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // check if optional filter applies │ │ │ │ │ - if (applies && this.filter) { │ │ │ │ │ - // feature id filters get the feature, others get the context │ │ │ │ │ - if (this.filter.CLASS_NAME == "OpenLayers.Filter.FeatureId") { │ │ │ │ │ - applies = this.filter.evaluate(feature); │ │ │ │ │ - } else { │ │ │ │ │ - applies = this.filter.evaluate(context); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return applies; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getContext │ │ │ │ │ - * Gets the context for evaluating this rule │ │ │ │ │ - * │ │ │ │ │ - * Paramters: │ │ │ │ │ - * feature - {} feature to take the context from if │ │ │ │ │ - * none is specified. │ │ │ │ │ - */ │ │ │ │ │ - getContext: function(feature) { │ │ │ │ │ - var context = this.context; │ │ │ │ │ - if (!context) { │ │ │ │ │ - context = feature.attributes || feature.data; │ │ │ │ │ - } │ │ │ │ │ - if (typeof this.context == "function") { │ │ │ │ │ - context = this.context(feature); │ │ │ │ │ - } │ │ │ │ │ - return context; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this rule. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this rule. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - // clone symbolizers │ │ │ │ │ - var len = this.symbolizers.length; │ │ │ │ │ - options.symbolizers = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - options.symbolizers[i] = this.symbolizers[i].clone(); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // clone symbolizer │ │ │ │ │ - options.symbolizer = {}; │ │ │ │ │ - var value, type; │ │ │ │ │ - for (var key in this.symbolizer) { │ │ │ │ │ - value = this.symbolizer[key]; │ │ │ │ │ - type = typeof value; │ │ │ │ │ - if (type === "object") { │ │ │ │ │ - options.symbolizer[key] = OpenLayers.Util.extend({}, value); │ │ │ │ │ - } else if (type === "string") { │ │ │ │ │ - options.symbolizer[key] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // clone filter │ │ │ │ │ - options.filter = this.filter && this.filter.clone(); │ │ │ │ │ - // clone context │ │ │ │ │ - options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ - return new OpenLayers.Rule(options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Filter.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Filter │ │ │ │ │ - * This class represents an OGC Filter. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Filter = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Filter │ │ │ │ │ - * This class represents a generic filter. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Remove reference to anything added. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * Evaluates this filter in a specific context. Instances or subclasses │ │ │ │ │ - * are supposed to override this method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * context - {Object} Context to use in evaluating the filter. If a vector │ │ │ │ │ - * feature is provided, the feature.attributes will be used as context. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The filter applies. │ │ │ │ │ - */ │ │ │ │ │ - evaluate: function(context) { │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this filter. Should be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: toString │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Include in your build to get a CQL │ │ │ │ │ - * representation of the filter returned. Otherwise "[Object object]" │ │ │ │ │ - * will be returned. │ │ │ │ │ - */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - var string; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.CQL) { │ │ │ │ │ - string = OpenLayers.Format.CQL.prototype.write(this); │ │ │ │ │ - } else { │ │ │ │ │ - string = Object.prototype.toString.call(this); │ │ │ │ │ - } │ │ │ │ │ - return string; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler │ │ │ │ │ - * Base class to construct a higher-level handler for event sequences. All │ │ │ │ │ - * handlers have activate and deactivate methods. In addition, they have │ │ │ │ │ - * methods named like browser events. When a handler is activated, any │ │ │ │ │ - * additional methods named like a browser event is registered as a │ │ │ │ │ - * listener for the corresponding event. When a handler is deactivated, │ │ │ │ │ - * those same methods are unregistered as event listeners. │ │ │ │ │ - * │ │ │ │ │ - * Handlers also typically have a callbacks object with keys named like │ │ │ │ │ - * the abstracted events or event sequences that they are in charge of │ │ │ │ │ - * handling. The controls that wrap handlers define the methods that │ │ │ │ │ - * correspond to these abstract events - so instead of listening for │ │ │ │ │ - * individual browser events, they only listen for the abstract events │ │ │ │ │ - * defined by the handler. │ │ │ │ │ - * │ │ │ │ │ - * Handlers are created by controls, which ultimately have the responsibility │ │ │ │ │ - * of making changes to the the state of the application. Handlers │ │ │ │ │ - * themselves may make temporary changes, but in general are expected to │ │ │ │ │ - * return the application in the same state that they found it. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: control │ │ │ │ │ - * {}. The control that initialized this handler. The │ │ │ │ │ - * control is assumed to have a valid map property - that map is used │ │ │ │ │ - * in the handler's own setMap method. │ │ │ │ │ - */ │ │ │ │ │ - control: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: keyMask │ │ │ │ │ - * {Integer} Use bitwise operators and one or more of the OpenLayers.Handler │ │ │ │ │ - * constants to construct a keyMask. The keyMask is used by │ │ │ │ │ - * . If the keyMask matches the combination of keys │ │ │ │ │ - * down on an event, checkModifiers returns true. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * // handler only responds if the Shift key is down │ │ │ │ │ - * handler.keyMask = OpenLayers.Handler.MOD_SHIFT; │ │ │ │ │ - * │ │ │ │ │ - * // handler only responds if Ctrl-Shift is down │ │ │ │ │ - * handler.keyMask = OpenLayers.Handler.MOD_SHIFT | │ │ │ │ │ - * OpenLayers.Handler.MOD_CTRL; │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ - keyMask: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: active │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - active: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: evt │ │ │ │ │ - * {Event} This property references the last event handled by the handler. │ │ │ │ │ - * Note that this property is not part of the stable API. Use of the │ │ │ │ │ - * evt property should be restricted to controls in the library │ │ │ │ │ - * or other applications that are willing to update with changes to │ │ │ │ │ - * the OpenLayers code. │ │ │ │ │ - */ │ │ │ │ │ - evt: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: touch │ │ │ │ │ - * {Boolean} Indicates the support of touch events. When touch events are │ │ │ │ │ - * started touch will be true and all mouse related listeners will do │ │ │ │ │ - * nothing. │ │ │ │ │ - */ │ │ │ │ │ - touch: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler │ │ │ │ │ - * Construct a handler. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that initialized this │ │ │ │ │ - * handler. The control is assumed to have a valid map property; that │ │ │ │ │ - * map is used in the handler's own setMap method. If a map property │ │ │ │ │ - * is present in the options argument it will be used instead. │ │ │ │ │ - * callbacks - {Object} An object whose properties correspond to abstracted │ │ │ │ │ - * events or sequences of browser events. The values for these │ │ │ │ │ - * properties are functions defined by the control that get called by │ │ │ │ │ - * the handler. │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the handler. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.control = control; │ │ │ │ │ - this.callbacks = callbacks; │ │ │ │ │ - │ │ │ │ │ - var map = this.map || control.map; │ │ │ │ │ - if (map) { │ │ │ │ │ - this.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: checkModifiers │ │ │ │ │ - * Check the keyMask on the handler. If no is set, this always │ │ │ │ │ - * returns true. If a is set and it matches the combination │ │ │ │ │ - * of keys down on an event, this returns true. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The keyMask matches the keys down on an event. │ │ │ │ │ - */ │ │ │ │ │ - checkModifiers: function(evt) { │ │ │ │ │ - if (this.keyMask == null) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - /* calculate the keyboard modifier mask for this event */ │ │ │ │ │ - var keyModifiers = │ │ │ │ │ - (evt.shiftKey ? OpenLayers.Handler.MOD_SHIFT : 0) | │ │ │ │ │ - (evt.ctrlKey ? OpenLayers.Handler.MOD_CTRL : 0) | │ │ │ │ │ - (evt.altKey ? OpenLayers.Handler.MOD_ALT : 0) | │ │ │ │ │ - (evt.metaKey ? OpenLayers.Handler.MOD_META : 0); │ │ │ │ │ - │ │ │ │ │ - /* if it differs from the handler object's key mask, │ │ │ │ │ - bail out of the event handler */ │ │ │ │ │ - return (keyModifiers == this.keyMask); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - // register for event handlers defined on this class. │ │ │ │ │ - var events = OpenLayers.Events.prototype.BROWSER_EVENTS; │ │ │ │ │ - for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ - if (this[events[i]]) { │ │ │ │ │ - this.register(events[i], this[events[i]]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.active = true; │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Turn off the handler. Returns false if the handler was already inactive. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - // unregister event handlers defined on this class. │ │ │ │ │ - var events = OpenLayers.Events.prototype.BROWSER_EVENTS; │ │ │ │ │ - for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ - if (this[events[i]]) { │ │ │ │ │ - this.unregister(events[i], this[events[i]]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.touch = false; │ │ │ │ │ - this.active = false; │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: startTouch │ │ │ │ │ - * Start touch events, this method must be called by subclasses in │ │ │ │ │ - * "touchstart" method. When touch events are started will be │ │ │ │ │ - * true and all mouse related listeners will do nothing. │ │ │ │ │ - */ │ │ │ │ │ - startTouch: function() { │ │ │ │ │ - if (!this.touch) { │ │ │ │ │ - this.touch = true; │ │ │ │ │ - var events = [ │ │ │ │ │ - "mousedown", "mouseup", "mousemove", "click", "dblclick", │ │ │ │ │ - "mouseout" │ │ │ │ │ - ]; │ │ │ │ │ - for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ - if (this[events[i]]) { │ │ │ │ │ - this.unregister(events[i], this[events[i]]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: callback │ │ │ │ │ - * Trigger the control's named callback with the given arguments │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The key for the callback that is one of the properties │ │ │ │ │ - * of the handler's callbacks object. │ │ │ │ │ - * args - {Array(*)} An array of arguments (any type) with which to call │ │ │ │ │ - * the callback (defined by the control). │ │ │ │ │ - */ │ │ │ │ │ - callback: function(name, args) { │ │ │ │ │ - if (name && this.callbacks[name]) { │ │ │ │ │ - this.callbacks[name].apply(this.control, args); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: register │ │ │ │ │ - * register an event on the map │ │ │ │ │ - */ │ │ │ │ │ - register: function(name, method) { │ │ │ │ │ - // TODO: deal with registerPriority in 3.0 │ │ │ │ │ - this.map.events.registerPriority(name, this, method); │ │ │ │ │ - this.map.events.registerPriority(name, this, this.setEvent); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unregister │ │ │ │ │ - * unregister an event from the map │ │ │ │ │ - */ │ │ │ │ │ - unregister: function(name, method) { │ │ │ │ │ - this.map.events.unregister(name, this, method); │ │ │ │ │ - this.map.events.unregister(name, this, this.setEvent); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setEvent │ │ │ │ │ - * With each registered browser event, the handler sets its own evt │ │ │ │ │ - * property. This property can be accessed by controls if needed │ │ │ │ │ - * to get more information about the event that the handler is │ │ │ │ │ - * processing. │ │ │ │ │ - * │ │ │ │ │ - * This allows modifier keys on the event to be checked (alt, shift, ctrl, │ │ │ │ │ - * and meta cannot be checked with the keyboard handler). For a │ │ │ │ │ - * control to determine which modifier keys are associated with the │ │ │ │ │ - * event that a handler is currently processing, it should access │ │ │ │ │ - * (code)handler.evt.altKey || handler.evt.shiftKey || │ │ │ │ │ - * handler.evt.ctrlKey || handler.evt.metaKey(end). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event. │ │ │ │ │ - */ │ │ │ │ │ - setEvent: function(evt) { │ │ │ │ │ - this.evt = evt; │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Deconstruct the handler. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // unregister event listeners │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - // eliminate circular references │ │ │ │ │ - this.control = this.map = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_NONE │ │ │ │ │ - * If set as the , returns false if any key is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_NONE = 0; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_SHIFT │ │ │ │ │ - * If set as the , returns false if Shift is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_SHIFT = 1; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_CTRL │ │ │ │ │ - * If set as the , returns false if Ctrl is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_CTRL = 2; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_ALT │ │ │ │ │ - * If set as the , returns false if Alt is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_ALT = 4; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_META │ │ │ │ │ - * If set as the , returns false if Cmd is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_META = 8; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/StyleMap.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.StyleMap │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.StyleMap = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: styles │ │ │ │ │ - * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ - * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ - */ │ │ │ │ │ - styles: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: extendDefault │ │ │ │ │ - * {Boolean} if true, every render intent will extend the symbolizers │ │ │ │ │ - * specified for the "default" intent at rendering time. Otherwise, every │ │ │ │ │ - * rendering intent will be treated as a completely independent style. │ │ │ │ │ - */ │ │ │ │ │ - extendDefault: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.StyleMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * style - {Object} Optional. Either a style hash, or a style object, or │ │ │ │ │ - * a hash of style objects (style hashes) keyed by rendering │ │ │ │ │ - * intent. If just one style hash or style object is passed, │ │ │ │ │ - * this will be used for all known render intents (default, │ │ │ │ │ - * select, temporary) │ │ │ │ │ - * options - {Object} optional hash of additional options for this │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(style, options) { │ │ │ │ │ - this.styles = { │ │ │ │ │ - "default": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["default"]), │ │ │ │ │ - "select": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["select"]), │ │ │ │ │ - "temporary": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["temporary"]), │ │ │ │ │ - "delete": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["delete"]) │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // take whatever the user passed as style parameter and convert it │ │ │ │ │ - // into parts of stylemap. │ │ │ │ │ - if (style instanceof OpenLayers.Style) { │ │ │ │ │ - // user passed a style object │ │ │ │ │ - this.styles["default"] = style; │ │ │ │ │ - this.styles["select"] = style; │ │ │ │ │ - this.styles["temporary"] = style; │ │ │ │ │ - this.styles["delete"] = style; │ │ │ │ │ - } else if (typeof style == "object") { │ │ │ │ │ - for (var key in style) { │ │ │ │ │ - if (style[key] instanceof OpenLayers.Style) { │ │ │ │ │ - // user passed a hash of style objects │ │ │ │ │ - this.styles[key] = style[key]; │ │ │ │ │ - } else if (typeof style[key] == "object") { │ │ │ │ │ - // user passsed a hash of style hashes │ │ │ │ │ - this.styles[key] = new OpenLayers.Style(style[key]); │ │ │ │ │ - } else { │ │ │ │ │ - // user passed a style hash (i.e. symbolizer) │ │ │ │ │ - this.styles["default"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["select"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["temporary"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["delete"] = new OpenLayers.Style(style); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var key in this.styles) { │ │ │ │ │ - this.styles[key].destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.styles = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createSymbolizer │ │ │ │ │ - * Creates the symbolizer for a feature for a render intent. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature to evaluate the rules │ │ │ │ │ - * of the intended style against. │ │ │ │ │ - * intent - {String} The intent determines the symbolizer that will be │ │ │ │ │ - * used to draw the feature. Well known intents are "default" │ │ │ │ │ - * (for just drawing the features), "select" (for selected │ │ │ │ │ - * features) and "temporary" (for drawing features). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} symbolizer hash │ │ │ │ │ - */ │ │ │ │ │ - createSymbolizer: function(feature, intent) { │ │ │ │ │ - if (!feature) { │ │ │ │ │ - feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - } │ │ │ │ │ - if (!this.styles[intent]) { │ │ │ │ │ - intent = "default"; │ │ │ │ │ - } │ │ │ │ │ - feature.renderIntent = intent; │ │ │ │ │ - var defaultSymbolizer = {}; │ │ │ │ │ - if (this.extendDefault && intent != "default") { │ │ │ │ │ - defaultSymbolizer = this.styles["default"].createSymbolizer(feature); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Util.extend(defaultSymbolizer, │ │ │ │ │ - this.styles[intent].createSymbolizer(feature)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addUniqueValueRules │ │ │ │ │ - * Convenience method to create comparison rules for unique values of a │ │ │ │ │ - * property. The rules will be added to the style object for a specified │ │ │ │ │ - * rendering intent. This method is a shortcut for creating something like │ │ │ │ │ - * the "unique value legends" familiar from well known desktop GIS systems │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * renderIntent - {String} rendering intent to add the rules to │ │ │ │ │ - * property - {String} values of feature attributes to create the │ │ │ │ │ - * rules for │ │ │ │ │ - * symbolizers - {Object} Hash of symbolizers, keyed by the desired │ │ │ │ │ - * property values │ │ │ │ │ - * context - {Object} An optional object with properties that │ │ │ │ │ - * symbolizers' property values should be evaluated │ │ │ │ │ - * against. If no context is specified, feature.attributes │ │ │ │ │ - * will be used │ │ │ │ │ - */ │ │ │ │ │ - addUniqueValueRules: function(renderIntent, property, symbolizers, context) { │ │ │ │ │ - var rules = []; │ │ │ │ │ - for (var value in symbolizers) { │ │ │ │ │ - rules.push(new OpenLayers.Rule({ │ │ │ │ │ - symbolizer: symbolizers[value], │ │ │ │ │ - context: context, │ │ │ │ │ - filter: new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.EQUAL_TO, │ │ │ │ │ - property: property, │ │ │ │ │ - value: value │ │ │ │ │ - }) │ │ │ │ │ - })); │ │ │ │ │ - } │ │ │ │ │ - this.styles[renderIntent].addRules(rules); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Point.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Point │ │ │ │ │ - * Point geometry class. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: x │ │ │ │ │ - * {float} │ │ │ │ │ - */ │ │ │ │ │ - x: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: y │ │ │ │ │ - * {float} │ │ │ │ │ - */ │ │ │ │ │ - y: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ - * Construct a point geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {float} │ │ │ │ │ - * y - {float} │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.x = parseFloat(x); │ │ │ │ │ - this.y = parseFloat(y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ - */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ - * Create a new Bounds based on the lon/lat │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ - this.x, this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var distance, x0, y0, x1, y1, result; │ │ │ │ │ - if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - x0 = this.x; │ │ │ │ │ - y0 = this.y; │ │ │ │ │ - x1 = geometry.x; │ │ │ │ │ - y1 = geometry.y; │ │ │ │ │ - distance = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); │ │ │ │ │ - result = !details ? │ │ │ │ │ - distance : { │ │ │ │ │ - x0: x0, │ │ │ │ │ - y0: y0, │ │ │ │ │ - x1: x1, │ │ │ │ │ - y1: y1, │ │ │ │ │ - distance: distance │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - result = geometry.distanceTo(this, options); │ │ │ │ │ - if (details) { │ │ │ │ │ - // switch coord order since this geom is target │ │ │ │ │ - result = { │ │ │ │ │ - x0: result.x1, │ │ │ │ │ - y0: result.y1, │ │ │ │ │ - x1: result.x0, │ │ │ │ │ - y1: result.y0, │ │ │ │ │ - distance: result.distance │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geom - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ - */ │ │ │ │ │ - equals: function(geom) { │ │ │ │ │ - var equals = false; │ │ │ │ │ - if (geom != null) { │ │ │ │ │ - equals = ((this.x == geom.x && this.y == geom.y) || │ │ │ │ │ - (isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y))); │ │ │ │ │ - } │ │ │ │ │ - return equals; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toShortString │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Shortened String representation of Point object. │ │ │ │ │ - * (ex. "5, 42") │ │ │ │ │ - */ │ │ │ │ │ - toShortString: function() { │ │ │ │ │ - return (this.x + ", " + this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: move │ │ │ │ │ - * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ - * This modifies the position of the geometry and clears the cached │ │ │ │ │ - * bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ - * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ - */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - this.x = this.x + x; │ │ │ │ │ - this.y = this.y + y; │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: rotate │ │ │ │ │ - * Rotate a point around another. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ - * from the positive x-axis) │ │ │ │ │ - * origin - {} Center point for the rotation │ │ │ │ │ - */ │ │ │ │ │ - rotate: function(angle, origin) { │ │ │ │ │ - angle *= Math.PI / 180; │ │ │ │ │ - var radius = this.distanceTo(origin); │ │ │ │ │ - var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x); │ │ │ │ │ - this.x = origin.x + (radius * Math.cos(theta)); │ │ │ │ │ - this.y = origin.y + (radius * Math.sin(theta)); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: resize │ │ │ │ │ - * Resize a point relative to some origin. For points, this has the effect │ │ │ │ │ - * of scaling a vector (from the origin to the point). This method is │ │ │ │ │ - * more useful on geometry collection subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {Float} Ratio of the new distance from the origin to the old │ │ │ │ │ - * distance from the origin. A scale of 2 doubles the │ │ │ │ │ - * distance between the point and origin. │ │ │ │ │ - * origin - {} Point of origin for resizing │ │ │ │ │ - * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ - */ │ │ │ │ │ - resize: function(scale, origin, ratio) { │ │ │ │ │ - ratio = (ratio == undefined) ? 1 : ratio; │ │ │ │ │ - this.x = origin.x + (scale * ratio * (this.x - origin.x)); │ │ │ │ │ - this.y = origin.y + (scale * (this.y - origin.y)); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - intersect = this.equals(geometry); │ │ │ │ │ - } else { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Translate the x,y properties of the point from source to dest. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - transform: function(source, dest) { │ │ │ │ │ - if ((source && dest)) { │ │ │ │ │ - OpenLayers.Projection.transform( │ │ │ │ │ - this, source, dest); │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - return [this]; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Collection.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Collection │ │ │ │ │ - * A Collection is exactly what it sounds like: A collection of different │ │ │ │ │ - * Geometries. These are stored in the local parameter (which │ │ │ │ │ - * can be passed as a parameter to the constructor). │ │ │ │ │ - * │ │ │ │ │ - * As new geometries are added to the collection, they are NOT cloned. │ │ │ │ │ - * When removing geometries, they need to be specified by reference (ie you │ │ │ │ │ - * have to pass in the *exact* geometry to be removed). │ │ │ │ │ - * │ │ │ │ │ - * The and functions here merely iterate through │ │ │ │ │ - * the components, summing their respective areas and lengths. │ │ │ │ │ - * │ │ │ │ │ - * Create a new instance with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: components │ │ │ │ │ - * {Array()} The component parts of this geometry │ │ │ │ │ - */ │ │ │ │ │ - components: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null value means the │ │ │ │ │ - * component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ - * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} Optional array of geometries │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(components) { │ │ │ │ │ - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.components = []; │ │ │ │ │ - if (components != null) { │ │ │ │ │ - this.addComponents(components); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.components.length = 0; │ │ │ │ │ - this.components = null; │ │ │ │ │ - OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clone this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this collection │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var geometry = eval("new " + this.CLASS_NAME + "()"); │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - geometry.addComponent(this.components[i].clone()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ - │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getComponentsString │ │ │ │ │ - * Get a string representing the components for this collection │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representation of the components of this geometry │ │ │ │ │ - */ │ │ │ │ │ - getComponentsString: function() { │ │ │ │ │ - var strings = []; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - strings.push(this.components[i].toShortString()); │ │ │ │ │ - } │ │ │ │ │ - return strings.join(","); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds by iterating through the components and │ │ │ │ │ - * calling calling extendBounds() on each item. │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - var bounds = new OpenLayers.Bounds(); │ │ │ │ │ - var components = this.components; │ │ │ │ │ - if (components) { │ │ │ │ │ - for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ - bounds.extend(components[i].getBounds()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // to preserve old behavior, we only set bounds if non-null │ │ │ │ │ - // in the future, we could add bounds.isEmpty() │ │ │ │ │ - if (bounds.left != null && bounds.bottom != null && │ │ │ │ │ - bounds.right != null && bounds.top != null) { │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addComponents │ │ │ │ │ - * Add components to this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} An array of geometries to add │ │ │ │ │ - */ │ │ │ │ │ - addComponents: function(components) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ - this.addComponent(components[i]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addComponent │ │ │ │ │ - * Add a new component (geometry) to the collection. If this.componentTypes │ │ │ │ │ - * is set, then the component class name must be in the componentTypes array. │ │ │ │ │ - * │ │ │ │ │ - * The bounds cache is reset. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * component - {} A geometry to add │ │ │ │ │ - * index - {int} Optional index into the array to insert the component │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component geometry was successfully added │ │ │ │ │ - */ │ │ │ │ │ - addComponent: function(component, index) { │ │ │ │ │ - var added = false; │ │ │ │ │ - if (component) { │ │ │ │ │ - if (this.componentTypes == null || │ │ │ │ │ - (OpenLayers.Util.indexOf(this.componentTypes, │ │ │ │ │ - component.CLASS_NAME) > -1)) { │ │ │ │ │ - │ │ │ │ │ - if (index != null && (index < this.components.length)) { │ │ │ │ │ - var components1 = this.components.slice(0, index); │ │ │ │ │ - var components2 = this.components.slice(index, │ │ │ │ │ - this.components.length); │ │ │ │ │ - components1.push(component); │ │ │ │ │ - this.components = components1.concat(components2); │ │ │ │ │ - } else { │ │ │ │ │ - this.components.push(component); │ │ │ │ │ - } │ │ │ │ │ - component.parent = this; │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - added = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return added; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeComponents │ │ │ │ │ - * Remove components from this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} The components to be removed │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponents: function(components) { │ │ │ │ │ - var removed = false; │ │ │ │ │ - │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ - } │ │ │ │ │ - for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ - removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ - } │ │ │ │ │ - return removed; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeComponent │ │ │ │ │ - * Remove a component from this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * component - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponent: function(component) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ - │ │ │ │ │ - // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ - // to this.getBounds(); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLength │ │ │ │ │ - * Calculate the length of this geometry │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the geometry │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i].getLength(); │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getArea │ │ │ │ │ - * Calculate the area of this geometry. Note how this function is overridden │ │ │ │ │ - * in . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The area of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - area += this.components[i].getArea(); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicArea │ │ │ │ │ - * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Reference: │ │ │ │ │ - * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for │ │ │ │ │ - * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion │ │ │ │ │ - * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {float} The approximate geodesic area of the geometry in square meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicArea: function(projection) { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - area += this.components[i].getGeodesicArea(projection); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Compute the centroid for this geometry collection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ - * returning an area weighted average of all geometries in this collection. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function(weighted) { │ │ │ │ │ - if (!weighted) { │ │ │ │ │ - return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ - } │ │ │ │ │ - var len = this.components.length; │ │ │ │ │ - if (!len) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var areas = []; │ │ │ │ │ - var centroids = []; │ │ │ │ │ - var areaSum = 0; │ │ │ │ │ - var minArea = Number.MAX_VALUE; │ │ │ │ │ - var component; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - component = this.components[i]; │ │ │ │ │ - var area = component.getArea(); │ │ │ │ │ - var centroid = component.getCentroid(true); │ │ │ │ │ - if (isNaN(area) || isNaN(centroid.x) || isNaN(centroid.y)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - areas.push(area); │ │ │ │ │ - areaSum += area; │ │ │ │ │ - minArea = (area < minArea && area > 0) ? area : minArea; │ │ │ │ │ - centroids.push(centroid); │ │ │ │ │ - } │ │ │ │ │ - len = areas.length; │ │ │ │ │ - if (areaSum === 0) { │ │ │ │ │ - // all the components in this collection have 0 area │ │ │ │ │ - // probably a collection of points -- weight all the points the same │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - areas[i] = 1; │ │ │ │ │ - } │ │ │ │ │ - areaSum = areas.length; │ │ │ │ │ - } else { │ │ │ │ │ - // normalize all the areas where the smallest area will get │ │ │ │ │ - // a value of 1 │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - areas[i] /= minArea; │ │ │ │ │ - } │ │ │ │ │ - areaSum /= minArea; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var xSum = 0, │ │ │ │ │ - ySum = 0, │ │ │ │ │ - centroid, area; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - centroid = centroids[i]; │ │ │ │ │ - area = areas[i]; │ │ │ │ │ - xSum += centroid.x * area; │ │ │ │ │ - ySum += centroid.y * area; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicLength: function(projection) { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i].getGeodesicLength(projection); │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: move │ │ │ │ │ - * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ - * This modifies the position of the geometry and clears the cached │ │ │ │ │ - * bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ - * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ - */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - this.components[i].move(x, y); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: rotate │ │ │ │ │ - * Rotate a geometry around some origin │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ - * from the positive x-axis) │ │ │ │ │ - * origin - {} Center point for the rotation │ │ │ │ │ - */ │ │ │ │ │ - rotate: function(angle, origin) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - this.components[i].rotate(angle, origin); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: resize │ │ │ │ │ - * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ - * a uniform scaling to a geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {Float} Factor by which to scale the geometry. A scale of 2 │ │ │ │ │ - * doubles the size of the geometry in each dimension │ │ │ │ │ - * (lines, for example, will be twice as long, and polygons │ │ │ │ │ - * will have four times the area). │ │ │ │ │ - * origin - {} Point of origin for resizing │ │ │ │ │ - * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ - */ │ │ │ │ │ - resize: function(scale, origin, ratio) { │ │ │ │ │ - for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ - this.components[i].resize(scale, origin, ratio); │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and y1 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var result, best, distance; │ │ │ │ │ - var min = Number.POSITIVE_INFINITY; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - result = this.components[i].distanceTo(geometry, options); │ │ │ │ │ - distance = details ? result.distance : result; │ │ │ │ │ - if (distance < min) { │ │ │ │ │ - min = distance; │ │ │ │ │ - best = result; │ │ │ │ │ - if (min == 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return best; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ - */ │ │ │ │ │ - equals: function(geometry) { │ │ │ │ │ - var equivalent = true; │ │ │ │ │ - if (!geometry || !geometry.CLASS_NAME || │ │ │ │ │ - (this.CLASS_NAME != geometry.CLASS_NAME)) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - } else if (!(OpenLayers.Util.isArray(geometry.components)) || │ │ │ │ │ - (geometry.components.length != this.components.length)) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - if (!this.components[i].equals(geometry.components[i])) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return equivalent; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Reproject the components geometry from source to dest. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - transform: function(source, dest) { │ │ │ │ │ - if (source && dest) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - var component = this.components[i]; │ │ │ │ │ - component.transform(source, dest); │ │ │ │ │ - } │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - intersect = geometry.intersects(this.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - var vertices = []; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - Array.prototype.push.apply( │ │ │ │ │ - vertices, this.components[i].getVertices(nodes) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return vertices; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * MultiPoint is a collection of Points. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.MultiPoint = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.Collection, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null value means the │ │ │ │ │ - * component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * Create a new MultiPoint Geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addPoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be added │ │ │ │ │ - * index - {Integer} Optional index │ │ │ │ │ - */ │ │ │ │ │ - addPoint: function(point, index) { │ │ │ │ │ - this.addComponent(point, index); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removePoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be removed │ │ │ │ │ - */ │ │ │ │ │ - removePoint: function(point) { │ │ │ │ │ - this.removeComponent(point); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Curve.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Curve │ │ │ │ │ - * A Curve is a MultiPoint, whose points are assumed to be connected. To │ │ │ │ │ - * this end, we provide a "getLength()" function, which iterates through │ │ │ │ │ - * the points, summing the distances between them. │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null │ │ │ │ │ - * value means the component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Array()} │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLength │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the curve │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - if (this.components && (this.components.length > 1)) { │ │ │ │ │ - for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i - 1].distanceTo(this.components[i]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicLength: function(projection) { │ │ │ │ │ - var geom = this; // so we can work with a clone if needed │ │ │ │ │ - if (projection) { │ │ │ │ │ - var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - if (!gg.equals(projection)) { │ │ │ │ │ - geom = this.clone().transform(projection, gg); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - if (geom.components && (geom.components.length > 1)) { │ │ │ │ │ - var p1, p2; │ │ │ │ │ - for (var i = 1, len = geom.components.length; i < len; i++) { │ │ │ │ │ - p1 = geom.components[i - 1]; │ │ │ │ │ - p2 = geom.components[i]; │ │ │ │ │ - // this returns km and requires lon/lat properties │ │ │ │ │ - length += OpenLayers.Util.distVincenty({ │ │ │ │ │ - lon: p1.x, │ │ │ │ │ - lat: p1.y │ │ │ │ │ - }, { │ │ │ │ │ - lon: p2.x, │ │ │ │ │ - lat: p2.y │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // convert to m │ │ │ │ │ - return length * 1000; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/LineString.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.LineString │ │ │ │ │ - * A LineString is a Curve which, once two points have been added to it, can │ │ │ │ │ - * never be less than two points long. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ - * Create a new LineString geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * points - {Array()} An array of points used to │ │ │ │ │ - * generate the linestring │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeComponent │ │ │ │ │ - * Only allows removal of a point if there are three or more points in │ │ │ │ │ - * the linestring. (otherwise the result would be just a single point) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} The point to be removed │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponent: function(point) { │ │ │ │ │ - var removed = this.components && (this.components.length > 2); │ │ │ │ │ - if (removed) { │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - } │ │ │ │ │ - return removed; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Test for instersection between two geometries. This is a cheapo │ │ │ │ │ - * implementation of the Bently-Ottmann algorigithm. It doesn't │ │ │ │ │ - * really keep track of a sweep line data structure. It is closer │ │ │ │ │ - * to the brute force method, except that segments are sorted and │ │ │ │ │ - * potential intersections are only calculated when bounding boxes │ │ │ │ │ - * intersect. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this geometry. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - var type = geometry.CLASS_NAME; │ │ │ │ │ - if (type == "OpenLayers.Geometry.LineString" || │ │ │ │ │ - type == "OpenLayers.Geometry.LinearRing" || │ │ │ │ │ - type == "OpenLayers.Geometry.Point") { │ │ │ │ │ - var segs1 = this.getSortedSegments(); │ │ │ │ │ - var segs2; │ │ │ │ │ - if (type == "OpenLayers.Geometry.Point") { │ │ │ │ │ - segs2 = [{ │ │ │ │ │ - x1: geometry.x, │ │ │ │ │ - y1: geometry.y, │ │ │ │ │ - x2: geometry.x, │ │ │ │ │ - y2: geometry.y │ │ │ │ │ - }]; │ │ │ │ │ - } else { │ │ │ │ │ - segs2 = geometry.getSortedSegments(); │ │ │ │ │ - } │ │ │ │ │ - var seg1, seg1x1, seg1x2, seg1y1, seg1y2, │ │ │ │ │ - seg2, seg2y1, seg2y2; │ │ │ │ │ - // sweep right │ │ │ │ │ - outer: for (var i = 0, len = segs1.length; i < len; ++i) { │ │ │ │ │ - seg1 = segs1[i]; │ │ │ │ │ - seg1x1 = seg1.x1; │ │ │ │ │ - seg1x2 = seg1.x2; │ │ │ │ │ - seg1y1 = seg1.y1; │ │ │ │ │ - seg1y2 = seg1.y2; │ │ │ │ │ - inner: for (var j = 0, jlen = segs2.length; j < jlen; ++j) { │ │ │ │ │ - seg2 = segs2[j]; │ │ │ │ │ - if (seg2.x1 > seg1x2) { │ │ │ │ │ - // seg1 still left of seg2 │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - if (seg2.x2 < seg1x1) { │ │ │ │ │ - // seg2 still left of seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - seg2y1 = seg2.y1; │ │ │ │ │ - seg2y2 = seg2.y2; │ │ │ │ │ - if (Math.min(seg2y1, seg2y2) > Math.max(seg1y1, seg1y2)) { │ │ │ │ │ - // seg2 above seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (Math.max(seg2y1, seg2y2) < Math.min(seg1y1, seg1y2)) { │ │ │ │ │ - // seg2 below seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Geometry.segmentsIntersect(seg1, seg2)) { │ │ │ │ │ - intersect = true; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSortedSegments │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of segment objects. Segment objects have properties │ │ │ │ │ - * x1, y1, x2, and y2. The start point is represented by x1 and y1. │ │ │ │ │ - * The end point is represented by x2 and y2. Start and end are │ │ │ │ │ - * ordered so that x1 < x2. │ │ │ │ │ - */ │ │ │ │ │ - getSortedSegments: function() { │ │ │ │ │ - var numSeg = this.components.length - 1; │ │ │ │ │ - var segments = new Array(numSeg), │ │ │ │ │ - point1, point2; │ │ │ │ │ - for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ - point1 = this.components[i]; │ │ │ │ │ - point2 = this.components[i + 1]; │ │ │ │ │ - if (point1.x < point2.x) { │ │ │ │ │ - segments[i] = { │ │ │ │ │ - x1: point1.x, │ │ │ │ │ - y1: point1.y, │ │ │ │ │ - x2: point2.x, │ │ │ │ │ - y2: point2.y │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - segments[i] = { │ │ │ │ │ - x1: point2.x, │ │ │ │ │ - y1: point2.y, │ │ │ │ │ - x2: point1.x, │ │ │ │ │ - y2: point1.y │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // more efficient to define this somewhere static │ │ │ │ │ - function byX1(seg1, seg2) { │ │ │ │ │ - return seg1.x1 - seg2.x1; │ │ │ │ │ - } │ │ │ │ │ - return segments.sort(byX1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: splitWithSegment │ │ │ │ │ - * Split this geometry with the given segment. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * seg - {Object} An object with x1, y1, x2, and y2 properties referencing │ │ │ │ │ - * segment endpoint coordinates. │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source segment must be within the │ │ │ │ │ - * tolerance distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of one of the source segment's │ │ │ │ │ - * endpoints will be assumed to occur at the endpoint. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with *lines* and *points* properties. If the given │ │ │ │ │ - * segment intersects this linestring, the lines array will reference │ │ │ │ │ - * geometries that result from the split. The points array will contain │ │ │ │ │ - * all intersection points. Intersection points are sorted along the │ │ │ │ │ - * segment (in order from x1,y1 to x2,y2). │ │ │ │ │ - */ │ │ │ │ │ - splitWithSegment: function(seg, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var tolerance = options && options.tolerance; │ │ │ │ │ - var lines = []; │ │ │ │ │ - var verts = this.getVertices(); │ │ │ │ │ - var points = []; │ │ │ │ │ - var intersections = []; │ │ │ │ │ - var split = false; │ │ │ │ │ - var vert1, vert2, point; │ │ │ │ │ - var node, vertex, target; │ │ │ │ │ - var interOptions = { │ │ │ │ │ - point: true, │ │ │ │ │ - tolerance: tolerance │ │ │ │ │ - }; │ │ │ │ │ - var result = null; │ │ │ │ │ - for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ - vert1 = verts[i]; │ │ │ │ │ - points.push(vert1.clone()); │ │ │ │ │ - vert2 = verts[i + 1]; │ │ │ │ │ - target = { │ │ │ │ │ - x1: vert1.x, │ │ │ │ │ - y1: vert1.y, │ │ │ │ │ - x2: vert2.x, │ │ │ │ │ - y2: vert2.y │ │ │ │ │ - }; │ │ │ │ │ - point = OpenLayers.Geometry.segmentsIntersect( │ │ │ │ │ - seg, target, interOptions │ │ │ │ │ - ); │ │ │ │ │ - if (point instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - if ((point.x === seg.x1 && point.y === seg.y1) || │ │ │ │ │ - (point.x === seg.x2 && point.y === seg.y2) || │ │ │ │ │ - point.equals(vert1) || point.equals(vert2)) { │ │ │ │ │ - vertex = true; │ │ │ │ │ - } else { │ │ │ │ │ - vertex = false; │ │ │ │ │ - } │ │ │ │ │ - if (vertex || edge) { │ │ │ │ │ - // push intersections different than the previous │ │ │ │ │ - if (!point.equals(intersections[intersections.length - 1])) { │ │ │ │ │ - intersections.push(point.clone()); │ │ │ │ │ - } │ │ │ │ │ - if (i === 0) { │ │ │ │ │ - if (point.equals(vert1)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (point.equals(vert2)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - split = true; │ │ │ │ │ - if (!point.equals(vert1)) { │ │ │ │ │ - points.push(point); │ │ │ │ │ - } │ │ │ │ │ - lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - points = [point.clone()]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (split) { │ │ │ │ │ - points.push(vert2.clone()); │ │ │ │ │ - lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - } │ │ │ │ │ - if (intersections.length > 0) { │ │ │ │ │ - // sort intersections along segment │ │ │ │ │ - var xDir = seg.x1 < seg.x2 ? 1 : -1; │ │ │ │ │ - var yDir = seg.y1 < seg.y2 ? 1 : -1; │ │ │ │ │ - result = { │ │ │ │ │ - lines: lines, │ │ │ │ │ - points: intersections.sort(function(p1, p2) { │ │ │ │ │ - return (xDir * p1.x - xDir * p2.x) || (yDir * p1.y - yDir * p2.y); │ │ │ │ │ - }) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: split │ │ │ │ │ - * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {} The target geometry. │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ - * geometry. Default is false. │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ - * distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of an existing vertex on the source │ │ │ │ │ - * will be assumed to occur at the vertex. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ - * result from splitting the target with the source geometry. The │ │ │ │ │ - * source and target geometry will remain unmodified. If no split │ │ │ │ │ - * results, null will be returned. If mutual is true and a split │ │ │ │ │ - * results, return will be an array of two arrays - the first will be │ │ │ │ │ - * all geometries that result from splitting the source geometry and │ │ │ │ │ - * the second will be all geometries that result from splitting the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - split: function(target, options) { │ │ │ │ │ - var results = null; │ │ │ │ │ - var mutual = options && options.mutual; │ │ │ │ │ - var sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ - if (target instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ - var verts = this.getVertices(); │ │ │ │ │ - var vert1, vert2, seg, splits, lines, point; │ │ │ │ │ - var points = []; │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ - vert1 = verts[i]; │ │ │ │ │ - vert2 = verts[i + 1]; │ │ │ │ │ - seg = { │ │ │ │ │ - x1: vert1.x, │ │ │ │ │ - y1: vert1.y, │ │ │ │ │ - x2: vert2.x, │ │ │ │ │ - y2: vert2.y │ │ │ │ │ - }; │ │ │ │ │ - targetParts = targetParts || [target]; │ │ │ │ │ - if (mutual) { │ │ │ │ │ - points.push(vert1.clone()); │ │ │ │ │ - } │ │ │ │ │ - for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ - splits = targetParts[j].splitWithSegment(seg, options); │ │ │ │ │ - if (splits) { │ │ │ │ │ - // splice in new features │ │ │ │ │ - lines = splits.lines; │ │ │ │ │ - if (lines.length > 0) { │ │ │ │ │ - lines.unshift(j, 1); │ │ │ │ │ - Array.prototype.splice.apply(targetParts, lines); │ │ │ │ │ - j += lines.length - 2; │ │ │ │ │ - } │ │ │ │ │ - if (mutual) { │ │ │ │ │ - for (var k = 0, len = splits.points.length; k < len; ++k) { │ │ │ │ │ - point = splits.points[k]; │ │ │ │ │ - if (!point.equals(vert1)) { │ │ │ │ │ - points.push(point); │ │ │ │ │ - sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - if (point.equals(vert2)) { │ │ │ │ │ - points = []; │ │ │ │ │ - } else { │ │ │ │ │ - points = [point.clone()]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (mutual && sourceParts.length > 0 && points.length > 0) { │ │ │ │ │ - points.push(vert2.clone()); │ │ │ │ │ - sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - results = target.splitWith(this, options); │ │ │ │ │ - } │ │ │ │ │ - if (targetParts && targetParts.length > 1) { │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - targetParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (targetSplit || sourceSplit) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - results = [sourceParts, targetParts]; │ │ │ │ │ - } else { │ │ │ │ │ - results = targetParts; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return results; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: splitWith │ │ │ │ │ - * Split this geometry (the target) with the given geometry (the source). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A geometry used to split this │ │ │ │ │ - * geometry (the source). │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ - * geometry. Default is false. │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ - * distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of an existing vertex on the source │ │ │ │ │ - * will be assumed to occur at the vertex. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ - * result from splitting the target with the source geometry. The │ │ │ │ │ - * source and target geometry will remain unmodified. If no split │ │ │ │ │ - * results, null will be returned. If mutual is true and a split │ │ │ │ │ - * results, return will be an array of two arrays - the first will be │ │ │ │ │ - * all geometries that result from splitting the source geometry and │ │ │ │ │ - * the second will be all geometries that result from splitting the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - splitWith: function(geometry, options) { │ │ │ │ │ - return geometry.split(this, options); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - var vertices; │ │ │ │ │ - if (nodes === true) { │ │ │ │ │ - vertices = [ │ │ │ │ │ - this.components[0], │ │ │ │ │ - this.components[this.components.length - 1] │ │ │ │ │ - ]; │ │ │ │ │ - } else if (nodes === false) { │ │ │ │ │ - vertices = this.components.slice(1, this.components.length - 1); │ │ │ │ │ - } else { │ │ │ │ │ - vertices = this.components.slice(); │ │ │ │ │ - } │ │ │ │ │ - return vertices; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var result, best = {}; │ │ │ │ │ - var min = Number.POSITIVE_INFINITY; │ │ │ │ │ - if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - var segs = this.getSortedSegments(); │ │ │ │ │ - var x = geometry.x; │ │ │ │ │ - var y = geometry.y; │ │ │ │ │ - var seg; │ │ │ │ │ - for (var i = 0, len = segs.length; i < len; ++i) { │ │ │ │ │ - seg = segs[i]; │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment(geometry, seg); │ │ │ │ │ - if (result.distance < min) { │ │ │ │ │ - min = result.distance; │ │ │ │ │ - best = result; │ │ │ │ │ - if (min === 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // if distance increases and we cross y0 to the right of x0, no need to keep looking. │ │ │ │ │ - if (seg.x2 > x && ((y > seg.y1 && y < seg.y2) || (y < seg.y1 && y > seg.y2))) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: best.distance, │ │ │ │ │ - x0: best.x, │ │ │ │ │ - y0: best.y, │ │ │ │ │ - x1: x, │ │ │ │ │ - y1: y │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - best = best.distance; │ │ │ │ │ - } │ │ │ │ │ - } else if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ - var segs0 = this.getSortedSegments(); │ │ │ │ │ - var segs1 = geometry.getSortedSegments(); │ │ │ │ │ - var seg0, seg1, intersection, x0, y0; │ │ │ │ │ - var len1 = segs1.length; │ │ │ │ │ - var interOptions = { │ │ │ │ │ - point: true │ │ │ │ │ - }; │ │ │ │ │ - outer: for (var i = 0, len = segs0.length; i < len; ++i) { │ │ │ │ │ - seg0 = segs0[i]; │ │ │ │ │ - x0 = seg0.x1; │ │ │ │ │ - y0 = seg0.y1; │ │ │ │ │ - for (var j = 0; j < len1; ++j) { │ │ │ │ │ - seg1 = segs1[j]; │ │ │ │ │ - intersection = OpenLayers.Geometry.segmentsIntersect(seg0, seg1, interOptions); │ │ │ │ │ - if (intersection) { │ │ │ │ │ - min = 0; │ │ │ │ │ - best = { │ │ │ │ │ - distance: 0, │ │ │ │ │ - x0: intersection.x, │ │ │ │ │ - y0: intersection.y, │ │ │ │ │ - x1: intersection.x, │ │ │ │ │ - y1: intersection.y │ │ │ │ │ - }; │ │ │ │ │ - break outer; │ │ │ │ │ - } else { │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment({ │ │ │ │ │ - x: x0, │ │ │ │ │ - y: y0 │ │ │ │ │ - }, seg1); │ │ │ │ │ - if (result.distance < min) { │ │ │ │ │ - min = result.distance; │ │ │ │ │ - best = { │ │ │ │ │ - distance: min, │ │ │ │ │ - x0: x0, │ │ │ │ │ - y0: y0, │ │ │ │ │ - x1: result.x, │ │ │ │ │ - y1: result.y │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!details) { │ │ │ │ │ - best = best.distance; │ │ │ │ │ - } │ │ │ │ │ - if (min !== 0) { │ │ │ │ │ - // check the final vertex in this line's sorted segments │ │ │ │ │ - if (seg0) { │ │ │ │ │ - result = geometry.distanceTo( │ │ │ │ │ - new OpenLayers.Geometry.Point(seg0.x2, seg0.y2), │ │ │ │ │ - options │ │ │ │ │ - ); │ │ │ │ │ - var dist = details ? result.distance : result; │ │ │ │ │ - if (dist < min) { │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: min, │ │ │ │ │ - x0: result.x1, │ │ │ │ │ - y0: result.y1, │ │ │ │ │ - x1: result.x0, │ │ │ │ │ - y1: result.y0 │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - best = dist; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - best = geometry.distanceTo(this, options); │ │ │ │ │ - // swap since target comes from this line │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: best.distance, │ │ │ │ │ - x0: best.x1, │ │ │ │ │ - y0: best.y1, │ │ │ │ │ - x1: best.x0, │ │ │ │ │ - y1: best.y0 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return best; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: simplify │ │ │ │ │ - * This function will return a simplified LineString. │ │ │ │ │ - * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ - */ │ │ │ │ │ - simplify: function(tolerance) { │ │ │ │ │ - if (this && this !== null) { │ │ │ │ │ - var points = this.getVertices(); │ │ │ │ │ - if (points.length < 3) { │ │ │ │ │ - return this; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var compareNumbers = function(a, b) { │ │ │ │ │ - return (a - b); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Private function doing the Douglas-Peucker reduction │ │ │ │ │ - */ │ │ │ │ │ - var douglasPeuckerReduction = function(points, firstPoint, lastPoint, tolerance) { │ │ │ │ │ - var maxDistance = 0; │ │ │ │ │ - var indexFarthest = 0; │ │ │ │ │ - │ │ │ │ │ - for (var index = firstPoint, distance; index < lastPoint; index++) { │ │ │ │ │ - distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]); │ │ │ │ │ - if (distance > maxDistance) { │ │ │ │ │ - maxDistance = distance; │ │ │ │ │ - indexFarthest = index; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (maxDistance > tolerance && indexFarthest != firstPoint) { │ │ │ │ │ - //Add the largest point that exceeds the tolerance │ │ │ │ │ - pointIndexsToKeep.push(indexFarthest); │ │ │ │ │ - douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance); │ │ │ │ │ - douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Private function calculating the perpendicular distance │ │ │ │ │ - * TODO: check whether OpenLayers.Geometry.LineString::distanceTo() is faster or slower │ │ │ │ │ - */ │ │ │ │ │ - var perpendicularDistance = function(point1, point2, point) { │ │ │ │ │ - //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)| *Area of triangle │ │ │ │ │ - //Base = v((x1-x2)²+(x1-x2)²) *Base of Triangle* │ │ │ │ │ - //Area = .5*Base*H *Solve for height │ │ │ │ │ - //Height = Area/.5/Base │ │ │ │ │ - │ │ │ │ │ - var area = Math.abs(0.5 * (point1.x * point2.y + point2.x * point.y + point.x * point1.y - point2.x * point1.y - point.x * point2.y - point1.x * point.y)); │ │ │ │ │ - var bottom = Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)); │ │ │ │ │ - var height = area / bottom * 2; │ │ │ │ │ - │ │ │ │ │ - return height; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - var firstPoint = 0; │ │ │ │ │ - var lastPoint = points.length - 1; │ │ │ │ │ - var pointIndexsToKeep = []; │ │ │ │ │ - │ │ │ │ │ - //Add the first and last index to the keepers │ │ │ │ │ - pointIndexsToKeep.push(firstPoint); │ │ │ │ │ - pointIndexsToKeep.push(lastPoint); │ │ │ │ │ - │ │ │ │ │ - //The first and the last point cannot be the same │ │ │ │ │ - while (points[firstPoint].equals(points[lastPoint])) { │ │ │ │ │ - lastPoint--; │ │ │ │ │ - //Addition: the first point not equal to first point in the LineString is kept as well │ │ │ │ │ - pointIndexsToKeep.push(lastPoint); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - douglasPeuckerReduction(points, firstPoint, lastPoint, tolerance); │ │ │ │ │ - var returnPoints = []; │ │ │ │ │ - pointIndexsToKeep.sort(compareNumbers); │ │ │ │ │ - for (var index = 0; index < pointIndexsToKeep.length; index++) { │ │ │ │ │ - returnPoints.push(points[pointIndexsToKeep[index]]); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.LineString(returnPoints); │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - return this; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.LineString" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.LineString" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ @@ -22754,14 +15841,104 @@ │ │ │ │ │ * Constant: OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ * {Object} Default properties for the WFST format. │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Format.WFST.DEFAULTS = { │ │ │ │ │ "version": "1.0.0" │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Filter.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter │ │ │ │ │ + * This class represents an OGC Filter. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter │ │ │ │ │ + * This class represents a generic filter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Remove reference to anything added. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * Evaluates this filter in a specific context. Instances or subclasses │ │ │ │ │ + * are supposed to override this method. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * context - {Object} Context to use in evaluating the filter. If a vector │ │ │ │ │ + * feature is provided, the feature.attributes will be used as context. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The filter applies. │ │ │ │ │ + */ │ │ │ │ │ + evaluate: function(context) { │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. Should be implemented by subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + return null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: toString │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Include in your build to get a CQL │ │ │ │ │ + * representation of the filter returned. Otherwise "[Object object]" │ │ │ │ │ + * will be returned. │ │ │ │ │ + */ │ │ │ │ │ + toString: function() { │ │ │ │ │ + var string; │ │ │ │ │ + if (OpenLayers.Format && OpenLayers.Format.CQL) { │ │ │ │ │ + string = OpenLayers.Format.CQL.prototype.write(this); │ │ │ │ │ + } else { │ │ │ │ │ + string = Object.prototype.toString.call(this); │ │ │ │ │ + } │ │ │ │ │ + return string; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/Filter/Spatial.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -28848,3971 +22025,5256 @@ │ │ │ │ │ rawDataOutput: { │ │ │ │ │ identifier: output.identifier, │ │ │ │ │ mimeType: this.findMimeType(output.complexOutput.supported.formats, options.supportedFormats) │ │ │ │ │ } │ │ │ │ │ }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getOutputIndex │ │ │ │ │ - * Gets the index of a processOutput by its identifier │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * outputs - {Array} The processOutputs array to look at │ │ │ │ │ - * identifier - {String} The identifier of the output │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {Integer} The index of the processOutput with the provided identifier │ │ │ │ │ - * in the outputs array. │ │ │ │ │ - */ │ │ │ │ │ - getOutputIndex: function(outputs, identifier) { │ │ │ │ │ - var output; │ │ │ │ │ - if (identifier) { │ │ │ │ │ - for (var i = outputs.length - 1; i >= 0; --i) { │ │ │ │ │ - if (outputs[i].identifier === identifier) { │ │ │ │ │ - output = i; │ │ │ │ │ - break; │ │ │ │ │ + /** │ │ │ │ │ + * Method: getOutputIndex │ │ │ │ │ + * Gets the index of a processOutput by its identifier │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * outputs - {Array} The processOutputs array to look at │ │ │ │ │ + * identifier - {String} The identifier of the output │ │ │ │ │ + * │ │ │ │ │ + * Returns │ │ │ │ │ + * {Integer} The index of the processOutput with the provided identifier │ │ │ │ │ + * in the outputs array. │ │ │ │ │ + */ │ │ │ │ │ + getOutputIndex: function(outputs, identifier) { │ │ │ │ │ + var output; │ │ │ │ │ + if (identifier) { │ │ │ │ │ + for (var i = outputs.length - 1; i >= 0; --i) { │ │ │ │ │ + if (outputs[i].identifier === identifier) { │ │ │ │ │ + output = i; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + output = 0; │ │ │ │ │ + } │ │ │ │ │ + return output; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: chainProcess │ │ │ │ │ + * Sets a fully configured chained process as input for this process. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * input - {Object} The dataInput that the chained process provides. │ │ │ │ │ + * chainLink - {} The process to chain. │ │ │ │ │ + */ │ │ │ │ │ + chainProcess: function(input, chainLink) { │ │ │ │ │ + var output = this.getOutputIndex( │ │ │ │ │ + chainLink.process.description.processOutputs, chainLink.output │ │ │ │ │ + ); │ │ │ │ │ + input.reference.mimeType = this.findMimeType( │ │ │ │ │ + input.complexData.supported.formats, │ │ │ │ │ + chainLink.process.description.processOutputs[output].complexOutput.supported.formats │ │ │ │ │ + ); │ │ │ │ │ + var formats = {}; │ │ │ │ │ + formats[input.reference.mimeType] = true; │ │ │ │ │ + chainLink.process.setResponseForm({ │ │ │ │ │ + outputIndex: output, │ │ │ │ │ + supportedFormats: formats │ │ │ │ │ + }); │ │ │ │ │ + input.reference.body = chainLink.process.description; │ │ │ │ │ + while (this.executeCallbacks.length > 0) { │ │ │ │ │ + this.executeCallbacks[0](); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: toFeatures │ │ │ │ │ + * Converts spatial input into features so it can be processed by │ │ │ │ │ + * instances. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * source - {Mixed} An , an │ │ │ │ │ + * , or an array of geometries or features │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} │ │ │ │ │ + */ │ │ │ │ │ + toFeatures: function(source) { │ │ │ │ │ + var isArray = OpenLayers.Util.isArray(source); │ │ │ │ │ + if (!isArray) { │ │ │ │ │ + source = [source]; │ │ │ │ │ + } │ │ │ │ │ + var target = new Array(source.length), │ │ │ │ │ + current; │ │ │ │ │ + for (var i = 0, ii = source.length; i < ii; ++i) { │ │ │ │ │ + current = source[i]; │ │ │ │ │ + target[i] = current instanceof OpenLayers.Feature.Vector ? │ │ │ │ │ + current : new OpenLayers.Feature.Vector(current); │ │ │ │ │ + } │ │ │ │ │ + return isArray ? target : target[0]; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: findMimeType │ │ │ │ │ + * Finds a supported mime type. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * sourceFormats - {Object} An object literal with mime types as key and │ │ │ │ │ + * true as value for supported formats. │ │ │ │ │ + * targetFormats - {Object} Like , but optional to check for │ │ │ │ │ + * supported mime types on a different target than this process. │ │ │ │ │ + * Default is to check against this process's supported formats. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A supported mime type. │ │ │ │ │ + */ │ │ │ │ │ + findMimeType: function(sourceFormats, targetFormats) { │ │ │ │ │ + targetFormats = targetFormats || this.formats; │ │ │ │ │ + for (var f in sourceFormats) { │ │ │ │ │ + if (f in targetFormats) { │ │ │ │ │ + return f; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.WPSProcess" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ + * Type for chaining processes. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.WPSProcess.ChainLink = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: process │ │ │ │ │ + * {} The process to chain │ │ │ │ │ + */ │ │ │ │ │ + process: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: output │ │ │ │ │ + * {String} The output identifier of the output we are going to use as │ │ │ │ │ + * input for another process. │ │ │ │ │ + */ │ │ │ │ │ + output: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Properties to set on the instance. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.WPSProcess.ChainLink" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1_1_0.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * Read WPS DescribeProcess responses. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.XML, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + wps: "http://www.opengis.net/wps/1.0.0", │ │ │ │ │ + ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + */ │ │ │ │ │ + defaultPrefix: "wps", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ + */ │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Parse a WPS DescribeProcess and return an object with its information. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + read: function(data) { │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + if (data && data.nodeType == 9) { │ │ │ │ │ + data = data.documentElement; │ │ │ │ │ + } │ │ │ │ │ + var info = {}; │ │ │ │ │ + this.readNode(data, info); │ │ │ │ │ + return info; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: readers │ │ │ │ │ + * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ + * be applied when a namespaced node is found matching the function │ │ │ │ │ + * name. The function will be applied in the scope of this parser │ │ │ │ │ + * with two arguments: the node being read and a context object passed │ │ │ │ │ + * from the parent. │ │ │ │ │ + */ │ │ │ │ │ + readers: { │ │ │ │ │ + "wps": { │ │ │ │ │ + "ProcessDescriptions": function(node, obj) { │ │ │ │ │ + obj.processDescriptions = {}; │ │ │ │ │ + this.readChildNodes(node, obj.processDescriptions); │ │ │ │ │ + }, │ │ │ │ │ + "ProcessDescription": function(node, processDescriptions) { │ │ │ │ │ + var processVersion = this.getAttributeNS(node, this.namespaces.wps, "processVersion"); │ │ │ │ │ + var processDescription = { │ │ │ │ │ + processVersion: processVersion, │ │ │ │ │ + statusSupported: (node.getAttribute("statusSupported") === "true"), │ │ │ │ │ + storeSupported: (node.getAttribute("storeSupported") === "true") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, processDescription); │ │ │ │ │ + processDescriptions[processDescription.identifier] = processDescription; │ │ │ │ │ + }, │ │ │ │ │ + "DataInputs": function(node, processDescription) { │ │ │ │ │ + processDescription.dataInputs = []; │ │ │ │ │ + this.readChildNodes(node, processDescription.dataInputs); │ │ │ │ │ + }, │ │ │ │ │ + "ProcessOutputs": function(node, processDescription) { │ │ │ │ │ + processDescription.processOutputs = []; │ │ │ │ │ + this.readChildNodes(node, processDescription.processOutputs); │ │ │ │ │ + }, │ │ │ │ │ + "Output": function(node, processOutputs) { │ │ │ │ │ + var output = {}; │ │ │ │ │ + this.readChildNodes(node, output); │ │ │ │ │ + processOutputs.push(output); │ │ │ │ │ + }, │ │ │ │ │ + "ComplexOutput": function(node, output) { │ │ │ │ │ + output.complexOutput = {}; │ │ │ │ │ + this.readChildNodes(node, output.complexOutput); │ │ │ │ │ + }, │ │ │ │ │ + "LiteralOutput": function(node, output) { │ │ │ │ │ + output.literalOutput = {}; │ │ │ │ │ + this.readChildNodes(node, output.literalOutput); │ │ │ │ │ + }, │ │ │ │ │ + "Input": function(node, dataInputs) { │ │ │ │ │ + var input = { │ │ │ │ │ + maxOccurs: parseInt(node.getAttribute("maxOccurs")), │ │ │ │ │ + minOccurs: parseInt(node.getAttribute("minOccurs")) │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, input); │ │ │ │ │ + dataInputs.push(input); │ │ │ │ │ + }, │ │ │ │ │ + "BoundingBoxData": function(node, input) { │ │ │ │ │ + input.boundingBoxData = {}; │ │ │ │ │ + this.readChildNodes(node, input.boundingBoxData); │ │ │ │ │ + }, │ │ │ │ │ + "CRS": function(node, obj) { │ │ │ │ │ + if (!obj.CRSs) { │ │ │ │ │ + obj.CRSs = {}; │ │ │ │ │ + } │ │ │ │ │ + obj.CRSs[this.getChildValue(node)] = true; │ │ │ │ │ + }, │ │ │ │ │ + "LiteralData": function(node, input) { │ │ │ │ │ + input.literalData = {}; │ │ │ │ │ + this.readChildNodes(node, input.literalData); │ │ │ │ │ + }, │ │ │ │ │ + "ComplexData": function(node, input) { │ │ │ │ │ + input.complexData = {}; │ │ │ │ │ + this.readChildNodes(node, input.complexData); │ │ │ │ │ + }, │ │ │ │ │ + "Default": function(node, complexData) { │ │ │ │ │ + complexData["default"] = {}; │ │ │ │ │ + this.readChildNodes(node, complexData["default"]); │ │ │ │ │ + }, │ │ │ │ │ + "Supported": function(node, complexData) { │ │ │ │ │ + complexData["supported"] = {}; │ │ │ │ │ + this.readChildNodes(node, complexData["supported"]); │ │ │ │ │ + }, │ │ │ │ │ + "Format": function(node, obj) { │ │ │ │ │ + var format = {}; │ │ │ │ │ + this.readChildNodes(node, format); │ │ │ │ │ + if (!obj.formats) { │ │ │ │ │ + obj.formats = {}; │ │ │ │ │ + } │ │ │ │ │ + obj.formats[format.mimeType] = true; │ │ │ │ │ + }, │ │ │ │ │ + "MimeType": function(node, format) { │ │ │ │ │ + format.mimeType = this.getChildValue(node); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess" │ │ │ │ │ + │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/WPSClient.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/WPSProcess.js │ │ │ │ │ + * @requires OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.WPSClient │ │ │ │ │ + * High level API for interaction with Web Processing Services (WPS). │ │ │ │ │ + * An instance is used to create │ │ │ │ │ + * instances for servers known to the WPSClient. The WPSClient also caches │ │ │ │ │ + * DescribeProcess responses to reduce the number of requests sent to servers │ │ │ │ │ + * when processes are created. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.WPSClient = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: servers │ │ │ │ │ + * {Object} Service metadata, keyed by a local identifier. │ │ │ │ │ + * │ │ │ │ │ + * Properties: │ │ │ │ │ + * url - {String} the url of the server │ │ │ │ │ + * version - {String} WPS version of the server │ │ │ │ │ + * processDescription - {Object} Cache of raw DescribeProcess │ │ │ │ │ + * responses, keyed by process identifier. │ │ │ │ │ + */ │ │ │ │ │ + servers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: version │ │ │ │ │ + * {String} The default WPS version to use if none is configured. Default │ │ │ │ │ + * is '1.0.0'. │ │ │ │ │ + */ │ │ │ │ │ + version: '1.0.0', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: lazy │ │ │ │ │ + * {Boolean} Should the DescribeProcess be deferred until a process is │ │ │ │ │ + * fully configured? Default is false. │ │ │ │ │ + */ │ │ │ │ │ + lazy: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * describeprocess - Fires when the process description is available. │ │ │ │ │ + * Listeners receive an object with a 'raw' property holding the raw │ │ │ │ │ + * DescribeProcess response, and an 'identifier' property holding the │ │ │ │ │ + * process identifier of the described process. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.WPSClient │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * │ │ │ │ │ + * Avaliable options: │ │ │ │ │ + * servers - {Object} Mandatory. Service metadata, keyed by a local │ │ │ │ │ + * identifier. Can either be a string with the service url or an │ │ │ │ │ + * object literal with additional metadata: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * servers: { │ │ │ │ │ + * local: '/geoserver/wps' │ │ │ │ │ + * }, { │ │ │ │ │ + * opengeo: { │ │ │ │ │ + * url: 'http://demo.opengeo.org/geoserver/wps', │ │ │ │ │ + * version: '1.0.0' │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * lazy - {Boolean} Optional. Set to true if DescribeProcess should not be │ │ │ │ │ + * requested until a process is fully configured. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + this.servers = {}; │ │ │ │ │ + for (var s in options.servers) { │ │ │ │ │ + this.servers[s] = typeof options.servers[s] == 'string' ? { │ │ │ │ │ + url: options.servers[s], │ │ │ │ │ + version: this.version, │ │ │ │ │ + processDescription: {} │ │ │ │ │ + } : options.servers[s]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: execute │ │ │ │ │ + * Shortcut to execute a process with a single function call. This is │ │ │ │ │ + * equivalent to using and then calling execute on the │ │ │ │ │ + * process. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Options for the execute operation. │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * server - {String} Mandatory. One of the local identifiers of the │ │ │ │ │ + * configured servers. │ │ │ │ │ + * process - {String} Mandatory. A process identifier known to the │ │ │ │ │ + * server. │ │ │ │ │ + * inputs - {Object} The inputs for the process, keyed by input identifier. │ │ │ │ │ + * For spatial data inputs, the value of an input is usually an │ │ │ │ │ + * , an or an array of │ │ │ │ │ + * geometries or features. │ │ │ │ │ + * output - {String} The identifier of an output to parse. Optional. If not │ │ │ │ │ + * provided, the first output will be parsed. │ │ │ │ │ + * success - {Function} Callback to call when the process is complete. │ │ │ │ │ + * This function is called with an outputs object as argument, which │ │ │ │ │ + * will have a property with the identifier of the requested output │ │ │ │ │ + * (e.g. 'result'). For processes that generate spatial output, the │ │ │ │ │ + * value will either be a single or an │ │ │ │ │ + * array of features. │ │ │ │ │ + * scope - {Object} Optional scope for the success callback. │ │ │ │ │ + */ │ │ │ │ │ + execute: function(options) { │ │ │ │ │ + var process = this.getProcess(options.server, options.process); │ │ │ │ │ + process.execute({ │ │ │ │ │ + inputs: options.inputs, │ │ │ │ │ + success: options.success, │ │ │ │ │ + scope: options.scope │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getProcess │ │ │ │ │ + * Creates an . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * serverID - {String} Local identifier from the servers that this instance │ │ │ │ │ + * was constructed with. │ │ │ │ │ + * processID - {String} Process identifier known to the server. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getProcess: function(serverID, processID) { │ │ │ │ │ + var process = new OpenLayers.WPSProcess({ │ │ │ │ │ + client: this, │ │ │ │ │ + server: serverID, │ │ │ │ │ + identifier: processID │ │ │ │ │ + }); │ │ │ │ │ + if (!this.lazy) { │ │ │ │ │ + process.describe(); │ │ │ │ │ + } │ │ │ │ │ + return process; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: describeProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * serverID - {String} Identifier of the server │ │ │ │ │ + * processID - {String} Identifier of the requested process │ │ │ │ │ + * callback - {Function} Callback to call when the description is available │ │ │ │ │ + * scope - {Object} Optional execution scope for the callback function │ │ │ │ │ + */ │ │ │ │ │ + describeProcess: function(serverID, processID, callback, scope) { │ │ │ │ │ + var server = this.servers[serverID]; │ │ │ │ │ + if (!server.processDescription[processID]) { │ │ │ │ │ + if (!(processID in server.processDescription)) { │ │ │ │ │ + // set to null so we know a describeFeature request is pending │ │ │ │ │ + server.processDescription[processID] = null; │ │ │ │ │ + OpenLayers.Request.GET({ │ │ │ │ │ + url: server.url, │ │ │ │ │ + params: { │ │ │ │ │ + SERVICE: 'WPS', │ │ │ │ │ + VERSION: server.version, │ │ │ │ │ + REQUEST: 'DescribeProcess', │ │ │ │ │ + IDENTIFIER: processID │ │ │ │ │ + }, │ │ │ │ │ + success: function(response) { │ │ │ │ │ + server.processDescription[processID] = response.responseText; │ │ │ │ │ + this.events.triggerEvent('describeprocess', { │ │ │ │ │ + identifier: processID, │ │ │ │ │ + raw: response.responseText │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + // pending request │ │ │ │ │ + this.events.register('describeprocess', this, function describe(evt) { │ │ │ │ │ + if (evt.identifier === processID) { │ │ │ │ │ + this.events.unregister('describeprocess', this, describe); │ │ │ │ │ + callback.call(scope, evt.raw); │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + window.setTimeout(function() { │ │ │ │ │ + callback.call(scope, server.processDescription[processID]); │ │ │ │ │ + }, 0); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + this.servers = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Projection.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Projection │ │ │ │ │ + * Methods for coordinate transforms between coordinate systems. By default, │ │ │ │ │ + * OpenLayers ships with the ability to transform coordinates between │ │ │ │ │ + * geographic (EPSG:4326) and web or spherical mercator (EPSG:900913 et al.) │ │ │ │ │ + * coordinate reference systems. See the method for details │ │ │ │ │ + * on usage. │ │ │ │ │ + * │ │ │ │ │ + * Additional transforms may be added by using the │ │ │ │ │ + * library. If the proj4js library is included, the method │ │ │ │ │ + * will work between any two coordinate reference systems with proj4js │ │ │ │ │ + * definitions. │ │ │ │ │ + * │ │ │ │ │ + * If the proj4js library is not included, or if you wish to allow transforms │ │ │ │ │ + * between arbitrary coordinate reference systems, use the │ │ │ │ │ + * method to register a custom transform method. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: proj │ │ │ │ │ + * {Object} Proj4js.Proj instance. │ │ │ │ │ + */ │ │ │ │ │ + proj: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: projCode │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + projCode: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: titleRegEx │ │ │ │ │ + * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ + */ │ │ │ │ │ + titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Projection │ │ │ │ │ + * This class offers several methods for interacting with a wrapped │ │ │ │ │ + * pro4js projection object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * projCode - {String} A string identifying the Well Known Identifier for │ │ │ │ │ + * the projection. │ │ │ │ │ + * options - {Object} An optional object to set additional properties │ │ │ │ │ + * on the projection. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A projection object. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(projCode, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.projCode = projCode; │ │ │ │ │ + if (typeof Proj4js == "object") { │ │ │ │ │ + this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getCode │ │ │ │ │ + * Get the string SRS code. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The SRS code. │ │ │ │ │ + */ │ │ │ │ │ + getCode: function() { │ │ │ │ │ + return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getUnits │ │ │ │ │ + * Get the units string for the projection -- returns null if │ │ │ │ │ + * proj4js is not available. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The units abbreviation. │ │ │ │ │ + */ │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + return this.proj ? this.proj.units : null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Convert projection to string (getCode wrapper). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The projection code. │ │ │ │ │ + */ │ │ │ │ │ + toString: function() { │ │ │ │ │ + return this.getCode(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: equals │ │ │ │ │ + * Test equality of two projection instances. Determines equality based │ │ │ │ │ + * soley on the projection code. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The two projections are equivalent. │ │ │ │ │ + */ │ │ │ │ │ + equals: function(projection) { │ │ │ │ │ + var p = projection, │ │ │ │ │ + equals = false; │ │ │ │ │ + if (p) { │ │ │ │ │ + if (!(p instanceof OpenLayers.Projection)) { │ │ │ │ │ + p = new OpenLayers.Projection(p); │ │ │ │ │ + } │ │ │ │ │ + if ((typeof Proj4js == "object") && this.proj.defData && p.proj.defData) { │ │ │ │ │ + equals = this.proj.defData.replace(this.titleRegEx, "") == │ │ │ │ │ + p.proj.defData.replace(this.titleRegEx, ""); │ │ │ │ │ + } else if (p.getCode) { │ │ │ │ │ + var source = this.getCode(), │ │ │ │ │ + target = p.getCode(); │ │ │ │ │ + equals = source == target || │ │ │ │ │ + !!OpenLayers.Projection.transforms[source] && │ │ │ │ │ + OpenLayers.Projection.transforms[source][target] === │ │ │ │ │ + OpenLayers.Projection.nullTransform; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return equals; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /* Method: destroy │ │ │ │ │ + * Destroy projection object. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + delete this.proj; │ │ │ │ │ + delete this.projCode; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Projection" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Property: transforms │ │ │ │ │ + * {Object} Transforms is an object, with from properties, each of which may │ │ │ │ │ + * have a to property. This allows you to define projections without │ │ │ │ │ + * requiring support for proj4js to be included. │ │ │ │ │ + * │ │ │ │ │ + * This object has keys which correspond to a 'source' projection object. The │ │ │ │ │ + * keys should be strings, corresponding to the projection.getCode() value. │ │ │ │ │ + * Each source projection object should have a set of destination projection │ │ │ │ │ + * keys included in the object. │ │ │ │ │ + * │ │ │ │ │ + * Each value in the destination object should be a transformation function, │ │ │ │ │ + * where the function is expected to be passed an object with a .x and a .y │ │ │ │ │ + * property. The function should return the object, with the .x and .y │ │ │ │ │ + * transformed according to the transformation function. │ │ │ │ │ + * │ │ │ │ │ + * Note - Properties on this object should not be set directly. To add a │ │ │ │ │ + * transform method to this object, use the method. For an │ │ │ │ │ + * example of usage, see the OpenLayers.Layer.SphericalMercator file. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection.transforms = {}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIProperty: defaults │ │ │ │ │ + * {Object} Defaults for the SRS codes known to OpenLayers (currently │ │ │ │ │ + * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, │ │ │ │ │ + * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units, │ │ │ │ │ + * maxExtent (the validity extent for the SRS) and yx (true if this SRS is │ │ │ │ │ + * known to have a reverse axis order). │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection.defaults = { │ │ │ │ │ + "EPSG:4326": { │ │ │ │ │ + units: "degrees", │ │ │ │ │ + maxExtent: [-180, -90, 180, 90], │ │ │ │ │ + yx: true │ │ │ │ │ + }, │ │ │ │ │ + "CRS:84": { │ │ │ │ │ + units: "degrees", │ │ │ │ │ + maxExtent: [-180, -90, 180, 90] │ │ │ │ │ + }, │ │ │ │ │ + "EPSG:900913": { │ │ │ │ │ + units: "m", │ │ │ │ │ + maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34] │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIMethod: addTransform │ │ │ │ │ + * Set a custom transform method between two projections. Use this method in │ │ │ │ │ + * cases where the proj4js lib is not available or where custom projections │ │ │ │ │ + * need to be handled. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * from - {String} The code for the source projection │ │ │ │ │ + * to - {String} the code for the destination projection │ │ │ │ │ + * method - {Function} A function that takes a point as an argument and │ │ │ │ │ + * transforms that point from the source to the destination projection │ │ │ │ │ + * in place. The original point should be modified. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection.addTransform = function(from, to, method) { │ │ │ │ │ + if (method === OpenLayers.Projection.nullTransform) { │ │ │ │ │ + var defaults = OpenLayers.Projection.defaults[from]; │ │ │ │ │ + if (defaults && !OpenLayers.Projection.defaults[to]) { │ │ │ │ │ + OpenLayers.Projection.defaults[to] = defaults; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!OpenLayers.Projection.transforms[from]) { │ │ │ │ │ + OpenLayers.Projection.transforms[from] = {}; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Projection.transforms[from][to] = method; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Transform a point coordinate from one projection to another. Note that │ │ │ │ │ + * the input point is transformed in place. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - { | Object} An object with x and y │ │ │ │ │ + * properties representing coordinates in those dimensions. │ │ │ │ │ + * source - {OpenLayers.Projection} Source map coordinate system │ │ │ │ │ + * dest - {OpenLayers.Projection} Destination map coordinate system │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * point - {object} A transformed coordinate. The original point is modified. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection.transform = function(point, source, dest) { │ │ │ │ │ + if (source && dest) { │ │ │ │ │ + if (!(source instanceof OpenLayers.Projection)) { │ │ │ │ │ + source = new OpenLayers.Projection(source); │ │ │ │ │ + } │ │ │ │ │ + if (!(dest instanceof OpenLayers.Projection)) { │ │ │ │ │ + dest = new OpenLayers.Projection(dest); │ │ │ │ │ + } │ │ │ │ │ + if (source.proj && dest.proj) { │ │ │ │ │ + point = Proj4js.transform(source.proj, dest.proj, point); │ │ │ │ │ + } else { │ │ │ │ │ + var sourceCode = source.getCode(); │ │ │ │ │ + var destCode = dest.getCode(); │ │ │ │ │ + var transforms = OpenLayers.Projection.transforms; │ │ │ │ │ + if (transforms[sourceCode] && transforms[sourceCode][destCode]) { │ │ │ │ │ + transforms[sourceCode][destCode](point); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return point; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: nullTransform │ │ │ │ │ + * A null transformation - useful for defining projection aliases when │ │ │ │ │ + * proj4js is not available: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913", │ │ │ │ │ + * OpenLayers.Projection.nullTransform); │ │ │ │ │ + * OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857", │ │ │ │ │ + * OpenLayers.Projection.nullTransform); │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Projection.nullTransform = function(point) { │ │ │ │ │ + return point; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Note: Transforms for web mercator <-> geographic │ │ │ │ │ + * OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100. │ │ │ │ │ + * OpenLayers originally started referring to EPSG:900913 as web mercator. │ │ │ │ │ + * The EPSG has declared EPSG:3857 to be web mercator. │ │ │ │ │ + * ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as │ │ │ │ │ + * equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084. │ │ │ │ │ + * For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and │ │ │ │ │ + * urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis │ │ │ │ │ + * order for EPSG:4326. │ │ │ │ │ + */ │ │ │ │ │ +(function() { │ │ │ │ │ + │ │ │ │ │ + var pole = 20037508.34; │ │ │ │ │ + │ │ │ │ │ + function inverseMercator(xy) { │ │ │ │ │ + xy.x = 180 * xy.x / pole; │ │ │ │ │ + xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2); │ │ │ │ │ + return xy; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + function forwardMercator(xy) { │ │ │ │ │ + xy.x = xy.x * pole / 180; │ │ │ │ │ + var y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole; │ │ │ │ │ + xy.y = Math.max(-20037508.34, Math.min(y, 20037508.34)); │ │ │ │ │ + return xy; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + function map(base, codes) { │ │ │ │ │ + var add = OpenLayers.Projection.addTransform; │ │ │ │ │ + var same = OpenLayers.Projection.nullTransform; │ │ │ │ │ + var i, len, code, other, j; │ │ │ │ │ + for (i = 0, len = codes.length; i < len; ++i) { │ │ │ │ │ + code = codes[i]; │ │ │ │ │ + add(base, code, forwardMercator); │ │ │ │ │ + add(code, base, inverseMercator); │ │ │ │ │ + for (j = i + 1; j < len; ++j) { │ │ │ │ │ + other = codes[j]; │ │ │ │ │ + add(code, other, same); │ │ │ │ │ + add(other, code, same); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // list of equivalent codes for web mercator │ │ │ │ │ + var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"], │ │ │ │ │ + geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"], │ │ │ │ │ + i; │ │ │ │ │ + for (i = mercator.length - 1; i >= 0; --i) { │ │ │ │ │ + map(mercator[i], geographic); │ │ │ │ │ + } │ │ │ │ │ + for (i = geographic.length - 1; i >= 0; --i) { │ │ │ │ │ + map(geographic[i], mercator); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ +})(); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Map.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Tween.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Map │ │ │ │ │ + * Instances of OpenLayers.Map are interactive maps embedded in a web page. │ │ │ │ │ + * Create a new map with the constructor. │ │ │ │ │ + * │ │ │ │ │ + * On their own maps do not provide much functionality. To extend a map │ │ │ │ │ + * it's necessary to add controls () and │ │ │ │ │ + * layers () to the map. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Map = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: Z_INDEX_BASE │ │ │ │ │ + * {Object} Base z-indexes for different classes of thing │ │ │ │ │ + */ │ │ │ │ │ + Z_INDEX_BASE: { │ │ │ │ │ + BaseLayer: 100, │ │ │ │ │ + Overlay: 325, │ │ │ │ │ + Feature: 725, │ │ │ │ │ + Popup: 750, │ │ │ │ │ + Control: 1000 │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * map.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to map.events.object. │ │ │ │ │ + * element - {DOMElement} A reference to map.events.element. │ │ │ │ │ + * │ │ │ │ │ + * Browser events have the following additional properties: │ │ │ │ │ + * xy - {} The pixel location of the event (relative │ │ │ │ │ + * to the the map viewport). │ │ │ │ │ + * │ │ │ │ │ + * Supported map event types: │ │ │ │ │ + * preaddlayer - triggered before a layer has been added. The event │ │ │ │ │ + * object will include a *layer* property that references the layer │ │ │ │ │ + * to be added. When a listener returns "false" the adding will be │ │ │ │ │ + * aborted. │ │ │ │ │ + * addlayer - triggered after a layer has been added. The event object │ │ │ │ │ + * will include a *layer* property that references the added layer. │ │ │ │ │ + * preremovelayer - triggered before a layer has been removed. The event │ │ │ │ │ + * object will include a *layer* property that references the layer │ │ │ │ │ + * to be removed. When a listener returns "false" the removal will be │ │ │ │ │ + * aborted. │ │ │ │ │ + * removelayer - triggered after a layer has been removed. The event │ │ │ │ │ + * object will include a *layer* property that references the removed │ │ │ │ │ + * layer. │ │ │ │ │ + * changelayer - triggered after a layer name change, order change, │ │ │ │ │ + * opacity change, params change, visibility change (actual visibility, │ │ │ │ │ + * not the layer's visibility property) or attribution change (due to │ │ │ │ │ + * extent change). Listeners will receive an event object with *layer* │ │ │ │ │ + * and *property* properties. The *layer* property will be a reference │ │ │ │ │ + * to the changed layer. The *property* property will be a key to the │ │ │ │ │ + * changed property (name, order, opacity, params, visibility or │ │ │ │ │ + * attribution). │ │ │ │ │ + * movestart - triggered after the start of a drag, pan, or zoom. The event │ │ │ │ │ + * object may include a *zoomChanged* property that tells whether the │ │ │ │ │ + * zoom has changed. │ │ │ │ │ + * move - triggered after each drag, pan, or zoom │ │ │ │ │ + * moveend - triggered after a drag, pan, or zoom completes │ │ │ │ │ + * zoomend - triggered after a zoom completes │ │ │ │ │ + * mouseover - triggered after mouseover the map │ │ │ │ │ + * mouseout - triggered after mouseout the map │ │ │ │ │ + * mousemove - triggered after mousemove the map │ │ │ │ │ + * changebaselayer - triggered after the base layer changes │ │ │ │ │ + * updatesize - triggered after the method was executed │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} Unique identifier for the map │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: fractionalZoom │ │ │ │ │ + * {Boolean} For a base layer that supports it, allow the map resolution │ │ │ │ │ + * to be set to a value between one of the values in the resolutions │ │ │ │ │ + * array. Default is false. │ │ │ │ │ + * │ │ │ │ │ + * When fractionalZoom is set to true, it is possible to zoom to │ │ │ │ │ + * an arbitrary extent. This requires a base layer from a source │ │ │ │ │ + * that supports requests for arbitrary extents (i.e. not cached │ │ │ │ │ + * tiles on a regular lattice). This means that fractionalZoom │ │ │ │ │ + * will not work with commercial layers (Google, Yahoo, VE), layers │ │ │ │ │ + * using TileCache, or any other pre-cached data sources. │ │ │ │ │ + * │ │ │ │ │ + * If you are using fractionalZoom, then you should also use │ │ │ │ │ + * instead of layer.resolutions[zoom] as the │ │ │ │ │ + * former works for non-integer zoom levels. │ │ │ │ │ + */ │ │ │ │ │ + fractionalZoom: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the map │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: allOverlays │ │ │ │ │ + * {Boolean} Allow the map to function with "overlays" only. Defaults to │ │ │ │ │ + * false. If true, the lowest layer in the draw order will act as │ │ │ │ │ + * the base layer. In addition, if set to true, all layers will │ │ │ │ │ + * have isBaseLayer set to false when they are added to the map. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * If you set map.allOverlays to true, then you *cannot* use │ │ │ │ │ + * map.setBaseLayer or layer.setIsBaseLayer. With allOverlays true, │ │ │ │ │ + * the lowest layer in the draw layer is the base layer. So, to change │ │ │ │ │ + * the base layer, use or to set the layer │ │ │ │ │ + * index to 0. │ │ │ │ │ + */ │ │ │ │ │ + allOverlays: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement|String} The element that contains the map (or an id for │ │ │ │ │ + * that element). If the constructor is called │ │ │ │ │ + * with two arguments, this should be provided as the first argument. │ │ │ │ │ + * Alternatively, the map constructor can be called with the options │ │ │ │ │ + * object as the only argument. In this case (one argument), a │ │ │ │ │ + * div property may or may not be provided. If the div property │ │ │ │ │ + * is not provided, the map can be rendered to a container later │ │ │ │ │ + * using the method. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * If you are calling after map construction, do not use │ │ │ │ │ + * auto. Instead, divide your by your │ │ │ │ │ + * maximum expected dimension. │ │ │ │ │ + */ │ │ │ │ │ + div: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: dragging │ │ │ │ │ + * {Boolean} The map is currently being dragged. │ │ │ │ │ + */ │ │ │ │ │ + dragging: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} Size of the main div (this.div) │ │ │ │ │ + */ │ │ │ │ │ + size: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: viewPortDiv │ │ │ │ │ + * {HTMLDivElement} The element that represents the map viewport │ │ │ │ │ + */ │ │ │ │ │ + viewPortDiv: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerContainerOrigin │ │ │ │ │ + * {} The lonlat at which the later container was │ │ │ │ │ + * re-initialized (on-zoom) │ │ │ │ │ + */ │ │ │ │ │ + layerContainerOrigin: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerContainerDiv │ │ │ │ │ + * {HTMLDivElement} The element that contains the layers. │ │ │ │ │ + */ │ │ │ │ │ + layerContainerDiv: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} Ordered list of layers in the map │ │ │ │ │ + */ │ │ │ │ │ + layers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: controls │ │ │ │ │ + * {Array()} List of controls associated with the map. │ │ │ │ │ + * │ │ │ │ │ + * If not provided in the map options at construction, the map will │ │ │ │ │ + * by default be given the following controls if present in the build: │ │ │ │ │ + * - or │ │ │ │ │ + * - or │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ + controls: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: popups │ │ │ │ │ + * {Array()} List of popups associated with the map │ │ │ │ │ + */ │ │ │ │ │ + popups: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: baseLayer │ │ │ │ │ + * {} The currently selected base layer. This determines │ │ │ │ │ + * min/max zoom level, projection, etc. │ │ │ │ │ + */ │ │ │ │ │ + baseLayer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: center │ │ │ │ │ + * {} The current center of the map │ │ │ │ │ + */ │ │ │ │ │ + center: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} The resolution of the map. │ │ │ │ │ + */ │ │ │ │ │ + resolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoom │ │ │ │ │ + * {Integer} The current zoom level of the map │ │ │ │ │ + */ │ │ │ │ │ + zoom: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: panRatio │ │ │ │ │ + * {Float} The ratio of the current extent within │ │ │ │ │ + * which panning will tween. │ │ │ │ │ + */ │ │ │ │ │ + panRatio: 1.5, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: options │ │ │ │ │ + * {Object} The options object passed to the class constructor. Read-only. │ │ │ │ │ + */ │ │ │ │ │ + options: null, │ │ │ │ │ + │ │ │ │ │ + // Options │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tileSize │ │ │ │ │ + * {} Set in the map options to override the default tile │ │ │ │ │ + * size for this map. │ │ │ │ │ + */ │ │ │ │ │ + tileSize: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: projection │ │ │ │ │ + * {String} Set in the map options to specify the default projection │ │ │ │ │ + * for layers added to this map. When using a projection other than EPSG:4326 │ │ │ │ │ + * (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), │ │ │ │ │ + * also set maxExtent, maxResolution or resolutions. Default is "EPSG:4326". │ │ │ │ │ + * Note that the projection of the map is usually determined │ │ │ │ │ + * by that of the current baseLayer (see and ). │ │ │ │ │ + */ │ │ │ │ │ + projection: "EPSG:4326", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: units │ │ │ │ │ + * {String} The map units. Possible values are 'degrees' (or 'dd'), 'm', │ │ │ │ │ + * 'ft', 'km', 'mi', 'inches'. Normally taken from the projection. │ │ │ │ │ + * Only required if both map and layers do not define a projection, │ │ │ │ │ + * or if they define a projection which does not define units │ │ │ │ │ + */ │ │ │ │ │ + units: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: resolutions │ │ │ │ │ + * {Array(Float)} A list of map resolutions (map units per pixel) in │ │ │ │ │ + * descending order. If this is not set in the layer constructor, it │ │ │ │ │ + * will be set based on other resolution related properties │ │ │ │ │ + * (maxExtent, maxResolution, maxScale, etc.). │ │ │ │ │ + */ │ │ │ │ │ + resolutions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxResolution │ │ │ │ │ + * {Float} Required if you are not displaying the whole world on a tile │ │ │ │ │ + * with the size specified in . │ │ │ │ │ + */ │ │ │ │ │ + maxResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minResolution │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + maxScale: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minScale: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The maximum extent for the map. │ │ │ │ │ + * Default depends on projection; if this is one of those defined in OpenLayers.Projection.defaults │ │ │ │ │ + * (EPSG:4326 or web mercator), maxExtent will be set to the value defined there; │ │ │ │ │ + * else, defaults to null. │ │ │ │ │ + * To restrict user panning and zooming of the map, use instead. │ │ │ │ │ + * The value for will change calculations for tile URLs. │ │ │ │ │ + */ │ │ │ │ │ + maxExtent: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The minimum extent for the map. Defaults to null. │ │ │ │ │ + */ │ │ │ │ │ + minExtent: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: restrictedExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * Limit map navigation to this extent where possible. │ │ │ │ │ + * If a non-null restrictedExtent is set, panning will be restricted │ │ │ │ │ + * to the given bounds. In addition, zooming to a resolution that │ │ │ │ │ + * displays more than the restricted extent will center the map │ │ │ │ │ + * on the restricted extent. If you wish to limit the zoom level │ │ │ │ │ + * or resolution, use maxResolution. │ │ │ │ │ + */ │ │ │ │ │ + restrictedExtent: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} Number of zoom levels for the map. Defaults to 16. Set a │ │ │ │ │ + * different value in the map options if needed. │ │ │ │ │ + */ │ │ │ │ │ + numZoomLevels: 16, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: theme │ │ │ │ │ + * {String} Relative path to a CSS file from which to load theme styles. │ │ │ │ │ + * Specify null in the map options (e.g. {theme: null}) if you │ │ │ │ │ + * want to get cascading style declarations - by putting links to │ │ │ │ │ + * stylesheets or style declarations directly in your page. │ │ │ │ │ + */ │ │ │ │ │ + theme: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayProjection │ │ │ │ │ + * {} Requires proj4js support for projections other │ │ │ │ │ + * than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by │ │ │ │ │ + * several controls to display data to user. If this property is set, │ │ │ │ │ + * it will be set on any control which has a null displayProjection │ │ │ │ │ + * property at the time the control is added to the map. │ │ │ │ │ + */ │ │ │ │ │ + displayProjection: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tileManager │ │ │ │ │ + * {|Object} By default, and if the build contains │ │ │ │ │ + * TileManager.js, the map will use the TileManager to queue image requests │ │ │ │ │ + * and to cache tile image elements. To create a map without a TileManager │ │ │ │ │ + * configure the map with tileManager: null. To create a TileManager with │ │ │ │ │ + * non-default options, supply the options instead or alternatively supply │ │ │ │ │ + * an instance of {}. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fallThrough │ │ │ │ │ + * {Boolean} Should OpenLayers allow events on the map to fall through to │ │ │ │ │ + * other elements on the page, or should it swallow them? (#457) │ │ │ │ │ + * Default is to swallow. │ │ │ │ │ + */ │ │ │ │ │ + fallThrough: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: autoUpdateSize │ │ │ │ │ + * {Boolean} Should OpenLayers automatically update the size of the map │ │ │ │ │ + * when the resize event is fired. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + autoUpdateSize: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ + */ │ │ │ │ │ + eventListeners: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: panTween │ │ │ │ │ + * {} Animated panning tween object, see panTo() │ │ │ │ │ + */ │ │ │ │ │ + panTween: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: panMethod │ │ │ │ │ + * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ + * OpenLayers.Easing.Expo.easeOut. Setting this to 'null' turns off │ │ │ │ │ + * animated panning. │ │ │ │ │ + */ │ │ │ │ │ + panMethod: OpenLayers.Easing.Expo.easeOut, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: panDuration │ │ │ │ │ + * {Integer} The number of steps to be passed to the │ │ │ │ │ + * OpenLayers.Tween.start() method when the map is │ │ │ │ │ + * panned. │ │ │ │ │ + * Default is 50. │ │ │ │ │ + */ │ │ │ │ │ + panDuration: 50, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomTween │ │ │ │ │ + * {} Animated zooming tween object, see zoomTo() │ │ │ │ │ + */ │ │ │ │ │ + zoomTween: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomMethod │ │ │ │ │ + * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ + * OpenLayers.Easing.Quad.easeOut. Setting this to 'null' turns off │ │ │ │ │ + * animated zooming. │ │ │ │ │ + */ │ │ │ │ │ + zoomMethod: OpenLayers.Easing.Quad.easeOut, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomDuration │ │ │ │ │ + * {Integer} The number of steps to be passed to the │ │ │ │ │ + * OpenLayers.Tween.start() method when the map is zoomed. │ │ │ │ │ + * Default is 20. │ │ │ │ │ + */ │ │ │ │ │ + zoomDuration: 20, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: paddingForPopups │ │ │ │ │ + * {} Outside margin of the popup. Used to prevent │ │ │ │ │ + * the popup from getting too close to the map border. │ │ │ │ │ + */ │ │ │ │ │ + paddingForPopups: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerContainerOriginPx │ │ │ │ │ + * {Object} Cached object representing the layer container origin (in pixels). │ │ │ │ │ + */ │ │ │ │ │ + layerContainerOriginPx: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: minPx │ │ │ │ │ + * {Object} An object with a 'x' and 'y' values that is the lower │ │ │ │ │ + * left of maxExtent in viewport pixel space. │ │ │ │ │ + * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ + * is valid. It is also used in the getLonLatFromViewPortPx function │ │ │ │ │ + * of Layer. │ │ │ │ │ + */ │ │ │ │ │ + minPx: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: maxPx │ │ │ │ │ + * {Object} An object with a 'x' and 'y' values that is the top │ │ │ │ │ + * right of maxExtent in viewport pixel space. │ │ │ │ │ + * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ + * is valid. │ │ │ │ │ + */ │ │ │ │ │ + maxPx: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Map │ │ │ │ │ + * Constructor for a new OpenLayers.Map instance. There are two possible │ │ │ │ │ + * ways to call the map constructor. See the examples below. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * div - {DOMElement|String} The element or id of an element in your page │ │ │ │ │ + * that will contain the map. May be omitted if the
option is │ │ │ │ │ + * provided or if you intend to call the method later. │ │ │ │ │ + * options - {Object} Optional object with properties to tag onto the map. │ │ │ │ │ + * │ │ │ │ │ + * Valid options (in addition to the listed API properties): │ │ │ │ │ + * center - {|Array} The default initial center of the map. │ │ │ │ │ + * If provided as array, the first value is the x coordinate, │ │ │ │ │ + * and the 2nd value is the y coordinate. │ │ │ │ │ + * Only specify if is provided. │ │ │ │ │ + * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ + * and the querystring contains coordinates, center will be set │ │ │ │ │ + * by that, and this option will be ignored. │ │ │ │ │ + * zoom - {Number} The initial zoom level for the map. Only specify if │ │ │ │ │ + * is provided. │ │ │ │ │ + * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ + * and the querystring contains a zoom level, zoom will be set │ │ │ │ │ + * by that, and this option will be ignored. │ │ │ │ │ + * extent - {|Array} The initial extent of the map. │ │ │ │ │ + * If provided as an array, the array should consist of │ │ │ │ │ + * four values (left, bottom, right, top). │ │ │ │ │ + * Only specify if
and are not provided. │ │ │ │ │ + * │ │ │ │ │ + * Examples: │ │ │ │ │ + * (code) │ │ │ │ │ + * // create a map with default options in an element with the id "map1" │ │ │ │ │ + * var map = new OpenLayers.Map("map1"); │ │ │ │ │ + * │ │ │ │ │ + * // create a map with non-default options in an element with id "map2" │ │ │ │ │ + * var options = { │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000), │ │ │ │ │ + * center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095) │ │ │ │ │ + * }; │ │ │ │ │ + * var map = new OpenLayers.Map("map2", options); │ │ │ │ │ + * │ │ │ │ │ + * // map with non-default options - same as above but with a single argument, │ │ │ │ │ + * // a restricted extent, and using arrays for bounds and center │ │ │ │ │ + * var map = new OpenLayers.Map({ │ │ │ │ │ + * div: "map_id", │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146], │ │ │ │ │ + * restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962], │ │ │ │ │ + * center: [-12356463.476333, 5621521.4854095] │ │ │ │ │ + * }); │ │ │ │ │ + * │ │ │ │ │ + * // create a map without a reference to a container - call render later │ │ │ │ │ + * var map = new OpenLayers.Map({ │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000) │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(div, options) { │ │ │ │ │ + │ │ │ │ │ + // If only one argument is provided, check if it is an object. │ │ │ │ │ + if (arguments.length === 1 && typeof div === "object") { │ │ │ │ │ + options = div; │ │ │ │ │ + div = options && options.div; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // Simple-type defaults are set in class definition. │ │ │ │ │ + // Now set complex-type defaults │ │ │ │ │ + this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH, │ │ │ │ │ + OpenLayers.Map.TILE_HEIGHT); │ │ │ │ │ + │ │ │ │ │ + this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15); │ │ │ │ │ + │ │ │ │ │ + this.theme = OpenLayers._getScriptLocation() + │ │ │ │ │ + 'theme/default/style.css'; │ │ │ │ │ + │ │ │ │ │ + // backup original options │ │ │ │ │ + this.options = OpenLayers.Util.extend({}, options); │ │ │ │ │ + │ │ │ │ │ + // now override default options │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + │ │ │ │ │ + var projCode = this.projection instanceof OpenLayers.Projection ? │ │ │ │ │ + this.projection.projCode : this.projection; │ │ │ │ │ + OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]); │ │ │ │ │ + │ │ │ │ │ + // allow extents and center to be arrays │ │ │ │ │ + if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.maxExtent = new OpenLayers.Bounds(this.maxExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.minExtent && !(this.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.minExtent = new OpenLayers.Bounds(this.minExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.restrictedExtent && !(this.restrictedExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.restrictedExtent = new OpenLayers.Bounds(this.restrictedExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.center && !(this.center instanceof OpenLayers.LonLat)) { │ │ │ │ │ + this.center = new OpenLayers.LonLat(this.center); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // initialize layers array │ │ │ │ │ + this.layers = []; │ │ │ │ │ + │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID("OpenLayers.Map_"); │ │ │ │ │ + │ │ │ │ │ + this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ + if (!this.div) { │ │ │ │ │ + this.div = document.createElement("div"); │ │ │ │ │ + this.div.style.height = "1px"; │ │ │ │ │ + this.div.style.width = "1px"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ + │ │ │ │ │ + // the viewPortDiv is the outermost div we modify │ │ │ │ │ + var id = this.id + "_OpenLayers_ViewPort"; │ │ │ │ │ + this.viewPortDiv = OpenLayers.Util.createDiv(id, null, null, null, │ │ │ │ │ + "relative", null, │ │ │ │ │ + "hidden"); │ │ │ │ │ + this.viewPortDiv.style.width = "100%"; │ │ │ │ │ + this.viewPortDiv.style.height = "100%"; │ │ │ │ │ + this.viewPortDiv.className = "olMapViewport"; │ │ │ │ │ + this.div.appendChild(this.viewPortDiv); │ │ │ │ │ + │ │ │ │ │ + this.events = new OpenLayers.Events( │ │ │ │ │ + this, this.viewPortDiv, null, this.fallThrough, { │ │ │ │ │ + includeXY: true │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + if (OpenLayers.TileManager && this.tileManager !== null) { │ │ │ │ │ + if (!(this.tileManager instanceof OpenLayers.TileManager)) { │ │ │ │ │ + this.tileManager = new OpenLayers.TileManager(this.tileManager); │ │ │ │ │ + } │ │ │ │ │ + this.tileManager.addMap(this); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // the layerContainerDiv is the one that holds all the layers │ │ │ │ │ + id = this.id + "_OpenLayers_Container"; │ │ │ │ │ + this.layerContainerDiv = OpenLayers.Util.createDiv(id); │ │ │ │ │ + this.layerContainerDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] - 1; │ │ │ │ │ + this.layerContainerOriginPx = { │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }; │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ + │ │ │ │ │ + this.viewPortDiv.appendChild(this.layerContainerDiv); │ │ │ │ │ + │ │ │ │ │ + this.updateSize(); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.autoUpdateSize === true) { │ │ │ │ │ + // updateSize on catching the window's resize │ │ │ │ │ + // Note that this is ok, as updateSize() does nothing if the │ │ │ │ │ + // map's size has not actually changed. │ │ │ │ │ + this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize, │ │ │ │ │ + this); │ │ │ │ │ + OpenLayers.Event.observe(window, 'resize', │ │ │ │ │ + this.updateSizeDestroy); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // only append link stylesheet if the theme property is set │ │ │ │ │ + if (this.theme) { │ │ │ │ │ + // check existing links for equivalent url │ │ │ │ │ + var addNode = true; │ │ │ │ │ + var nodes = document.getElementsByTagName('link'); │ │ │ │ │ + for (var i = 0, len = nodes.length; i < len; ++i) { │ │ │ │ │ + if (OpenLayers.Util.isEquivalentUrl(nodes.item(i).href, │ │ │ │ │ + this.theme)) { │ │ │ │ │ + addNode = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // only add a new node if one with an equivalent url hasn't already │ │ │ │ │ + // been added │ │ │ │ │ + if (addNode) { │ │ │ │ │ + var cssNode = document.createElement('link'); │ │ │ │ │ + cssNode.setAttribute('rel', 'stylesheet'); │ │ │ │ │ + cssNode.setAttribute('type', 'text/css'); │ │ │ │ │ + cssNode.setAttribute('href', this.theme); │ │ │ │ │ + document.getElementsByTagName('head')[0].appendChild(cssNode); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.controls == null) { // default controls │ │ │ │ │ + this.controls = []; │ │ │ │ │ + if (OpenLayers.Control != null) { // running full or lite? │ │ │ │ │ + // Navigation or TouchNavigation depending on what is in build │ │ │ │ │ + if (OpenLayers.Control.Navigation) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Navigation()); │ │ │ │ │ + } else if (OpenLayers.Control.TouchNavigation) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.TouchNavigation()); │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.Zoom) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Zoom()); │ │ │ │ │ + } else if (OpenLayers.Control.PanZoom) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.PanZoom()); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (OpenLayers.Control.ArgParser) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.ArgParser()); │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.Attribution) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Attribution()); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - output = 0; │ │ │ │ │ } │ │ │ │ │ - return output; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: chainProcess │ │ │ │ │ - * Sets a fully configured chained process as input for this process. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * input - {Object} The dataInput that the chained process provides. │ │ │ │ │ - * chainLink - {} The process to chain. │ │ │ │ │ - */ │ │ │ │ │ - chainProcess: function(input, chainLink) { │ │ │ │ │ - var output = this.getOutputIndex( │ │ │ │ │ - chainLink.process.description.processOutputs, chainLink.output │ │ │ │ │ - ); │ │ │ │ │ - input.reference.mimeType = this.findMimeType( │ │ │ │ │ - input.complexData.supported.formats, │ │ │ │ │ - chainLink.process.description.processOutputs[output].complexOutput.supported.formats │ │ │ │ │ - ); │ │ │ │ │ - var formats = {}; │ │ │ │ │ - formats[input.reference.mimeType] = true; │ │ │ │ │ - chainLink.process.setResponseForm({ │ │ │ │ │ - outputIndex: output, │ │ │ │ │ - supportedFormats: formats │ │ │ │ │ - }); │ │ │ │ │ - input.reference.body = chainLink.process.description; │ │ │ │ │ - while (this.executeCallbacks.length > 0) { │ │ │ │ │ - this.executeCallbacks[0](); │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + this.addControlToMap(this.controls[i]); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.popups = []; │ │ │ │ │ + │ │ │ │ │ + this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + // always call map.destroy() │ │ │ │ │ + OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); │ │ │ │ │ + │ │ │ │ │ + // add any initial layers │ │ │ │ │ + if (options && options.layers) { │ │ │ │ │ + /** │ │ │ │ │ + * If you have set options.center, the map center property will be │ │ │ │ │ + * set at this point. However, since setCenter has not been called, │ │ │ │ │ + * addLayers gets confused. So we delete the map center in this │ │ │ │ │ + * case. Because the check below uses options.center, it will │ │ │ │ │ + * be properly set below. │ │ │ │ │ + */ │ │ │ │ │ + delete this.center; │ │ │ │ │ + delete this.zoom; │ │ │ │ │ + this.addLayers(options.layers); │ │ │ │ │ + // set center (and optionally zoom) │ │ │ │ │ + if (options.center && !this.getCenter()) { │ │ │ │ │ + // zoom can be undefined here │ │ │ │ │ + this.setCenter(options.center, options.zoom); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.panMethod) { │ │ │ │ │ + this.panTween = new OpenLayers.Tween(this.panMethod); │ │ │ │ │ + } │ │ │ │ │ + if (this.zoomMethod && this.applyTransform.transform) { │ │ │ │ │ + this.zoomTween = new OpenLayers.Tween(this.zoomMethod); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: toFeatures │ │ │ │ │ - * Converts spatial input into features so it can be processed by │ │ │ │ │ - * instances. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {Mixed} An , an │ │ │ │ │ - * , or an array of geometries or features │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getViewport │ │ │ │ │ + * Get the DOMElement representing the view port. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - toFeatures: function(source) { │ │ │ │ │ - var isArray = OpenLayers.Util.isArray(source); │ │ │ │ │ - if (!isArray) { │ │ │ │ │ - source = [source]; │ │ │ │ │ - } │ │ │ │ │ - var target = new Array(source.length), │ │ │ │ │ - current; │ │ │ │ │ - for (var i = 0, ii = source.length; i < ii; ++i) { │ │ │ │ │ - current = source[i]; │ │ │ │ │ - target[i] = current instanceof OpenLayers.Feature.Vector ? │ │ │ │ │ - current : new OpenLayers.Feature.Vector(current); │ │ │ │ │ - } │ │ │ │ │ - return isArray ? target : target[0]; │ │ │ │ │ + getViewport: function() { │ │ │ │ │ + return this.viewPortDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findMimeType │ │ │ │ │ - * Finds a supported mime type. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: render │ │ │ │ │ + * Render the map to a specified container. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * sourceFormats - {Object} An object literal with mime types as key and │ │ │ │ │ - * true as value for supported formats. │ │ │ │ │ - * targetFormats - {Object} Like , but optional to check for │ │ │ │ │ - * supported mime types on a different target than this process. │ │ │ │ │ - * Default is to check against this process's supported formats. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A supported mime type. │ │ │ │ │ + * div - {String|DOMElement} The container that the map should be rendered │ │ │ │ │ + * to. If different than the current container, the map viewport │ │ │ │ │ + * will be moved from the current to the new container. │ │ │ │ │ */ │ │ │ │ │ - findMimeType: function(sourceFormats, targetFormats) { │ │ │ │ │ - targetFormats = targetFormats || this.formats; │ │ │ │ │ - for (var f in sourceFormats) { │ │ │ │ │ - if (f in targetFormats) { │ │ │ │ │ - return f; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + render: function(div) { │ │ │ │ │ + this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ + this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ + this.div.appendChild(this.viewPortDiv); │ │ │ │ │ + this.updateSize(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.WPSProcess" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ - * Type for chaining processes. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.WPSProcess.ChainLink = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Property: process │ │ │ │ │ - * {} The process to chain │ │ │ │ │ + * Method: unloadDestroy │ │ │ │ │ + * Function that is called to destroy the map on page unload. stored here │ │ │ │ │ + * so that if map is manually destroyed, we can unregister this. │ │ │ │ │ */ │ │ │ │ │ - process: null, │ │ │ │ │ + unloadDestroy: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: output │ │ │ │ │ - * {String} The output identifier of the output we are going to use as │ │ │ │ │ - * input for another process. │ │ │ │ │ + * Method: updateSizeDestroy │ │ │ │ │ + * When the map is destroyed, we need to stop listening to updateSize │ │ │ │ │ + * events: this method stores the function we need to unregister in │ │ │ │ │ + * non-IE browsers. │ │ │ │ │ */ │ │ │ │ │ - output: null, │ │ │ │ │ + updateSizeDestroy: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Properties to set on the instance. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this map. │ │ │ │ │ + * Note that if you are using an application which removes a container │ │ │ │ │ + * of the map from the DOM, you need to ensure that you destroy the │ │ │ │ │ + * map *before* this happens; otherwise, the page unload handler │ │ │ │ │ + * will fail because the DOM elements that map.destroy() wants │ │ │ │ │ + * to clean up will be gone. (See │ │ │ │ │ + * http://trac.osgeo.org/openlayers/ticket/2277 for more information). │ │ │ │ │ + * This will apply to GeoExt and also to other applications which │ │ │ │ │ + * modify the DOM of the container of the OpenLayers Map. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.WPSProcess.ChainLink" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Format/OWSCommon/v1_1_0.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * Read WPS DescribeProcess responses. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.0.0 │ │ │ │ │ - */ │ │ │ │ │ - VERSION: "1.0.0", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - wps: "http://www.opengis.net/wps/1.0.0", │ │ │ │ │ - ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ - }, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // if unloadDestroy is null, we've already been destroyed │ │ │ │ │ + if (!this.unloadDestroy) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location │ │ │ │ │ - */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd", │ │ │ │ │ + // make sure panning doesn't continue after destruction │ │ │ │ │ + if (this.panTween) { │ │ │ │ │ + this.panTween.stop(); │ │ │ │ │ + this.panTween = null; │ │ │ │ │ + } │ │ │ │ │ + // make sure zooming doesn't continue after destruction │ │ │ │ │ + if (this.zoomTween) { │ │ │ │ │ + this.zoomTween.stop(); │ │ │ │ │ + this.zoomTween = null; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - */ │ │ │ │ │ - defaultPrefix: "wps", │ │ │ │ │ + // map has been destroyed. dont do it again! │ │ │ │ │ + OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); │ │ │ │ │ + this.unloadDestroy = null; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ - */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ + if (this.updateSizeDestroy) { │ │ │ │ │ + OpenLayers.Event.stopObserving(window, 'resize', │ │ │ │ │ + this.updateSizeDestroy); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ - */ │ │ │ │ │ + this.paddingForPopups = null; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Parse a WPS DescribeProcess and return an object with its information. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + if (this.controls != null) { │ │ │ │ │ + for (var i = this.controls.length - 1; i >= 0; --i) { │ │ │ │ │ + this.controls[i].destroy(); │ │ │ │ │ } │ │ │ │ │ - if (data && data.nodeType == 9) { │ │ │ │ │ - data = data.documentElement; │ │ │ │ │ + this.controls = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.layers != null) { │ │ │ │ │ + for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ + //pass 'false' to destroy so that map wont try to set a new │ │ │ │ │ + // baselayer after each baselayer is removed │ │ │ │ │ + this.layers[i].destroy(false); │ │ │ │ │ } │ │ │ │ │ - var info = {}; │ │ │ │ │ - this.readNode(data, info); │ │ │ │ │ - return info; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: readers │ │ │ │ │ - * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ - * be applied when a namespaced node is found matching the function │ │ │ │ │ - * name. The function will be applied in the scope of this parser │ │ │ │ │ - * with two arguments: the node being read and a context object passed │ │ │ │ │ - * from the parent. │ │ │ │ │ - */ │ │ │ │ │ - readers: { │ │ │ │ │ - "wps": { │ │ │ │ │ - "ProcessDescriptions": function(node, obj) { │ │ │ │ │ - obj.processDescriptions = {}; │ │ │ │ │ - this.readChildNodes(node, obj.processDescriptions); │ │ │ │ │ - }, │ │ │ │ │ - "ProcessDescription": function(node, processDescriptions) { │ │ │ │ │ - var processVersion = this.getAttributeNS(node, this.namespaces.wps, "processVersion"); │ │ │ │ │ - var processDescription = { │ │ │ │ │ - processVersion: processVersion, │ │ │ │ │ - statusSupported: (node.getAttribute("statusSupported") === "true"), │ │ │ │ │ - storeSupported: (node.getAttribute("storeSupported") === "true") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, processDescription); │ │ │ │ │ - processDescriptions[processDescription.identifier] = processDescription; │ │ │ │ │ - }, │ │ │ │ │ - "DataInputs": function(node, processDescription) { │ │ │ │ │ - processDescription.dataInputs = []; │ │ │ │ │ - this.readChildNodes(node, processDescription.dataInputs); │ │ │ │ │ - }, │ │ │ │ │ - "ProcessOutputs": function(node, processDescription) { │ │ │ │ │ - processDescription.processOutputs = []; │ │ │ │ │ - this.readChildNodes(node, processDescription.processOutputs); │ │ │ │ │ - }, │ │ │ │ │ - "Output": function(node, processOutputs) { │ │ │ │ │ - var output = {}; │ │ │ │ │ - this.readChildNodes(node, output); │ │ │ │ │ - processOutputs.push(output); │ │ │ │ │ - }, │ │ │ │ │ - "ComplexOutput": function(node, output) { │ │ │ │ │ - output.complexOutput = {}; │ │ │ │ │ - this.readChildNodes(node, output.complexOutput); │ │ │ │ │ - }, │ │ │ │ │ - "LiteralOutput": function(node, output) { │ │ │ │ │ - output.literalOutput = {}; │ │ │ │ │ - this.readChildNodes(node, output.literalOutput); │ │ │ │ │ - }, │ │ │ │ │ - "Input": function(node, dataInputs) { │ │ │ │ │ - var input = { │ │ │ │ │ - maxOccurs: parseInt(node.getAttribute("maxOccurs")), │ │ │ │ │ - minOccurs: parseInt(node.getAttribute("minOccurs")) │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, input); │ │ │ │ │ - dataInputs.push(input); │ │ │ │ │ - }, │ │ │ │ │ - "BoundingBoxData": function(node, input) { │ │ │ │ │ - input.boundingBoxData = {}; │ │ │ │ │ - this.readChildNodes(node, input.boundingBoxData); │ │ │ │ │ - }, │ │ │ │ │ - "CRS": function(node, obj) { │ │ │ │ │ - if (!obj.CRSs) { │ │ │ │ │ - obj.CRSs = {}; │ │ │ │ │ - } │ │ │ │ │ - obj.CRSs[this.getChildValue(node)] = true; │ │ │ │ │ - }, │ │ │ │ │ - "LiteralData": function(node, input) { │ │ │ │ │ - input.literalData = {}; │ │ │ │ │ - this.readChildNodes(node, input.literalData); │ │ │ │ │ - }, │ │ │ │ │ - "ComplexData": function(node, input) { │ │ │ │ │ - input.complexData = {}; │ │ │ │ │ - this.readChildNodes(node, input.complexData); │ │ │ │ │ - }, │ │ │ │ │ - "Default": function(node, complexData) { │ │ │ │ │ - complexData["default"] = {}; │ │ │ │ │ - this.readChildNodes(node, complexData["default"]); │ │ │ │ │ - }, │ │ │ │ │ - "Supported": function(node, complexData) { │ │ │ │ │ - complexData["supported"] = {}; │ │ │ │ │ - this.readChildNodes(node, complexData["supported"]); │ │ │ │ │ - }, │ │ │ │ │ - "Format": function(node, obj) { │ │ │ │ │ - var format = {}; │ │ │ │ │ - this.readChildNodes(node, format); │ │ │ │ │ - if (!obj.formats) { │ │ │ │ │ - obj.formats = {}; │ │ │ │ │ - } │ │ │ │ │ - obj.formats[format.mimeType] = true; │ │ │ │ │ - }, │ │ │ │ │ - "MimeType": function(node, format) { │ │ │ │ │ - format.mimeType = this.getChildValue(node); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess" │ │ │ │ │ - │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/WPSClient.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + this.layers = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.viewPortDiv && this.viewPortDiv.parentNode) { │ │ │ │ │ + this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ + } │ │ │ │ │ + this.viewPortDiv = null; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ + if (this.tileManager) { │ │ │ │ │ + this.tileManager.removeMap(this); │ │ │ │ │ + this.tileManager = null; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/WPSProcess.js │ │ │ │ │ - * @requires OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - */ │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.WPSClient │ │ │ │ │ - * High level API for interaction with Web Processing Services (WPS). │ │ │ │ │ - * An instance is used to create │ │ │ │ │ - * instances for servers known to the WPSClient. The WPSClient also caches │ │ │ │ │ - * DescribeProcess responses to reduce the number of requests sent to servers │ │ │ │ │ - * when processes are created. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.WPSClient = OpenLayers.Class({ │ │ │ │ │ + this.options = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: servers │ │ │ │ │ - * {Object} Service metadata, keyed by a local identifier. │ │ │ │ │ + * APIMethod: setOptions │ │ │ │ │ + * Change the map options │ │ │ │ │ * │ │ │ │ │ - * Properties: │ │ │ │ │ - * url - {String} the url of the server │ │ │ │ │ - * version - {String} WPS version of the server │ │ │ │ │ - * processDescription - {Object} Cache of raw DescribeProcess │ │ │ │ │ - * responses, keyed by process identifier. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Hashtable of options to tag to the map │ │ │ │ │ */ │ │ │ │ │ - servers: null, │ │ │ │ │ + setOptions: function(options) { │ │ │ │ │ + var updatePxExtent = this.minPx && │ │ │ │ │ + options.restrictedExtent != this.restrictedExtent; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + // force recalculation of minPx and maxPx │ │ │ │ │ + updatePxExtent && this.moveTo(this.getCachedCenter(), this.zoom, { │ │ │ │ │ + forceZoomChange: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} The default WPS version to use if none is configured. Default │ │ │ │ │ - * is '1.0.0'. │ │ │ │ │ + * APIMethod: getTileSize │ │ │ │ │ + * Get the tile size for the map │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - version: '1.0.0', │ │ │ │ │ + getTileSize: function() { │ │ │ │ │ + return this.tileSize; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lazy │ │ │ │ │ - * {Boolean} Should the DescribeProcess be deferred until a process is │ │ │ │ │ - * fully configured? Default is false. │ │ │ │ │ + * APIMethod: getBy │ │ │ │ │ + * Get a list of objects given a property and a match item. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {String} A property on the map whose value is an array. │ │ │ │ │ + * property - {String} A property on each item of the given array. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(map[array][i][property]) evaluates to true, the item will │ │ │ │ │ + * be included in the array returned. If no items are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of items where the given property matches the given │ │ │ │ │ + * criteria. │ │ │ │ │ */ │ │ │ │ │ - lazy: false, │ │ │ │ │ + getBy: function(array, property, match) { │ │ │ │ │ + var test = (typeof match.test == "function"); │ │ │ │ │ + var found = OpenLayers.Array.filter(this[array], function(item) { │ │ │ │ │ + return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ + }); │ │ │ │ │ + return found; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} │ │ │ │ │ + * APIMethod: getLayersBy │ │ │ │ │ + * Get a list of layers with properties matching the given criteria. │ │ │ │ │ * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * describeprocess - Fires when the process description is available. │ │ │ │ │ - * Listeners receive an object with a 'raw' property holding the raw │ │ │ │ │ - * DescribeProcess response, and an 'identifier' property holding the │ │ │ │ │ - * process identifier of the described process. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} A layer property to be matched. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ + * included in the array returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of layers matching the given criteria. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + getLayersBy: function(property, match) { │ │ │ │ │ + return this.getBy("layers", property, match); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.WPSClient │ │ │ │ │ + * APIMethod: getLayersByName │ │ │ │ │ + * Get a list of layers with names matching the given name. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * match - {String | Object} A layer name. The name can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * name.test(layer.name) evaluates to true, the layer will be included │ │ │ │ │ + * in the list of layers returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ * │ │ │ │ │ - * Avaliable options: │ │ │ │ │ - * servers - {Object} Mandatory. Service metadata, keyed by a local │ │ │ │ │ - * identifier. Can either be a string with the service url or an │ │ │ │ │ - * object literal with additional metadata: │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of layers matching the given name. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ + */ │ │ │ │ │ + getLayersByName: function(match) { │ │ │ │ │ + return this.getLayersBy("name", match); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayersByClass │ │ │ │ │ + * Get a list of layers of a given class (CLASS_NAME). │ │ │ │ │ * │ │ │ │ │ - * (code) │ │ │ │ │ - * servers: { │ │ │ │ │ - * local: '/geoserver/wps' │ │ │ │ │ - * }, { │ │ │ │ │ - * opengeo: { │ │ │ │ │ - * url: 'http://demo.opengeo.org/geoserver/wps', │ │ │ │ │ - * version: '1.0.0' │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * match - {String | Object} A layer class name. The match can also be a │ │ │ │ │ + * regular expression literal or object. In addition, it can be any │ │ │ │ │ + * object with a method named test. For reqular expressions or other, │ │ │ │ │ + * if type.test(layer.CLASS_NAME) evaluates to true, the layer will │ │ │ │ │ + * be included in the list of layers returned. If no layers are │ │ │ │ │ + * found, an empty array is returned. │ │ │ │ │ * │ │ │ │ │ - * lazy - {Boolean} Optional. Set to true if DescribeProcess should not be │ │ │ │ │ - * requested until a process is fully configured. Default is false. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of layers matching the given class. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.events = new OpenLayers.Events(this); │ │ │ │ │ - this.servers = {}; │ │ │ │ │ - for (var s in options.servers) { │ │ │ │ │ - this.servers[s] = typeof options.servers[s] == 'string' ? { │ │ │ │ │ - url: options.servers[s], │ │ │ │ │ - version: this.version, │ │ │ │ │ - processDescription: {} │ │ │ │ │ - } : options.servers[s]; │ │ │ │ │ - } │ │ │ │ │ + getLayersByClass: function(match) { │ │ │ │ │ + return this.getLayersBy("CLASS_NAME", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: execute │ │ │ │ │ - * Shortcut to execute a process with a single function call. This is │ │ │ │ │ - * equivalent to using and then calling execute on the │ │ │ │ │ - * process. │ │ │ │ │ + * APIMethod: getControlsBy │ │ │ │ │ + * Get a list of controls with properties matching the given criteria. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Options for the execute operation. │ │ │ │ │ + * property - {String} A control property to be matched. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ + * included in the array returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ * │ │ │ │ │ - * Available options: │ │ │ │ │ - * server - {String} Mandatory. One of the local identifiers of the │ │ │ │ │ - * configured servers. │ │ │ │ │ - * process - {String} Mandatory. A process identifier known to the │ │ │ │ │ - * server. │ │ │ │ │ - * inputs - {Object} The inputs for the process, keyed by input identifier. │ │ │ │ │ - * For spatial data inputs, the value of an input is usually an │ │ │ │ │ - * , an or an array of │ │ │ │ │ - * geometries or features. │ │ │ │ │ - * output - {String} The identifier of an output to parse. Optional. If not │ │ │ │ │ - * provided, the first output will be parsed. │ │ │ │ │ - * success - {Function} Callback to call when the process is complete. │ │ │ │ │ - * This function is called with an outputs object as argument, which │ │ │ │ │ - * will have a property with the identifier of the requested output │ │ │ │ │ - * (e.g. 'result'). For processes that generate spatial output, the │ │ │ │ │ - * value will either be a single or an │ │ │ │ │ - * array of features. │ │ │ │ │ - * scope - {Object} Optional scope for the success callback. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of controls matching the given │ │ │ │ │ + * criteria. An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - execute: function(options) { │ │ │ │ │ - var process = this.getProcess(options.server, options.process); │ │ │ │ │ - process.execute({ │ │ │ │ │ - inputs: options.inputs, │ │ │ │ │ - success: options.success, │ │ │ │ │ - scope: options.scope │ │ │ │ │ - }); │ │ │ │ │ + getControlsBy: function(property, match) { │ │ │ │ │ + return this.getBy("controls", property, match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getProcess │ │ │ │ │ - * Creates an . │ │ │ │ │ + * APIMethod: getControlsByClass │ │ │ │ │ + * Get a list of controls of a given class (CLASS_NAME). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * serverID - {String} Local identifier from the servers that this instance │ │ │ │ │ - * was constructed with. │ │ │ │ │ - * processID - {String} Process identifier known to the server. │ │ │ │ │ + * match - {String | Object} A control class name. The match can also be a │ │ │ │ │ + * regular expression literal or object. In addition, it can be any │ │ │ │ │ + * object with a method named test. For reqular expressions or other, │ │ │ │ │ + * if type.test(control.CLASS_NAME) evaluates to true, the control will │ │ │ │ │ + * be included in the list of controls returned. If no controls are │ │ │ │ │ + * found, an empty array is returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {Array()} A list of controls matching the given class. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - getProcess: function(serverID, processID) { │ │ │ │ │ - var process = new OpenLayers.WPSProcess({ │ │ │ │ │ - client: this, │ │ │ │ │ - server: serverID, │ │ │ │ │ - identifier: processID │ │ │ │ │ - }); │ │ │ │ │ - if (!this.lazy) { │ │ │ │ │ - process.describe(); │ │ │ │ │ - } │ │ │ │ │ - return process; │ │ │ │ │ + getControlsByClass: function(match) { │ │ │ │ │ + return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Layer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Layers to and from the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: describeProcess │ │ │ │ │ + * APIMethod: getLayer │ │ │ │ │ + * Get a layer based on its id │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * serverID - {String} Identifier of the server │ │ │ │ │ - * processID - {String} Identifier of the requested process │ │ │ │ │ - * callback - {Function} Callback to call when the description is available │ │ │ │ │ - * scope - {Object} Optional execution scope for the callback function │ │ │ │ │ + * id - {String} A layer id │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The Layer with the corresponding id from the map's │ │ │ │ │ + * layer collection, or null if not found. │ │ │ │ │ */ │ │ │ │ │ - describeProcess: function(serverID, processID, callback, scope) { │ │ │ │ │ - var server = this.servers[serverID]; │ │ │ │ │ - if (!server.processDescription[processID]) { │ │ │ │ │ - if (!(processID in server.processDescription)) { │ │ │ │ │ - // set to null so we know a describeFeature request is pending │ │ │ │ │ - server.processDescription[processID] = null; │ │ │ │ │ - OpenLayers.Request.GET({ │ │ │ │ │ - url: server.url, │ │ │ │ │ - params: { │ │ │ │ │ - SERVICE: 'WPS', │ │ │ │ │ - VERSION: server.version, │ │ │ │ │ - REQUEST: 'DescribeProcess', │ │ │ │ │ - IDENTIFIER: processID │ │ │ │ │ - }, │ │ │ │ │ - success: function(response) { │ │ │ │ │ - server.processDescription[processID] = response.responseText; │ │ │ │ │ - this.events.triggerEvent('describeprocess', { │ │ │ │ │ - identifier: processID, │ │ │ │ │ - raw: response.responseText │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - // pending request │ │ │ │ │ - this.events.register('describeprocess', this, function describe(evt) { │ │ │ │ │ - if (evt.identifier === processID) { │ │ │ │ │ - this.events.unregister('describeprocess', this, describe); │ │ │ │ │ - callback.call(scope, evt.raw); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ + getLayer: function(id) { │ │ │ │ │ + var foundLayer = null; │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer.id == id) { │ │ │ │ │ + foundLayer = layer; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - window.setTimeout(function() { │ │ │ │ │ - callback.call(scope, server.processDescription[processID]); │ │ │ │ │ - }, 0); │ │ │ │ │ } │ │ │ │ │ + return foundLayer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: setLayerZIndex │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * zIdx - {int} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - this.servers = null; │ │ │ │ │ + setLayerZIndex: function(layer, zIdx) { │ │ │ │ │ + layer.setZIndex( │ │ │ │ │ + this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] + │ │ │ │ │ + zIdx * 5); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ + /** │ │ │ │ │ + * Method: resetLayersZIndex │ │ │ │ │ + * Reset each layer's z-index based on layer's array index │ │ │ │ │ + */ │ │ │ │ │ + resetLayersZIndex: function() { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + this.setLayerZIndex(layer, i); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Tile.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addLayer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the layer has been added to the map. │ │ │ │ │ + */ │ │ │ │ │ + addLayer: function(layer) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + if (this.layers[i] == layer) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.events.triggerEvent("preaddlayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }) === false) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + if (this.allOverlays) { │ │ │ │ │ + layer.isBaseLayer = false; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + layer.div.className = "olLayerDiv"; │ │ │ │ │ + layer.div.style.overflow = ""; │ │ │ │ │ + this.setLayerZIndex(layer, this.layers.length); │ │ │ │ │ │ │ │ │ │ + if (layer.isFixed) { │ │ │ │ │ + this.viewPortDiv.appendChild(layer.div); │ │ │ │ │ + } else { │ │ │ │ │ + this.layerContainerDiv.appendChild(layer.div); │ │ │ │ │ + } │ │ │ │ │ + this.layers.push(layer); │ │ │ │ │ + layer.setMap(this); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ + if (layer.isBaseLayer || (this.allOverlays && !this.baseLayer)) { │ │ │ │ │ + if (this.baseLayer == null) { │ │ │ │ │ + // set the first baselaye we add as the baselayer │ │ │ │ │ + this.setBaseLayer(layer); │ │ │ │ │ + } else { │ │ │ │ │ + layer.setVisibility(false); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + layer.redraw(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Tile │ │ │ │ │ - * This is a class designed to designate a single tile, however │ │ │ │ │ - * it is explicitly designed to do relatively little. Tiles store │ │ │ │ │ - * information about themselves -- such as the URL that they are related │ │ │ │ │ - * to, and their size - but do not add themselves to the layer div │ │ │ │ │ - * automatically, for example. Create a new tile with the │ │ │ │ │ - * constructor, or a subclass. │ │ │ │ │ - * │ │ │ │ │ - * TBD 3.0 - remove reference to url in above paragraph │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Tile = OpenLayers.Class({ │ │ │ │ │ + this.events.triggerEvent("addlayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.events.triggerEvent("added", { │ │ │ │ │ + map: this, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.afterAdd(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the tile. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * tile.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * beforedraw - Triggered before the tile is drawn. Used to defer │ │ │ │ │ - * drawing to an animation queue. To defer drawing, listeners need │ │ │ │ │ - * to return false, which will abort drawing. The queue handler needs │ │ │ │ │ - * to call (true) to actually draw the tile. │ │ │ │ │ - * loadstart - Triggered when tile loading starts. │ │ │ │ │ - * loadend - Triggered when tile loading ends. │ │ │ │ │ - * loaderror - Triggered before the loadend event (i.e. when the tile is │ │ │ │ │ - * still hidden) if the tile could not be loaded. │ │ │ │ │ - * reload - Triggered when an already loading tile is reloaded. │ │ │ │ │ - * unload - Triggered before a tile is unloaded. │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ + * APIMethod: addLayers │ │ │ │ │ * │ │ │ │ │ - * This options can be set in the ``tileOptions`` option from │ │ │ │ │ - * . For example, to be notified of the │ │ │ │ │ - * ``loadend`` event of each tiles: │ │ │ │ │ - * (code) │ │ │ │ │ - * new OpenLayers.Layer.OSM('osm', 'http://tile.openstreetmap.org/${z}/${x}/${y}.png', { │ │ │ │ │ - * tileOptions: { │ │ │ │ │ - * eventListeners: { │ │ │ │ │ - * 'loadend': function(evt) { │ │ │ │ │ - * // do something on loadend │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} null │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layers - {Array()} │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + addLayers: function(layers) { │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + this.addLayer(layers[i]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} layer the tile is attached to │ │ │ │ │ + * APIMethod: removeLayer │ │ │ │ │ + * Removes a layer from the map by removing its visual element (the │ │ │ │ │ + * layer.div property), then removing it from the map's internal list │ │ │ │ │ + * of layers, setting the layer's map property to null. │ │ │ │ │ + * │ │ │ │ │ + * a "removelayer" event is triggered. │ │ │ │ │ + * │ │ │ │ │ + * very worthy of mention is that simply removing a layer from a map │ │ │ │ │ + * will not cause the removal of any popups which may have been created │ │ │ │ │ + * by the layer. this is due to the fact that it was decided at some │ │ │ │ │ + * point that popups would not belong to layers. thus there is no way │ │ │ │ │ + * for us to know here to which layer the popup belongs. │ │ │ │ │ + * │ │ │ │ │ + * A simple solution to this is simply to call destroy() on the layer. │ │ │ │ │ + * the default OpenLayers.Layer class's destroy() function │ │ │ │ │ + * automatically takes care to remove itself from whatever map it has │ │ │ │ │ + * been attached to. │ │ │ │ │ + * │ │ │ │ │ + * The correct solution is for the layer itself to register an │ │ │ │ │ + * event-handler on "removelayer" and when it is called, if it │ │ │ │ │ + * recognizes itself as the layer being removed, then it cycles through │ │ │ │ │ + * its own personal list of popups, removing them from the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * setNewBaseLayer - {Boolean} Default is true │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + removeLayer: function(layer, setNewBaseLayer) { │ │ │ │ │ + if (this.events.triggerEvent("preremovelayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }) === false) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (layer.isFixed) { │ │ │ │ │ + this.viewPortDiv.removeChild(layer.div); │ │ │ │ │ + } else { │ │ │ │ │ + this.layerContainerDiv.removeChild(layer.div); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.removeItem(this.layers, layer); │ │ │ │ │ + layer.removeMap(this); │ │ │ │ │ + layer.map = null; │ │ │ │ │ + │ │ │ │ │ + // if we removed the base layer, need to set a new one │ │ │ │ │ + if (this.baseLayer == layer) { │ │ │ │ │ + this.baseLayer = null; │ │ │ │ │ + if (setNewBaseLayer) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var iLayer = this.layers[i]; │ │ │ │ │ + if (iLayer.isBaseLayer || this.allOverlays) { │ │ │ │ │ + this.setBaseLayer(iLayer); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.resetLayersZIndex(); │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("removelayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.events.triggerEvent("removed", { │ │ │ │ │ + map: this, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} url of the request. │ │ │ │ │ - * │ │ │ │ │ - * TBD 3.0 │ │ │ │ │ - * Deprecated. The base tile class does not need an url. This should be │ │ │ │ │ - * handled in subclasses. Does not belong here. │ │ │ │ │ + * APIMethod: getNumLayers │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Int} The number of layers attached to the map. │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + getNumLayers: function() { │ │ │ │ │ + return this.layers.length; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: bounds │ │ │ │ │ - * {} null │ │ │ │ │ + * APIMethod: getLayerIndex │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The current (zero-based) index of the given layer in the map's │ │ │ │ │ + * layer stack. Returns -1 if the layer isn't on the map. │ │ │ │ │ */ │ │ │ │ │ - bounds: null, │ │ │ │ │ + getLayerIndex: function(layer) { │ │ │ │ │ + return OpenLayers.Util.indexOf(this.layers, layer); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} null │ │ │ │ │ + * APIMethod: setLayerIndex │ │ │ │ │ + * Move the given layer to the specified (zero-based) index in the layer │ │ │ │ │ + * list, changing its z-index in the map display. Use │ │ │ │ │ + * map.getLayerIndex() to find out the current index of a layer. Note │ │ │ │ │ + * that this cannot (or at least should not) be effectively used to │ │ │ │ │ + * raise base layers above overlays. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * idx - {int} │ │ │ │ │ */ │ │ │ │ │ - size: null, │ │ │ │ │ + setLayerIndex: function(layer, idx) { │ │ │ │ │ + var base = this.getLayerIndex(layer); │ │ │ │ │ + if (idx < 0) { │ │ │ │ │ + idx = 0; │ │ │ │ │ + } else if (idx > this.layers.length) { │ │ │ │ │ + idx = this.layers.length; │ │ │ │ │ + } │ │ │ │ │ + if (base != idx) { │ │ │ │ │ + this.layers.splice(base, 1); │ │ │ │ │ + this.layers.splice(idx, 0, layer); │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + this.setLayerZIndex(this.layers[i], i); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: layer, │ │ │ │ │ + property: "order" │ │ │ │ │ + }); │ │ │ │ │ + if (this.allOverlays) { │ │ │ │ │ + if (idx === 0) { │ │ │ │ │ + this.setBaseLayer(layer); │ │ │ │ │ + } else if (this.baseLayer !== this.layers[0]) { │ │ │ │ │ + this.setBaseLayer(this.layers[0]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: position │ │ │ │ │ - * {} Top Left pixel of the tile │ │ │ │ │ - */ │ │ │ │ │ - position: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: isLoading │ │ │ │ │ - * {Boolean} Is the tile loading? │ │ │ │ │ - */ │ │ │ │ │ - isLoading: false, │ │ │ │ │ - │ │ │ │ │ - /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. │ │ │ │ │ - * there is no need for the base tile class to have a url. │ │ │ │ │ + * APIMethod: raiseLayer │ │ │ │ │ + * Change the index of the given layer by delta. If delta is positive, │ │ │ │ │ + * the layer is moved up the map's layer stack; if delta is negative, │ │ │ │ │ + * the layer is moved down. Again, note that this cannot (or at least │ │ │ │ │ + * should not) be effectively used to raise base layers above overlays. │ │ │ │ │ + * │ │ │ │ │ + * Paremeters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * delta - {int} │ │ │ │ │ */ │ │ │ │ │ + raiseLayer: function(layer, delta) { │ │ │ │ │ + var idx = this.getLayerIndex(layer) + delta; │ │ │ │ │ + this.setLayerIndex(layer, idx); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Tile │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ + * APIMethod: setBaseLayer │ │ │ │ │ + * Allows user to specify one of the currently-loaded layers as the Map's │ │ │ │ │ + * new base layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} layer that the tile will go in. │ │ │ │ │ - * position - {} │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * url - {} │ │ │ │ │ - * size - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * newBaseLayer - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.position = position.clone(); │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - this.url = url; │ │ │ │ │ - if (size) { │ │ │ │ │ - this.size = size.clone(); │ │ │ │ │ - } │ │ │ │ │ + setBaseLayer: function(newBaseLayer) { │ │ │ │ │ │ │ │ │ │ - //give the tile a unique id based on its BBOX. │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID("Tile_"); │ │ │ │ │ + if (newBaseLayer != this.baseLayer) { │ │ │ │ │ │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ + // ensure newBaseLayer is already loaded │ │ │ │ │ + if (OpenLayers.Util.indexOf(this.layers, newBaseLayer) != -1) { │ │ │ │ │ │ │ │ │ │ - this.events = new OpenLayers.Events(this); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ + // preserve center and scale when changing base layers │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ + var newResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.getScale(), newBaseLayer.units │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + // make the old base layer invisible │ │ │ │ │ + if (this.baseLayer != null && !this.allOverlays) { │ │ │ │ │ + this.baseLayer.setVisibility(false); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // set new baselayer │ │ │ │ │ + this.baseLayer = newBaseLayer; │ │ │ │ │ + │ │ │ │ │ + if (!this.allOverlays || this.baseLayer.visibility) { │ │ │ │ │ + this.baseLayer.setVisibility(true); │ │ │ │ │ + // Layer may previously have been visible but not in range. │ │ │ │ │ + // In this case we need to redraw it to make it visible. │ │ │ │ │ + if (this.baseLayer.inRange === false) { │ │ │ │ │ + this.baseLayer.redraw(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // recenter the map │ │ │ │ │ + if (center != null) { │ │ │ │ │ + // new zoom level derived from old scale │ │ │ │ │ + var newZoom = this.getZoomForResolution( │ │ │ │ │ + newResolution || this.resolution, true │ │ │ │ │ + ); │ │ │ │ │ + // zoom and force zoom change │ │ │ │ │ + this.setCenter(center, newZoom, false, true); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this.baseLayer │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Control Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Controls to and from the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: unload │ │ │ │ │ - * Call immediately before destroying if you are listening to tile │ │ │ │ │ - * events, so that counters are properly handled if tile is still │ │ │ │ │ - * loading at destroy-time. Will only fire an event if the tile is │ │ │ │ │ - * still loading. │ │ │ │ │ + * APIMethod: addControl │ │ │ │ │ + * Add the passed over control to the map. Optionally │ │ │ │ │ + * position the control at the given pixel. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - unload: function() { │ │ │ │ │ - if (this.isLoading) { │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.events.triggerEvent("unload"); │ │ │ │ │ - } │ │ │ │ │ + addControl: function(control, px) { │ │ │ │ │ + this.controls.push(control); │ │ │ │ │ + this.addControlToMap(control, px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Nullify references to prevent circular references and memory leaks. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addControls │ │ │ │ │ + * Add all of the passed over controls to the map. │ │ │ │ │ + * You can pass over an optional second array │ │ │ │ │ + * with pixel-objects to position the controls. │ │ │ │ │ + * The indices of the two arrays should match and │ │ │ │ │ + * you can add null as pixel for those controls │ │ │ │ │ + * you want to be autopositioned. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * controls - {Array()} │ │ │ │ │ + * pixels - {Array()} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.position = null; │ │ │ │ │ - │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ + addControls: function(controls, pixels) { │ │ │ │ │ + var pxs = (arguments.length === 1) ? [] : pixels; │ │ │ │ │ + for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ + var ctrl = controls[i]; │ │ │ │ │ + var px = (pxs[i]) ? pxs[i] : null; │ │ │ │ │ + this.addControl(ctrl, px); │ │ │ │ │ } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Clear whatever is currently in the tile, then return whether or not │ │ │ │ │ - * it should actually be re-drawn. This is an example implementation │ │ │ │ │ - * that can be overridden by subclasses. The minimum thing to do here │ │ │ │ │ - * is to call and return the result from . │ │ │ │ │ - * │ │ │ │ │ + * Method: addControlToMap │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * force - {Boolean} If true, the tile will not be cleared and no beforedraw │ │ │ │ │ - * event will be fired. This is used for drawing tiles asynchronously │ │ │ │ │ - * after drawing has been cancelled by returning false from a beforedraw │ │ │ │ │ - * listener. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the tile should actually be drawn. Returns null │ │ │ │ │ - * if a beforedraw listener returned false. │ │ │ │ │ + * control - {} │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - draw: function(force) { │ │ │ │ │ - if (!force) { │ │ │ │ │ - //clear tile's contents and mark as not drawn │ │ │ │ │ - this.clear(); │ │ │ │ │ + addControlToMap: function(control, px) { │ │ │ │ │ + // If a control doesn't have a div at this point, it belongs in the │ │ │ │ │ + // viewport. │ │ │ │ │ + control.outsideViewport = (control.div != null); │ │ │ │ │ + │ │ │ │ │ + // If the map has a displayProjection, and the control doesn't, set │ │ │ │ │ + // the display projection. │ │ │ │ │ + if (this.displayProjection && !control.displayProjection) { │ │ │ │ │ + control.displayProjection = this.displayProjection; │ │ │ │ │ } │ │ │ │ │ - var draw = this.shouldDraw(); │ │ │ │ │ - if (draw && !force && this.events.triggerEvent("beforedraw") === false) { │ │ │ │ │ - draw = null; │ │ │ │ │ + │ │ │ │ │ + control.setMap(this); │ │ │ │ │ + var div = control.draw(px); │ │ │ │ │ + if (div) { │ │ │ │ │ + if (!control.outsideViewport) { │ │ │ │ │ + div.style.zIndex = this.Z_INDEX_BASE['Control'] + │ │ │ │ │ + this.controls.length; │ │ │ │ │ + this.viewPortDiv.appendChild(div); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (control.autoActivate) { │ │ │ │ │ + control.activate(); │ │ │ │ │ } │ │ │ │ │ - return draw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shouldDraw │ │ │ │ │ - * Return whether or not the tile should actually be (re-)drawn. The only │ │ │ │ │ - * case where we *wouldn't* want to draw the tile is if the tile is outside │ │ │ │ │ - * its layer's maxExtent │ │ │ │ │ + * APIMethod: getControl │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {String} ID of the control to return. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the tile should actually be drawn. │ │ │ │ │ + * {} The control from the map's list of controls │ │ │ │ │ + * which has a matching 'id'. If none found, │ │ │ │ │ + * returns null. │ │ │ │ │ */ │ │ │ │ │ - shouldDraw: function() { │ │ │ │ │ - var withinMaxExtent = false, │ │ │ │ │ - maxExtent = this.layer.maxExtent; │ │ │ │ │ - if (maxExtent) { │ │ │ │ │ - var map = this.layer.map; │ │ │ │ │ - var worldBounds = map.baseLayer.wrapDateLine && map.getMaxExtent(); │ │ │ │ │ - if (this.bounds.intersectsBounds(maxExtent, { │ │ │ │ │ - inclusive: false, │ │ │ │ │ - worldBounds: worldBounds │ │ │ │ │ - })) { │ │ │ │ │ - withinMaxExtent = true; │ │ │ │ │ + getControl: function(id) { │ │ │ │ │ + var returnControl = null; │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + var control = this.controls[i]; │ │ │ │ │ + if (control.id == id) { │ │ │ │ │ + returnControl = control; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return withinMaxExtent || this.layer.displayOutsideMaxExtent; │ │ │ │ │ + return returnControl; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBounds │ │ │ │ │ - * Sets the bounds on this instance │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removeControl │ │ │ │ │ + * Remove a control from the map. Removes the control both from the map │ │ │ │ │ + * object's internal array of controls, as well as from the map's │ │ │ │ │ + * viewPort (assuming the control was not added outsideViewport) │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds {} │ │ │ │ │ + * control - {} The control to remove. │ │ │ │ │ */ │ │ │ │ │ - setBounds: function(bounds) { │ │ │ │ │ - bounds = bounds.clone(); │ │ │ │ │ - if (this.layer.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var worldExtent = this.layer.map.getMaxExtent(), │ │ │ │ │ - tolerance = this.layer.map.getResolution(); │ │ │ │ │ - bounds = bounds.wrapDateLine(worldExtent, { │ │ │ │ │ - leftTolerance: tolerance, │ │ │ │ │ - rightTolerance: tolerance │ │ │ │ │ - }); │ │ │ │ │ + removeControl: function(control) { │ │ │ │ │ + //make sure control is non-null and actually part of our map │ │ │ │ │ + if ((control) && (control == this.getControl(control.id))) { │ │ │ │ │ + if (control.div && (control.div.parentNode == this.viewPortDiv)) { │ │ │ │ │ + this.viewPortDiv.removeChild(control.div); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.removeItem(this.controls, control); │ │ │ │ │ } │ │ │ │ │ - this.bounds = bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Popup Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Popups to and from the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Reposition the tile. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: addPopup │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * position - {} │ │ │ │ │ - * redraw - {Boolean} Call draw method on tile after moving. │ │ │ │ │ - * Default is true │ │ │ │ │ + * popup - {} │ │ │ │ │ + * exclusive - {Boolean} If true, closes all other popups first │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, position, redraw) { │ │ │ │ │ - if (redraw == null) { │ │ │ │ │ - redraw = true; │ │ │ │ │ + addPopup: function(popup, exclusive) { │ │ │ │ │ + │ │ │ │ │ + if (exclusive) { │ │ │ │ │ + //remove all other popups from screen │ │ │ │ │ + for (var i = this.popups.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removePopup(this.popups[i]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - this.position = position.clone(); │ │ │ │ │ - if (redraw) { │ │ │ │ │ - this.draw(); │ │ │ │ │ + popup.map = this; │ │ │ │ │ + this.popups.push(popup); │ │ │ │ │ + var popupDiv = popup.draw(); │ │ │ │ │ + if (popupDiv) { │ │ │ │ │ + popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + │ │ │ │ │ + this.popups.length; │ │ │ │ │ + this.layerContainerDiv.appendChild(popupDiv); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Clear the tile of any bounds/position-related data so that it can │ │ │ │ │ - * be reused in a new location. │ │ │ │ │ + * APIMethod: removePopup │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * popup - {} │ │ │ │ │ */ │ │ │ │ │ - clear: function(draw) { │ │ │ │ │ - // to be extended by subclasses │ │ │ │ │ + removePopup: function(popup) { │ │ │ │ │ + OpenLayers.Util.removeItem(this.popups, popup); │ │ │ │ │ + if (popup.div) { │ │ │ │ │ + try { │ │ │ │ │ + this.layerContainerDiv.removeChild(popup.div); │ │ │ │ │ + } catch (e) {} // Popups sometimes apparently get disconnected │ │ │ │ │ + // from the layerContainerDiv, and cause complaints. │ │ │ │ │ + } │ │ │ │ │ + popup.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Renderer.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Renderer │ │ │ │ │ - * This is the base class for all renderers. │ │ │ │ │ - * │ │ │ │ │ - * This is based on a merger code written by Paul Spencer and Bertil Chapuis. │ │ │ │ │ - * It is largely composed of virtual functions that are to be implemented │ │ │ │ │ - * in technology-specific subclasses, but there is some generic code too. │ │ │ │ │ - * │ │ │ │ │ - * The functions that *are* implemented here merely deal with the maintenance │ │ │ │ │ - * of the size and extent variables, as well as the cached 'resolution' │ │ │ │ │ - * value. │ │ │ │ │ - * │ │ │ │ │ - * A note to the user that all subclasses should use getResolution() instead │ │ │ │ │ - * of directly accessing this.resolution in order to correctly use the │ │ │ │ │ - * cacheing system. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Renderer = OpenLayers.Class({ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Container Div Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with the access to */ │ │ │ │ │ + /* and maintenance of the size of the container div */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: container │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getSize │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An object that represents the │ │ │ │ │ + * size, in pixels, of the div into which OpenLayers │ │ │ │ │ + * has been loaded. │ │ │ │ │ + * Note - A clone() of this locally cached variable is │ │ │ │ │ + * returned, so as not to allow users to modify it. │ │ │ │ │ */ │ │ │ │ │ - container: null, │ │ │ │ │ + getSize: function() { │ │ │ │ │ + var size = null; │ │ │ │ │ + if (this.size != null) { │ │ │ │ │ + size = this.size.clone(); │ │ │ │ │ + } │ │ │ │ │ + return size; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: root │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIMethod: updateSize │ │ │ │ │ + * This function should be called by any external code which dynamically │ │ │ │ │ + * changes the size of the map div (because mozilla wont let us catch │ │ │ │ │ + * the "onresize" for an element) │ │ │ │ │ */ │ │ │ │ │ - root: null, │ │ │ │ │ + updateSize: function() { │ │ │ │ │ + // the div might have moved on the page, also │ │ │ │ │ + var newSize = this.getCurrentSize(); │ │ │ │ │ + if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) { │ │ │ │ │ + this.events.clearMouseCache(); │ │ │ │ │ + var oldSize = this.getSize(); │ │ │ │ │ + if (oldSize == null) { │ │ │ │ │ + this.size = oldSize = newSize; │ │ │ │ │ + } │ │ │ │ │ + if (!newSize.equals(oldSize)) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: extent │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - extent: null, │ │ │ │ │ + // store the new size │ │ │ │ │ + this.size = newSize; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: locked │ │ │ │ │ - * {Boolean} If the renderer is currently in a state where many things │ │ │ │ │ - * are changing, the 'locked' property is set to true. This means │ │ │ │ │ - * that renderers can expect at least one more drawFeature event to be │ │ │ │ │ - * called with the 'locked' property set to 'true': In some renderers, │ │ │ │ │ - * this might make sense to use as a 'only update local information' │ │ │ │ │ - * flag. │ │ │ │ │ - */ │ │ │ │ │ - locked: false, │ │ │ │ │ + //notify layers of mapresize │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + this.layers[i].onMapResize(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} cache of current map resolution │ │ │ │ │ - */ │ │ │ │ │ - resolution: null, │ │ │ │ │ + if (this.baseLayer != null && center != null) { │ │ │ │ │ + var zoom = this.getZoom(); │ │ │ │ │ + this.zoom = null; │ │ │ │ │ + this.setCenter(center, zoom); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("updatesize"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: featureDx │ │ │ │ │ - * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ - * applied to the current feature while rendering (see │ │ │ │ │ - * ). │ │ │ │ │ + * Method: getCurrentSize │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A new object with the dimensions │ │ │ │ │ + * of the map div │ │ │ │ │ */ │ │ │ │ │ - featureDx: 0, │ │ │ │ │ + getCurrentSize: function() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Renderer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * containerID - {} │ │ │ │ │ - * options - {Object} options for this renderer. See sublcasses for │ │ │ │ │ - * supported options. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(containerID, options) { │ │ │ │ │ - this.container = OpenLayers.Util.getElement(containerID); │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ + var size = new OpenLayers.Size(this.div.clientWidth, │ │ │ │ │ + this.div.clientHeight); │ │ │ │ │ + │ │ │ │ │ + if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ + size.w = this.div.offsetWidth; │ │ │ │ │ + size.h = this.div.offsetHeight; │ │ │ │ │ + } │ │ │ │ │ + if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ + size.w = parseInt(this.div.style.width); │ │ │ │ │ + size.h = parseInt(this.div.style.height); │ │ │ │ │ + } │ │ │ │ │ + return size; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * center - {} Default is this.getCenter() │ │ │ │ │ + * resolution - {float} Default is this.getResolution() │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A bounds based on resolution, center, and │ │ │ │ │ + * current mapsize. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.container = null; │ │ │ │ │ - this.extent = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.resolution = null; │ │ │ │ │ - this.map = null; │ │ │ │ │ + calculateBounds: function(center, resolution) { │ │ │ │ │ + │ │ │ │ │ + var extent = null; │ │ │ │ │ + │ │ │ │ │ + if (center == null) { │ │ │ │ │ + center = this.getCachedCenter(); │ │ │ │ │ + } │ │ │ │ │ + if (resolution == null) { │ │ │ │ │ + resolution = this.getResolution(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if ((center != null) && (resolution != null)) { │ │ │ │ │ + var halfWDeg = (this.size.w * resolution) / 2; │ │ │ │ │ + var halfHDeg = (this.size.h * resolution) / 2; │ │ │ │ │ + │ │ │ │ │ + extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ + center.lat - halfHDeg, │ │ │ │ │ + center.lon + halfWDeg, │ │ │ │ │ + center.lat + halfHDeg); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return extent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Zoom, Center, Pan Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions handle the validation, */ │ │ │ │ │ + /* getting and setting of the Zoom Level and Center */ │ │ │ │ │ + /* as well as the panning of the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: supported │ │ │ │ │ - * This should be overridden by specific subclasses │ │ │ │ │ + * APIMethod: getCenter │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - supported: function() { │ │ │ │ │ - return false; │ │ │ │ │ + getCenter: function() { │ │ │ │ │ + var center = null; │ │ │ │ │ + var cachedCenter = this.getCachedCenter(); │ │ │ │ │ + if (cachedCenter) { │ │ │ │ │ + center = cachedCenter.clone(); │ │ │ │ │ + } │ │ │ │ │ + return center; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setExtent │ │ │ │ │ - * Set the visible part of the layer. │ │ │ │ │ - * │ │ │ │ │ - * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ - * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ - * next it is needed. │ │ │ │ │ - * We nullify the resolution cache (this.resolution) if resolutionChanged │ │ │ │ │ - * is set to true - this way it will be re-computed on the next │ │ │ │ │ - * getResolution() request. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * extent - {} │ │ │ │ │ - * resolutionChanged - {Boolean} │ │ │ │ │ + * Method: getCachedCenter │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} true to notify the layer that the new extent does not exceed │ │ │ │ │ - * the coordinate range, and the features will not need to be redrawn. │ │ │ │ │ - * False otherwise. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - setExtent: function(extent, resolutionChanged) { │ │ │ │ │ - this.extent = extent.clone(); │ │ │ │ │ - if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var ratio = extent.getWidth() / this.map.getExtent().getWidth(), │ │ │ │ │ - extent = extent.scale(1 / ratio); │ │ │ │ │ - this.extent = extent.wrapDateLine(this.map.getMaxExtent()).scale(ratio); │ │ │ │ │ - } │ │ │ │ │ - if (resolutionChanged) { │ │ │ │ │ - this.resolution = null; │ │ │ │ │ + getCachedCenter: function() { │ │ │ │ │ + if (!this.center && this.size) { │ │ │ │ │ + this.center = this.getLonLatFromViewPortPx({ │ │ │ │ │ + x: this.size.w / 2, │ │ │ │ │ + y: this.size.h / 2 │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return this.center; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * Sets the size of the drawing surface. │ │ │ │ │ + * APIMethod: getZoom │ │ │ │ │ * │ │ │ │ │ - * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ - * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ - * next it is needed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} │ │ │ │ │ */ │ │ │ │ │ - setSize: function(size) { │ │ │ │ │ - this.size = size.clone(); │ │ │ │ │ - this.resolution = null; │ │ │ │ │ + getZoom: function() { │ │ │ │ │ + return this.zoom; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getResolution │ │ │ │ │ - * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ + * APIMethod: pan │ │ │ │ │ + * Allows user to pan by a value of screen pixels │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The current map's resolution │ │ │ │ │ - */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ - return this.resolution; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Draw the feature. The optional style argument can be used │ │ │ │ │ - * to override the feature's own style. This method should only │ │ │ │ │ - * be called from layer.drawFeature(). │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * style - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ - * undefined if the feature had no geometry │ │ │ │ │ + * dx - {Integer} │ │ │ │ │ + * dy - {Integer} │ │ │ │ │ + * options - {Object} Options to configure panning: │ │ │ │ │ + * - *animate* {Boolean} Use panTo instead of setCenter. Default is true. │ │ │ │ │ + * - *dragging* {Boolean} Call setCenter with dragging true. Default is │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function(feature, style) { │ │ │ │ │ - if (style == null) { │ │ │ │ │ - style = feature.style; │ │ │ │ │ - } │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - var bounds = feature.geometry.getBounds(); │ │ │ │ │ - if (bounds) { │ │ │ │ │ - var worldBounds; │ │ │ │ │ - if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ - worldBounds = this.map.getMaxExtent(); │ │ │ │ │ - } │ │ │ │ │ - if (!bounds.intersectsBounds(this.extent, { │ │ │ │ │ - worldBounds: worldBounds │ │ │ │ │ - })) { │ │ │ │ │ - style = { │ │ │ │ │ - display: "none" │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - this.calculateFeatureDx(bounds, worldBounds); │ │ │ │ │ - } │ │ │ │ │ - var rendered = this.drawGeometry(feature.geometry, style, feature.id); │ │ │ │ │ - if (style.display != "none" && style.label && rendered !== false) { │ │ │ │ │ + pan: function(dx, dy, options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ + animate: true, │ │ │ │ │ + dragging: false │ │ │ │ │ + }); │ │ │ │ │ + if (options.dragging) { │ │ │ │ │ + if (dx != 0 || dy != 0) { │ │ │ │ │ + this.moveByPx(dx, dy); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // getCenter │ │ │ │ │ + var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter()); │ │ │ │ │ │ │ │ │ │ - var location = feature.geometry.getCentroid(); │ │ │ │ │ - if (style.labelXOffset || style.labelYOffset) { │ │ │ │ │ - var xOffset = isNaN(style.labelXOffset) ? 0 : style.labelXOffset; │ │ │ │ │ - var yOffset = isNaN(style.labelYOffset) ? 0 : style.labelYOffset; │ │ │ │ │ - var res = this.getResolution(); │ │ │ │ │ - location.move(xOffset * res, yOffset * res); │ │ │ │ │ - } │ │ │ │ │ - this.drawText(feature.id, style, location); │ │ │ │ │ + // adjust │ │ │ │ │ + var newCenterPx = centerPx.add(dx, dy); │ │ │ │ │ + │ │ │ │ │ + if (this.dragging || !newCenterPx.equals(centerPx)) { │ │ │ │ │ + var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); │ │ │ │ │ + if (options.animate) { │ │ │ │ │ + this.panTo(newCenterLonLat); │ │ │ │ │ } else { │ │ │ │ │ - this.removeText(feature.id); │ │ │ │ │ + this.moveTo(newCenterLonLat); │ │ │ │ │ + if (this.dragging) { │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.events.triggerEvent("moveend"); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return rendered; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateFeatureDx │ │ │ │ │ - * {Number} Calculates the feature offset in x direction. Looking at the │ │ │ │ │ - * center of the feature bounds and the renderer extent, we calculate how │ │ │ │ │ - * many world widths the two are away from each other. This distance is │ │ │ │ │ - * used to shift the feature as close as possible to the center of the │ │ │ │ │ - * current enderer extent, which ensures that the feature is visible in the │ │ │ │ │ - * current viewport. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} Bounds of the feature │ │ │ │ │ - * worldBounds - {} Bounds of the world │ │ │ │ │ - */ │ │ │ │ │ - calculateFeatureDx: function(bounds, worldBounds) { │ │ │ │ │ - this.featureDx = 0; │ │ │ │ │ - if (worldBounds) { │ │ │ │ │ - var worldWidth = worldBounds.getWidth(), │ │ │ │ │ - rendererCenterX = (this.extent.left + this.extent.right) / 2, │ │ │ │ │ - featureCenterX = (bounds.left + bounds.right) / 2, │ │ │ │ │ - worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth); │ │ │ │ │ - this.featureDx = worldsAway * worldWidth; │ │ │ │ │ - } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawGeometry │ │ │ │ │ + * APIMethod: panTo │ │ │ │ │ + * Allows user to pan to a new lonlat │ │ │ │ │ + * If the new lonlat is in the current extent the map will slide smoothly │ │ │ │ │ * │ │ │ │ │ - * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ - * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ - * virtual function │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * style - {Object} │ │ │ │ │ - * featureId - {} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ */ │ │ │ │ │ - drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ + panTo: function(lonlat) { │ │ │ │ │ + if (this.panTween && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawText │ │ │ │ │ - * Function for drawing text labels. │ │ │ │ │ - * This method is only called by the renderer itself. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featureId - {String} │ │ │ │ │ - * style - │ │ │ │ │ - * location - {} │ │ │ │ │ - */ │ │ │ │ │ - drawText: function(featureId, style, location) {}, │ │ │ │ │ + // center will not change, don't do nothing │ │ │ │ │ + if (lonlat.equals(center)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeText │ │ │ │ │ - * Function for removing text labels. │ │ │ │ │ - * This method is only called by the renderer itself. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featureId - {String} │ │ │ │ │ - */ │ │ │ │ │ - removeText: function(featureId) {}, │ │ │ │ │ + var from = this.getPixelFromLonLat(center); │ │ │ │ │ + var to = this.getPixelFromLonLat(lonlat); │ │ │ │ │ + var vector = { │ │ │ │ │ + x: to.x - from.x, │ │ │ │ │ + y: to.y - from.y │ │ │ │ │ + }; │ │ │ │ │ + var last = { │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Clear all vectors from the renderer. │ │ │ │ │ - * virtual function. │ │ │ │ │ - */ │ │ │ │ │ - clear: function() {}, │ │ │ │ │ + this.panTween.start({ │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }, vector, this.panDuration, { │ │ │ │ │ + callbacks: { │ │ │ │ │ + eachStep: OpenLayers.Function.bind(function(px) { │ │ │ │ │ + var x = px.x - last.x, │ │ │ │ │ + y = px.y - last.y; │ │ │ │ │ + this.moveByPx(x, y); │ │ │ │ │ + last.x = Math.round(px.x); │ │ │ │ │ + last.y = Math.round(px.y); │ │ │ │ │ + }, this), │ │ │ │ │ + done: OpenLayers.Function.bind(function(px) { │ │ │ │ │ + this.moveTo(lonlat); │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.events.triggerEvent("moveend"); │ │ │ │ │ + }, this) │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + this.setCenter(lonlat); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureIdFromEvent │ │ │ │ │ - * Returns a feature id from an event on the renderer. │ │ │ │ │ - * How this happens is specific to the renderer. This should be │ │ │ │ │ - * called from layer.getFeatureFromEvent(). │ │ │ │ │ - * Virtual function. │ │ │ │ │ + * APIMethod: setCenter │ │ │ │ │ + * Set the map center (and optionally, the zoom level). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * lonlat - {|Array} The new center location. │ │ │ │ │ + * If provided as array, the first value is the x coordinate, │ │ │ │ │ + * and the 2nd value is the y coordinate. │ │ │ │ │ + * zoom - {Integer} Optional zoom level. │ │ │ │ │ + * dragging - {Boolean} Specifies whether or not to trigger │ │ │ │ │ + * movestart/end events │ │ │ │ │ + * forceZoomChange - {Boolean} Specifies whether or not to trigger zoom │ │ │ │ │ + * change events (needed on baseLayer change) │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A feature id or undefined. │ │ │ │ │ - */ │ │ │ │ │ - getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: eraseFeatures │ │ │ │ │ - * This is called by the layer to erase features │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ + * TBD: reconsider forceZoomChange in 3.0 │ │ │ │ │ */ │ │ │ │ │ - eraseFeatures: function(features) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ + setCenter: function(lonlat, zoom, dragging, forceZoomChange) { │ │ │ │ │ + if (this.panTween) { │ │ │ │ │ + this.panTween.stop(); │ │ │ │ │ } │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - var feature = features[i]; │ │ │ │ │ - this.eraseGeometry(feature.geometry, feature.id); │ │ │ │ │ - this.removeText(feature.id); │ │ │ │ │ + if (this.zoomTween) { │ │ │ │ │ + this.zoomTween.stop(); │ │ │ │ │ } │ │ │ │ │ + this.moveTo(lonlat, zoom, { │ │ │ │ │ + 'dragging': dragging, │ │ │ │ │ + 'forceZoomChange': forceZoomChange │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: eraseGeometry │ │ │ │ │ - * Remove a geometry from the renderer (by id). │ │ │ │ │ - * virtual function. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Drag the map by pixels. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * featureId - {String} │ │ │ │ │ + * dx - {Number} │ │ │ │ │ + * dy - {Number} │ │ │ │ │ */ │ │ │ │ │ - eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ + moveByPx: function(dx, dy) { │ │ │ │ │ + var hw = this.size.w / 2; │ │ │ │ │ + var hh = this.size.h / 2; │ │ │ │ │ + var x = hw + dx; │ │ │ │ │ + var y = hh + dy; │ │ │ │ │ + var wrapDateLine = this.baseLayer.wrapDateLine; │ │ │ │ │ + var xRestriction = 0; │ │ │ │ │ + var yRestriction = 0; │ │ │ │ │ + if (this.restrictedExtent) { │ │ │ │ │ + xRestriction = hw; │ │ │ │ │ + yRestriction = hh; │ │ │ │ │ + // wrapping the date line makes no sense for restricted extents │ │ │ │ │ + wrapDateLine = false; │ │ │ │ │ + } │ │ │ │ │ + dx = wrapDateLine || │ │ │ │ │ + x <= this.maxPx.x - xRestriction && │ │ │ │ │ + x >= this.minPx.x + xRestriction ? Math.round(dx) : 0; │ │ │ │ │ + dy = y <= this.maxPx.y - yRestriction && │ │ │ │ │ + y >= this.minPx.y + yRestriction ? Math.round(dy) : 0; │ │ │ │ │ + if (dx || dy) { │ │ │ │ │ + if (!this.dragging) { │ │ │ │ │ + this.dragging = true; │ │ │ │ │ + this.events.triggerEvent("movestart"); │ │ │ │ │ + } │ │ │ │ │ + this.center = null; │ │ │ │ │ + if (dx) { │ │ │ │ │ + this.layerContainerOriginPx.x -= dx; │ │ │ │ │ + this.minPx.x -= dx; │ │ │ │ │ + this.maxPx.x -= dx; │ │ │ │ │ + } │ │ │ │ │ + if (dy) { │ │ │ │ │ + this.layerContainerOriginPx.y -= dy; │ │ │ │ │ + this.minPx.y -= dy; │ │ │ │ │ + this.maxPx.y -= dy; │ │ │ │ │ + } │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ + var layer, i, len; │ │ │ │ │ + for (i = 0, len = this.layers.length; i < len; ++i) { │ │ │ │ │ + layer = this.layers[i]; │ │ │ │ │ + if (layer.visibility && │ │ │ │ │ + (layer === this.baseLayer || layer.inRange)) { │ │ │ │ │ + layer.moveByPx(dx, dy); │ │ │ │ │ + layer.events.triggerEvent("move"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("move"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveRoot │ │ │ │ │ - * moves this renderer's root to a (different) renderer. │ │ │ │ │ - * To be implemented by subclasses that require a common renderer root for │ │ │ │ │ - * feature selection. │ │ │ │ │ - * │ │ │ │ │ + * Method: adjustZoom │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * renderer - {} target renderer for the moved root │ │ │ │ │ + * zoom - {Number} The zoom level to adjust │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} Adjusted zoom level that shows a map not wider than its │ │ │ │ │ + * 's maxExtent. │ │ │ │ │ */ │ │ │ │ │ - moveRoot: function(renderer) {}, │ │ │ │ │ + adjustZoom: function(zoom) { │ │ │ │ │ + if (this.baseLayer && this.baseLayer.wrapDateLine) { │ │ │ │ │ + var resolution, resolutions = this.baseLayer.resolutions, │ │ │ │ │ + maxResolution = this.getMaxExtent().getWidth() / this.size.w; │ │ │ │ │ + if (this.getResolutionForZoom(zoom) > maxResolution) { │ │ │ │ │ + if (this.fractionalZoom) { │ │ │ │ │ + zoom = this.getZoomForResolution(maxResolution); │ │ │ │ │ + } else { │ │ │ │ │ + for (var i = zoom | 0, ii = resolutions.length; i < ii; ++i) { │ │ │ │ │ + if (resolutions[i] <= maxResolution) { │ │ │ │ │ + zoom = i; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getRenderLayerId │ │ │ │ │ - * Gets the layer that this renderer's output appears on. If moveRoot was │ │ │ │ │ - * used, this will be different from the id of the layer containing the │ │ │ │ │ - * features rendered by this renderer. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getMinZoom │ │ │ │ │ + * Returns the minimum zoom level for the current map view. If the base │ │ │ │ │ + * layer is configured with set to true, this will be the │ │ │ │ │ + * first zoom level that shows no more than one world width in the current │ │ │ │ │ + * map viewport. Components that rely on this value (e.g. zoom sliders) │ │ │ │ │ + * should also listen to the map's "updatesize" event and call this method │ │ │ │ │ + * in the "updatesize" listener. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} the id of the output layer. │ │ │ │ │ + * {Number} Minimum zoom level that shows a map not wider than its │ │ │ │ │ + * 's maxExtent. This is an Integer value, unless the map is │ │ │ │ │ + * configured with set to true. │ │ │ │ │ */ │ │ │ │ │ - getRenderLayerId: function() { │ │ │ │ │ - return this.container.id; │ │ │ │ │ + getMinZoom: function() { │ │ │ │ │ + return this.adjustZoom(0); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: applyDefaultSymbolizer │ │ │ │ │ - * │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * symbolizer - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * zoom - {Integer} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - applyDefaultSymbolizer: function(symbolizer) { │ │ │ │ │ - var result = OpenLayers.Util.extend({}, │ │ │ │ │ - OpenLayers.Renderer.defaultSymbolizer); │ │ │ │ │ - if (symbolizer.stroke === false) { │ │ │ │ │ - delete result.strokeWidth; │ │ │ │ │ - delete result.strokeColor; │ │ │ │ │ + moveTo: function(lonlat, zoom, options) { │ │ │ │ │ + if (lonlat != null && !(lonlat instanceof OpenLayers.LonLat)) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lonlat); │ │ │ │ │ } │ │ │ │ │ - if (symbolizer.fill === false) { │ │ │ │ │ - delete result.fillColor; │ │ │ │ │ + if (!options) { │ │ │ │ │ + options = {}; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Util.extend(result, symbolizer); │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ + if (zoom != null) { │ │ │ │ │ + zoom = parseFloat(zoom); │ │ │ │ │ + if (!this.fractionalZoom) { │ │ │ │ │ + zoom = Math.round(zoom); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var requestedZoom = zoom; │ │ │ │ │ + zoom = this.adjustZoom(zoom); │ │ │ │ │ + if (zoom !== requestedZoom) { │ │ │ │ │ + // zoom was adjusted, so keep old lonlat to avoid panning │ │ │ │ │ + lonlat = this.getCenter(); │ │ │ │ │ + } │ │ │ │ │ + // dragging is false by default │ │ │ │ │ + var dragging = options.dragging || this.dragging; │ │ │ │ │ + // forceZoomChange is false by default │ │ │ │ │ + var forceZoomChange = options.forceZoomChange; │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Renderer" │ │ │ │ │ -}); │ │ │ │ │ + if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) { │ │ │ │ │ + lonlat = this.maxExtent.getCenterLonLat(); │ │ │ │ │ + this.center = lonlat.clone(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Renderer.defaultSymbolizer │ │ │ │ │ - * {Object} Properties from this symbolizer will be applied to symbolizers │ │ │ │ │ - * with missing properties. This can also be used to set a global │ │ │ │ │ - * symbolizer default in OpenLayers. To be SLD 1.x compliant, add the │ │ │ │ │ - * following code before rendering any vector features: │ │ │ │ │ - * (code) │ │ │ │ │ - * OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ - * fillColor: "#808080", │ │ │ │ │ - * fillOpacity: 1, │ │ │ │ │ - * strokeColor: "#000000", │ │ │ │ │ - * strokeOpacity: 1, │ │ │ │ │ - * strokeWidth: 1, │ │ │ │ │ - * pointRadius: 3, │ │ │ │ │ - * graphicName: "square" │ │ │ │ │ - * }; │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ - fillColor: "#000000", │ │ │ │ │ - strokeColor: "#000000", │ │ │ │ │ - strokeWidth: 2, │ │ │ │ │ - fillOpacity: 1, │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - pointRadius: 0, │ │ │ │ │ - labelAlign: 'cm' │ │ │ │ │ -}; │ │ │ │ │ + if (this.restrictedExtent != null) { │ │ │ │ │ + // In 3.0, decide if we want to change interpretation of maxExtent. │ │ │ │ │ + if (lonlat == null) { │ │ │ │ │ + lonlat = this.center; │ │ │ │ │ + } │ │ │ │ │ + if (zoom == null) { │ │ │ │ │ + zoom = this.getZoom(); │ │ │ │ │ + } │ │ │ │ │ + var resolution = this.getResolutionForZoom(zoom); │ │ │ │ │ + var extent = this.calculateBounds(lonlat, resolution); │ │ │ │ │ + if (!this.restrictedExtent.containsBounds(extent)) { │ │ │ │ │ + var maxCenter = this.restrictedExtent.getCenterLonLat(); │ │ │ │ │ + if (extent.getWidth() > this.restrictedExtent.getWidth()) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(maxCenter.lon, lonlat.lat); │ │ │ │ │ + } else if (extent.left < this.restrictedExtent.left) { │ │ │ │ │ + lonlat = lonlat.add(this.restrictedExtent.left - │ │ │ │ │ + extent.left, 0); │ │ │ │ │ + } else if (extent.right > this.restrictedExtent.right) { │ │ │ │ │ + lonlat = lonlat.add(this.restrictedExtent.right - │ │ │ │ │ + extent.right, 0); │ │ │ │ │ + } │ │ │ │ │ + if (extent.getHeight() > this.restrictedExtent.getHeight()) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lonlat.lon, maxCenter.lat); │ │ │ │ │ + } else if (extent.bottom < this.restrictedExtent.bottom) { │ │ │ │ │ + lonlat = lonlat.add(0, this.restrictedExtent.bottom - │ │ │ │ │ + extent.bottom); │ │ │ │ │ + } else if (extent.top > this.restrictedExtent.top) { │ │ │ │ │ + lonlat = lonlat.add(0, this.restrictedExtent.top - │ │ │ │ │ + extent.top); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ + var zoomChanged = forceZoomChange || ( │ │ │ │ │ + (this.isValidZoomLevel(zoom)) && │ │ │ │ │ + (zoom != this.getZoom())); │ │ │ │ │ │ │ │ │ │ + var centerChanged = (this.isValidLonLat(lonlat)) && │ │ │ │ │ + (!lonlat.equals(this.center)); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Renderer.symbol │ │ │ │ │ - * Coordinate arrays for well known (named) symbols. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Renderer.symbol = { │ │ │ │ │ - "star": [350, 75, 379, 161, 469, 161, 397, 215, 423, 301, 350, 250, 277, 301, │ │ │ │ │ - 303, 215, 231, 161, 321, 161, 350, 75 │ │ │ │ │ - ], │ │ │ │ │ - "cross": [4, 0, 6, 0, 6, 4, 10, 4, 10, 6, 6, 6, 6, 10, 4, 10, 4, 6, 0, 6, 0, 4, 4, 4, │ │ │ │ │ - 4, 0 │ │ │ │ │ - ], │ │ │ │ │ - "x": [0, 0, 25, 0, 50, 35, 75, 0, 100, 0, 65, 50, 100, 100, 75, 100, 50, 65, 25, 100, 0, 100, 35, 50, 0, 0], │ │ │ │ │ - "square": [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], │ │ │ │ │ - "triangle": [0, 10, 10, 10, 5, 0, 0, 10] │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + // if neither center nor zoom will change, no need to do anything │ │ │ │ │ + if (zoomChanged || centerChanged || dragging) { │ │ │ │ │ + dragging || this.events.triggerEvent("movestart", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + if (centerChanged) { │ │ │ │ │ + if (!zoomChanged && this.center) { │ │ │ │ │ + // if zoom hasnt changed, just slide layerContainer │ │ │ │ │ + // (must be done before setting this.center to new value) │ │ │ │ │ + this.centerLayerContainer(lonlat); │ │ │ │ │ + } │ │ │ │ │ + this.center = lonlat.clone(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ + var res = zoomChanged ? │ │ │ │ │ + this.getResolutionForZoom(zoom) : this.getResolution(); │ │ │ │ │ + // (re)set the layerContainerDiv's location │ │ │ │ │ + if (zoomChanged || this.layerContainerOrigin == null) { │ │ │ │ │ + this.layerContainerOrigin = this.getCachedCenter(); │ │ │ │ │ + this.layerContainerOriginPx.x = 0; │ │ │ │ │ + this.layerContainerOriginPx.y = 0; │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ + var maxExtent = this.getMaxExtent({ │ │ │ │ │ + restricted: true │ │ │ │ │ + }); │ │ │ │ │ + var maxExtentCenter = maxExtent.getCenterLonLat(); │ │ │ │ │ + var lonDelta = this.center.lon - maxExtentCenter.lon; │ │ │ │ │ + var latDelta = maxExtentCenter.lat - this.center.lat; │ │ │ │ │ + var extentWidth = Math.round(maxExtent.getWidth() / res); │ │ │ │ │ + var extentHeight = Math.round(maxExtent.getHeight() / res); │ │ │ │ │ + this.minPx = { │ │ │ │ │ + x: (this.size.w - extentWidth) / 2 - lonDelta / res, │ │ │ │ │ + y: (this.size.h - extentHeight) / 2 - latDelta / res │ │ │ │ │ + }; │ │ │ │ │ + this.maxPx = { │ │ │ │ │ + x: this.minPx.x + Math.round(maxExtent.getWidth() / res), │ │ │ │ │ + y: this.minPx.y + Math.round(maxExtent.getHeight() / res) │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Layer.js │ │ │ │ │ - */ │ │ │ │ │ + if (zoomChanged) { │ │ │ │ │ + this.zoom = zoom; │ │ │ │ │ + this.resolution = res; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ + var bounds = this.getExtent(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: URL_HASH_FACTOR │ │ │ │ │ - * {Float} Used to hash URL param strings for multi-WMS server selection. │ │ │ │ │ - * Set to the Golden Ratio per Knuth's recommendation. │ │ │ │ │ - */ │ │ │ │ │ - URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ + //send the move call to the baselayer and all the overlays │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ - * a single url string. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ + if (this.baseLayer.visibility) { │ │ │ │ │ + this.baseLayer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ + options.dragging || this.baseLayer.events.triggerEvent( │ │ │ │ │ + "moveend", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: params │ │ │ │ │ - * {Object} Hashtable of key/value parameters │ │ │ │ │ - */ │ │ │ │ │ - params: null, │ │ │ │ │ + bounds = this.baseLayer.getExtent(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: reproject │ │ │ │ │ - * *Deprecated*. See http://docs.openlayers.org/library/spherical_mercator.html │ │ │ │ │ - * for information on the replacement for this functionality. │ │ │ │ │ - * {Boolean} Whether layer should reproject itself based on base layer │ │ │ │ │ - * locations. This allows reprojection onto commercial layers. │ │ │ │ │ - * Default is false: Most layers can't reproject, but layers │ │ │ │ │ - * which can create non-square geographic pixels can, like WMS. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - reproject: false, │ │ │ │ │ + for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer !== this.baseLayer && !layer.isBaseLayer) { │ │ │ │ │ + var inRange = layer.calculateInRange(); │ │ │ │ │ + if (layer.inRange != inRange) { │ │ │ │ │ + // the inRange property has changed. If the layer is │ │ │ │ │ + // no longer in range, we turn it off right away. If │ │ │ │ │ + // the layer is no longer out of range, the moveTo │ │ │ │ │ + // call below will turn on the layer. │ │ │ │ │ + layer.inRange = inRange; │ │ │ │ │ + if (!inRange) { │ │ │ │ │ + layer.display(false); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: layer, │ │ │ │ │ + property: "visibility" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (inRange && layer.visibility) { │ │ │ │ │ + layer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ + options.dragging || layer.events.triggerEvent( │ │ │ │ │ + "moveend", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + this.events.triggerEvent("move"); │ │ │ │ │ + dragging || this.events.triggerEvent("moveend"); │ │ │ │ │ + │ │ │ │ │ + if (zoomChanged) { │ │ │ │ │ + //redraw popups │ │ │ │ │ + for (var i = 0, len = this.popups.length; i < len; i++) { │ │ │ │ │ + this.popups[i].updatePosition(); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("zoomend"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: centerLayerContainer │ │ │ │ │ + * This function takes care to recenter the layerContainerDiv. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {Array(String) or String} │ │ │ │ │ - * params - {Object} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * lonlat - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); │ │ │ │ │ - this.url = url; │ │ │ │ │ - if (!this.params) { │ │ │ │ │ - this.params = OpenLayers.Util.extend({}, params); │ │ │ │ │ + centerLayerContainer: function(lonlat) { │ │ │ │ │ + var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin); │ │ │ │ │ + var newPx = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + │ │ │ │ │ + if ((originPx != null) && (newPx != null)) { │ │ │ │ │ + var oldLeft = this.layerContainerOriginPx.x; │ │ │ │ │ + var oldTop = this.layerContainerOriginPx.y; │ │ │ │ │ + var newLeft = Math.round(originPx.x - newPx.x); │ │ │ │ │ + var newTop = Math.round(originPx.y - newPx.y); │ │ │ │ │ + this.applyTransform( │ │ │ │ │ + (this.layerContainerOriginPx.x = newLeft), │ │ │ │ │ + (this.layerContainerOriginPx.y = newTop)); │ │ │ │ │ + var dx = oldLeft - newLeft; │ │ │ │ │ + var dy = oldTop - newTop; │ │ │ │ │ + this.minPx.x -= dx; │ │ │ │ │ + this.maxPx.x -= dx; │ │ │ │ │ + this.minPx.y -= dy; │ │ │ │ │ + this.maxPx.y -= dy; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: isValidZoomLevel │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoomLevel - {Integer} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the zoom level passed in is non-null and │ │ │ │ │ + * within the min/max range of zoom levels. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.url = null; │ │ │ │ │ - this.params = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ + isValidZoomLevel: function(zoomLevel) { │ │ │ │ │ + return ((zoomLevel != null) && │ │ │ │ │ + (zoomLevel >= 0) && │ │ │ │ │ + (zoomLevel < this.getNumZoomLevels())); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ + * Method: isValidLonLat │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - * │ │ │ │ │ + * {Boolean} Whether or not the lonlat passed in is non-null and within │ │ │ │ │ + * the maxExtent bounds │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.HTTPRequest(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + isValidLonLat: function(lonlat) { │ │ │ │ │ + var valid = false; │ │ │ │ │ + if (lonlat != null) { │ │ │ │ │ + var maxExtent = this.getMaxExtent(); │ │ │ │ │ + var worldBounds = this.baseLayer.wrapDateLine && maxExtent; │ │ │ │ │ + valid = maxExtent.containsLonLat(lonlat, { │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + return valid; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setUrl │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Layer Options */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Accessor functions to Layer Options parameters */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getProjection │ │ │ │ │ + * This method returns a string representing the projection. In │ │ │ │ │ + * the case of projection support, this will be the srsCode which │ │ │ │ │ + * is loaded -- otherwise it will simply be the string value that │ │ │ │ │ + * was passed to the projection at startup. │ │ │ │ │ + * │ │ │ │ │ + * FIXME: In 3.0, we will remove getProjectionObject, and instead │ │ │ │ │ + * return a Projection object from this function. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newUrl - {String} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The Projection string from the base layer or null. │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(newUrl) { │ │ │ │ │ - this.url = newUrl; │ │ │ │ │ + getProjection: function() { │ │ │ │ │ + var projection = this.getProjectionObject(); │ │ │ │ │ + return projection ? projection.getCode() : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ + * APIMethod: getProjectionObject │ │ │ │ │ + * Returns the projection obect from the baselayer. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ + * {} The Projection of the base layer. │ │ │ │ │ */ │ │ │ │ │ - mergeNewParams: function(newParams) { │ │ │ │ │ - this.params = OpenLayers.Util.extend(this.params, newParams); │ │ │ │ │ - var ret = this.redraw(); │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "params" │ │ │ │ │ - }); │ │ │ │ │ + getProjectionObject: function() { │ │ │ │ │ + var projection = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + projection = this.baseLayer.projection; │ │ │ │ │ } │ │ │ │ │ - return ret; │ │ │ │ │ + return projection; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getMaxResolution │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ + * {String} The Map's Maximum Resolution │ │ │ │ │ */ │ │ │ │ │ - redraw: function(force) { │ │ │ │ │ - if (force) { │ │ │ │ │ - return this.mergeNewParams({ │ │ │ │ │ - "_olSalt": Math.random() │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ + getMaxResolution: function() { │ │ │ │ │ + var maxResolution = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + maxResolution = this.baseLayer.maxResolution; │ │ │ │ │ } │ │ │ │ │ + return maxResolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectUrl │ │ │ │ │ - * selectUrl() implements the standard floating-point multiplicative │ │ │ │ │ - * hash function described by Knuth, and hashes the contents of the │ │ │ │ │ - * given param string into a float between 0 and 1. This float is then │ │ │ │ │ - * scaled to the size of the provided urls array, and used to select │ │ │ │ │ - * a URL. │ │ │ │ │ + * APIMethod: getMaxExtent │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * paramString - {String} │ │ │ │ │ - * urls - {Array(String)} │ │ │ │ │ + * options - {Object} │ │ │ │ │ * │ │ │ │ │ + * Allowed Options: │ │ │ │ │ + * restricted - {Boolean} If true, returns restricted extent (if it is │ │ │ │ │ + * available.) │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ - * on the paramString. │ │ │ │ │ + * {} The maxExtent property as set on the current │ │ │ │ │ + * baselayer, unless the 'restricted' option is set, in which case │ │ │ │ │ + * the 'restrictedExtent' option from the map is returned (if it │ │ │ │ │ + * is set). │ │ │ │ │ */ │ │ │ │ │ - selectUrl: function(paramString, urls) { │ │ │ │ │ - var product = 1; │ │ │ │ │ - for (var i = 0, len = paramString.length; i < len; i++) { │ │ │ │ │ - product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR; │ │ │ │ │ - product -= Math.floor(product); │ │ │ │ │ + getMaxExtent: function(options) { │ │ │ │ │ + var maxExtent = null; │ │ │ │ │ + if (options && options.restricted && this.restrictedExtent) { │ │ │ │ │ + maxExtent = this.restrictedExtent; │ │ │ │ │ + } else if (this.baseLayer != null) { │ │ │ │ │ + maxExtent = this.baseLayer.maxExtent; │ │ │ │ │ } │ │ │ │ │ - return urls[Math.floor(product * urls.length)]; │ │ │ │ │ + return maxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getFullRequestString │ │ │ │ │ - * Combine url with layer's params and these newParams. │ │ │ │ │ - * │ │ │ │ │ - * does checking on the serverPath variable, allowing for cases when it │ │ │ │ │ - * is supplied with trailing ? or &, as well as cases where not. │ │ │ │ │ - * │ │ │ │ │ - * return in formatted string like this: │ │ │ │ │ - * "server?key1=value1&key2=value2&key3=value3" │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getNumZoomLevels │ │ │ │ │ * │ │ │ │ │ - * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The total number of zoom levels that can be displayed by the │ │ │ │ │ + * current baseLayer. │ │ │ │ │ */ │ │ │ │ │ - getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ - │ │ │ │ │ - // if not altUrl passed in, use layer's url │ │ │ │ │ - var url = altUrl || this.url; │ │ │ │ │ - │ │ │ │ │ - // create a new params hashtable with all the layer params and the │ │ │ │ │ - // new params together. then convert to string │ │ │ │ │ - var allParams = OpenLayers.Util.extend({}, this.params); │ │ │ │ │ - allParams = OpenLayers.Util.extend(allParams, newParams); │ │ │ │ │ - var paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ - │ │ │ │ │ - // if url is not a string, it should be an array of strings, │ │ │ │ │ - // in which case we will deterministically select one of them in │ │ │ │ │ - // order to evenly distribute requests to different urls. │ │ │ │ │ - // │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(paramsString, url); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // ignore parameters that are already in the url search string │ │ │ │ │ - var urlParams = │ │ │ │ │ - OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); │ │ │ │ │ - for (var key in allParams) { │ │ │ │ │ - if (key.toUpperCase() in urlParams) { │ │ │ │ │ - delete allParams[key]; │ │ │ │ │ - } │ │ │ │ │ + getNumZoomLevels: function() { │ │ │ │ │ + var numZoomLevels = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + numZoomLevels = this.baseLayer.numZoomLevels; │ │ │ │ │ } │ │ │ │ │ - paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ + return numZoomLevels; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.HTTPRequest" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Tile/Image.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Tile.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Tile.Image │ │ │ │ │ - * Instances of OpenLayers.Tile.Image are used to manage the image tiles │ │ │ │ │ - * used by various layers. Create a new image tile with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Baselayer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions, all publicly exposed */ │ │ │ │ │ + /* in the API?, are all merely wrappers to the */ │ │ │ │ │ + /* the same calls on whatever layer is set as */ │ │ │ │ │ + /* the current base layer */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the tile. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * tile.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to the events): │ │ │ │ │ - * beforeload - Triggered before an image is prepared for loading, when the │ │ │ │ │ - * url for the image is known already. Listeners may call on │ │ │ │ │ - * the tile instance. If they do so, that image will be used and no new │ │ │ │ │ - * one will be created. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} The URL of the image being requested. No default. Filled in by │ │ │ │ │ - * layer.getURL() function. May be modified by loadstart listeners. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: imgDiv │ │ │ │ │ - * {HTMLImageElement} The image for this tile. │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - imgDiv: null, │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + var extent = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + extent = this.baseLayer.getExtent(); │ │ │ │ │ + } │ │ │ │ │ + return extent; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: frame │ │ │ │ │ - * {DOMElement} The image element is appended to the frame. Any gutter on │ │ │ │ │ - * the image will be hidden behind the frame. If no gutter is set, │ │ │ │ │ - * this will be null. │ │ │ │ │ - */ │ │ │ │ │ - frame: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageReloadAttempts │ │ │ │ │ - * {Integer} Attempts to load the image. │ │ │ │ │ + * APIMethod: getResolution │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current resolution of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - imageReloadAttempts: null, │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + var resolution = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + resolution = this.baseLayer.getResolution(); │ │ │ │ │ + } else if (this.allOverlays === true && this.layers.length > 0) { │ │ │ │ │ + // while adding the 1st layer to the map in allOverlays mode, │ │ │ │ │ + // this.baseLayer is not set yet when we need the resolution │ │ │ │ │ + // for calculateInRange. │ │ │ │ │ + resolution = this.layers[0].getResolution(); │ │ │ │ │ + } │ │ │ │ │ + return resolution; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layerAlphaHack │ │ │ │ │ - * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ + * APIMethod: getUnits │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current units of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - layerAlphaHack: null, │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + var units = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + units = this.baseLayer.units; │ │ │ │ │ + } │ │ │ │ │ + return units; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: asyncRequestId │ │ │ │ │ - * {Integer} ID of an request to see if request is still valid. This is a │ │ │ │ │ - * number which increments by 1 for each asynchronous request. │ │ │ │ │ + * APIMethod: getScale │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current scale denominator of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - asyncRequestId: null, │ │ │ │ │ + getScale: function() { │ │ │ │ │ + var scale = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + var units = this.baseLayer.units; │ │ │ │ │ + scale = OpenLayers.Util.getScaleFromResolution(res, units); │ │ │ │ │ + } │ │ │ │ │ + return scale; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxGetUrlLength │ │ │ │ │ - * {Number} If set, requests that would result in GET urls with more │ │ │ │ │ - * characters than the number provided will be made using form-encoded │ │ │ │ │ - * HTTP POST. It is good practice to avoid urls that are longer than 2048 │ │ │ │ │ - * characters. │ │ │ │ │ - * │ │ │ │ │ - * Caution: │ │ │ │ │ - * Older versions of Gecko based browsers (e.g. Firefox < 3.5) and most │ │ │ │ │ - * Opera versions do not fully support this option. On all browsers, │ │ │ │ │ - * transition effects are not supported if POST requests are used. │ │ │ │ │ + * APIMethod: getZoomForExtent │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} A suitable zoom level for the specified bounds. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - maxGetUrlLength: null, │ │ │ │ │ + getZoomForExtent: function(bounds, closest) { │ │ │ │ │ + var zoom = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + zoom = this.baseLayer.getZoomForExtent(bounds, closest); │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: canvasContext │ │ │ │ │ - * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ - * the tile image. │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. If no baselayer │ │ │ │ │ + * is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - canvasContext: null, │ │ │ │ │ + getResolutionForZoom: function(zoom) { │ │ │ │ │ + var resolution = null; │ │ │ │ │ + if (this.baseLayer) { │ │ │ │ │ + resolution = this.baseLayer.getResolutionForZoom(zoom); │ │ │ │ │ + } │ │ │ │ │ + return resolution; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: crossOriginKeyword │ │ │ │ │ - * The value of the crossorigin keyword to use when loading images. This is │ │ │ │ │ - * only relevant when using for tiles from remote │ │ │ │ │ - * origins and should be set to either 'anonymous' or 'use-credentials' │ │ │ │ │ - * for servers that send Access-Control-Allow-Origin headers with their │ │ │ │ │ - * tiles. │ │ │ │ │ + * APIMethod: getZoomForResolution │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * resolution - {Float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ + * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ + * resolution is actually smaller than we would have desired (if this │ │ │ │ │ + * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ + * the returned zoom index might not actually contain the entire │ │ │ │ │ + * extent specified... but it'll be close). │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} A suitable zoom level for the specified resolution. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ */ │ │ │ │ │ - crossOriginKeyword: null, │ │ │ │ │ + getZoomForResolution: function(resolution, closest) { │ │ │ │ │ + var zoom = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + zoom = this.baseLayer.getZoomForResolution(resolution, closest); │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** TBD 3.0 - reorder the parameters to the init function to remove │ │ │ │ │ - * URL. the getUrl() function on the layer gets called on │ │ │ │ │ - * each draw(), so no need to specify it here. │ │ │ │ │ - */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Zooming Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions, all publicly exposed */ │ │ │ │ │ + /* in the API, are all merely wrappers to the */ │ │ │ │ │ + /* the setCenter() function */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Tile.Image │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ + * APIMethod: zoomTo │ │ │ │ │ + * Zoom to a specific zoom level. Zooming will be animated unless the map │ │ │ │ │ + * is configured with {zoomMethod: null}. To zoom without animation, use │ │ │ │ │ + * without a lonlat argument. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} layer that the tile will go in. │ │ │ │ │ - * position - {} │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ - * size - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * zoom - {Integer} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ - OpenLayers.Tile.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.url = url; //deprecated remove me │ │ │ │ │ - │ │ │ │ │ - this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); │ │ │ │ │ + zoomTo: function(zoom, xy) { │ │ │ │ │ + // non-API arguments: │ │ │ │ │ + // xy - {} optional zoom origin │ │ │ │ │ │ │ │ │ │ - if (this.maxGetUrlLength != null || this.layer.gutter || this.layerAlphaHack) { │ │ │ │ │ - // only create frame if it's needed │ │ │ │ │ - this.frame = document.createElement("div"); │ │ │ │ │ - this.frame.style.position = "absolute"; │ │ │ │ │ - this.frame.style.overflow = "hidden"; │ │ │ │ │ - } │ │ │ │ │ - if (this.maxGetUrlLength != null) { │ │ │ │ │ - OpenLayers.Util.extend(this, OpenLayers.Tile.Image.IFrame); │ │ │ │ │ + var map = this; │ │ │ │ │ + if (map.isValidZoomLevel(zoom)) { │ │ │ │ │ + if (map.baseLayer.wrapDateLine) { │ │ │ │ │ + zoom = map.adjustZoom(zoom); │ │ │ │ │ + } │ │ │ │ │ + if (map.zoomTween) { │ │ │ │ │ + var currentRes = map.getResolution(), │ │ │ │ │ + targetRes = map.getResolutionForZoom(zoom), │ │ │ │ │ + start = { │ │ │ │ │ + scale: 1 │ │ │ │ │ + }, │ │ │ │ │ + end = { │ │ │ │ │ + scale: currentRes / targetRes │ │ │ │ │ + }; │ │ │ │ │ + if (map.zoomTween.playing && map.zoomTween.duration < 3 * map.zoomDuration) { │ │ │ │ │ + // update the end scale, and reuse the running zoomTween │ │ │ │ │ + map.zoomTween.finish = { │ │ │ │ │ + scale: map.zoomTween.finish.scale * end.scale │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + if (!xy) { │ │ │ │ │ + var size = map.getSize(); │ │ │ │ │ + xy = { │ │ │ │ │ + x: size.w / 2, │ │ │ │ │ + y: size.h / 2 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + map.zoomTween.start(start, end, map.zoomDuration, { │ │ │ │ │ + minFrameRate: 50, // don't spend much time zooming │ │ │ │ │ + callbacks: { │ │ │ │ │ + eachStep: function(data) { │ │ │ │ │ + var containerOrigin = map.layerContainerOriginPx, │ │ │ │ │ + scale = data.scale, │ │ │ │ │ + dx = ((scale - 1) * (containerOrigin.x - xy.x)) | 0, │ │ │ │ │ + dy = ((scale - 1) * (containerOrigin.y - xy.y)) | 0; │ │ │ │ │ + map.applyTransform(containerOrigin.x + dx, containerOrigin.y + dy, scale); │ │ │ │ │ + }, │ │ │ │ │ + done: function(data) { │ │ │ │ │ + map.applyTransform(); │ │ │ │ │ + var resolution = map.getResolution() / data.scale, │ │ │ │ │ + zoom = map.getZoomForResolution(resolution, true) │ │ │ │ │ + map.moveTo(map.getZoomTargetCenter(xy, resolution), zoom, true); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var center = xy ? │ │ │ │ │ + map.getZoomTargetCenter(xy, map.getResolutionForZoom(zoom)) : │ │ │ │ │ + null; │ │ │ │ │ + map.setCenter(center, zoom); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomIn │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.imgDiv) { │ │ │ │ │ - this.clear(); │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - this.frame = null; │ │ │ │ │ - } │ │ │ │ │ - // don't handle async requests any more │ │ │ │ │ - this.asyncRequestId = null; │ │ │ │ │ - OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ + zoomIn: function() { │ │ │ │ │ + this.zoomTo(this.getZoom() + 1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Check that a tile should be drawn, and draw it. │ │ │ │ │ + * APIMethod: zoomOut │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Was a tile drawn? Or null if a beforedraw listener returned │ │ │ │ │ - * false. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var shouldDraw = OpenLayers.Tile.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (shouldDraw) { │ │ │ │ │ - // The layer's reproject option is deprecated. │ │ │ │ │ - if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { │ │ │ │ │ - // getBoundsFromBaseLayer is defined in deprecated.js. │ │ │ │ │ - this.bounds = this.getBoundsFromBaseLayer(this.position); │ │ │ │ │ - } │ │ │ │ │ - if (this.isLoading) { │ │ │ │ │ - //if we're already loading, send 'reload' instead of 'loadstart'. │ │ │ │ │ - this._loadEvent = "reload"; │ │ │ │ │ - } else { │ │ │ │ │ - this.isLoading = true; │ │ │ │ │ - this._loadEvent = "loadstart"; │ │ │ │ │ - } │ │ │ │ │ - this.renderTile(); │ │ │ │ │ - this.positionTile(); │ │ │ │ │ - } else if (shouldDraw === false) { │ │ │ │ │ - this.unload(); │ │ │ │ │ - } │ │ │ │ │ - return shouldDraw; │ │ │ │ │ + zoomOut: function() { │ │ │ │ │ + this.zoomTo(this.getZoom() - 1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: renderTile │ │ │ │ │ - * Internal function to actually initialize the image tile, │ │ │ │ │ - * position it correctly, and set its url. │ │ │ │ │ + * APIMethod: zoomToExtent │ │ │ │ │ + * Zoom to the passed in bounds, recenter │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - renderTile: function() { │ │ │ │ │ - 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); │ │ │ │ │ - this.initImage(); │ │ │ │ │ + zoomToExtent: function(bounds, closest) { │ │ │ │ │ + if (!(bounds instanceof OpenLayers.Bounds)) { │ │ │ │ │ + bounds = new OpenLayers.Bounds(bounds); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + if (this.baseLayer.wrapDateLine) { │ │ │ │ │ + var maxExtent = this.getMaxExtent(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: positionTile │ │ │ │ │ - * Using the properties currenty set on the layer, position the tile correctly. │ │ │ │ │ - * This method is used both by the async and non-async versions of the Tile.Image │ │ │ │ │ - * code. │ │ │ │ │ - */ │ │ │ │ │ - positionTile: function() { │ │ │ │ │ - var style = this.getTile().style, │ │ │ │ │ - size = this.frame ? this.size : │ │ │ │ │ - this.layer.getImageSize(this.bounds), │ │ │ │ │ - ratio = 1; │ │ │ │ │ - if (this.layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - ratio = this.layer.getServerResolution() / this.layer.map.getResolution(); │ │ │ │ │ + //fix straddling bounds (in the case of a bbox that straddles the │ │ │ │ │ + // dateline, it's left and right boundaries will appear backwards. │ │ │ │ │ + // we fix this by allowing a right value that is greater than the │ │ │ │ │ + // max value at the dateline -- this allows us to pass a valid │ │ │ │ │ + // bounds to calculate zoom) │ │ │ │ │ + // │ │ │ │ │ + bounds = bounds.clone(); │ │ │ │ │ + while (bounds.right < bounds.left) { │ │ │ │ │ + bounds.right += maxExtent.getWidth(); │ │ │ │ │ + } │ │ │ │ │ + //if the bounds was straddling (see above), then the center point │ │ │ │ │ + // we got from it was wrong. So we take our new bounds and ask it │ │ │ │ │ + // for the center. │ │ │ │ │ + // │ │ │ │ │ + center = bounds.getCenterLonLat().wrapDateLine(maxExtent); │ │ │ │ │ } │ │ │ │ │ - style.left = this.position.x + "px"; │ │ │ │ │ - style.top = this.position.y + "px"; │ │ │ │ │ - style.width = Math.round(ratio * size.w) + "px"; │ │ │ │ │ - style.height = Math.round(ratio * size.h) + "px"; │ │ │ │ │ + this.setCenter(center, this.getZoomForExtent(bounds, closest)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Remove the tile from the DOM, clear it of any image related data so that │ │ │ │ │ - * it can be reused in a new location. │ │ │ │ │ + * APIMethod: zoomToMaxExtent │ │ │ │ │ + * Zoom to the full extent and recenter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Allowed Options: │ │ │ │ │ + * restricted - {Boolean} True to zoom to restricted extent if it is │ │ │ │ │ + * set. Defaults to true. │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - OpenLayers.Tile.prototype.clear.apply(this, arguments); │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (img) { │ │ │ │ │ - var tile = this.getTile(); │ │ │ │ │ - if (tile.parentNode === this.layer.div) { │ │ │ │ │ - this.layer.div.removeChild(tile); │ │ │ │ │ - } │ │ │ │ │ - this.setImgSrc(); │ │ │ │ │ - if (this.layerAlphaHack === true) { │ │ │ │ │ - img.style.filter = ""; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Element.removeClass(img, "olImageLoadError"); │ │ │ │ │ - } │ │ │ │ │ - this.canvasContext = null; │ │ │ │ │ + zoomToMaxExtent: function(options) { │ │ │ │ │ + //restricted is true by default │ │ │ │ │ + var restricted = (options) ? options.restricted : true; │ │ │ │ │ + │ │ │ │ │ + var maxExtent = this.getMaxExtent({ │ │ │ │ │ + 'restricted': restricted │ │ │ │ │ + }); │ │ │ │ │ + this.zoomToExtent(maxExtent); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getImage │ │ │ │ │ - * Returns or creates and returns the tile image. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomToScale │ │ │ │ │ + * Zoom to a specified scale │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scale - {float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified scale. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - getImage: function() { │ │ │ │ │ - if (!this.imgDiv) { │ │ │ │ │ - this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ + zoomToScale: function(scale, closest) { │ │ │ │ │ + var res = OpenLayers.Util.getResolutionFromScale(scale, │ │ │ │ │ + this.baseLayer.units); │ │ │ │ │ │ │ │ │ │ - var style = this.imgDiv.style; │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - var left = 0, │ │ │ │ │ - top = 0; │ │ │ │ │ - if (this.layer.gutter) { │ │ │ │ │ - left = this.layer.gutter / this.layer.tileSize.w * 100; │ │ │ │ │ - top = this.layer.gutter / this.layer.tileSize.h * 100; │ │ │ │ │ - } │ │ │ │ │ - style.left = -left + "%"; │ │ │ │ │ - style.top = -top + "%"; │ │ │ │ │ - style.width = (2 * left + 100) + "%"; │ │ │ │ │ - style.height = (2 * top + 100) + "%"; │ │ │ │ │ - } │ │ │ │ │ - style.visibility = "hidden"; │ │ │ │ │ - style.opacity = 0; │ │ │ │ │ - if (this.layer.opacity < 1) { │ │ │ │ │ - style.filter = 'alpha(opacity=' + │ │ │ │ │ - (this.layer.opacity * 100) + │ │ │ │ │ - ')'; │ │ │ │ │ - } │ │ │ │ │ - style.position = "absolute"; │ │ │ │ │ - if (this.layerAlphaHack) { │ │ │ │ │ - // move the image out of sight │ │ │ │ │ - style.paddingTop = style.height; │ │ │ │ │ - style.height = "0"; │ │ │ │ │ - style.width = "100%"; │ │ │ │ │ - } │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - this.frame.appendChild(this.imgDiv); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + var halfWDeg = (this.size.w * res) / 2; │ │ │ │ │ + var halfHDeg = (this.size.h * res) / 2; │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ │ │ │ │ │ - return this.imgDiv; │ │ │ │ │ + var extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ + center.lat - halfHDeg, │ │ │ │ │ + center.lon + halfWDeg, │ │ │ │ │ + center.lat + halfHDeg); │ │ │ │ │ + this.zoomToExtent(extent, closest); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Translation Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions translate between */ │ │ │ │ │ + /* LonLat, LayerPx, and ViewPortPx */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: LonLat <-> ViewPortPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setImage │ │ │ │ │ - * Sets the image element for this tile. This method should only be called │ │ │ │ │ - * from beforeload listeners. │ │ │ │ │ - * │ │ │ │ │ - * Parameters │ │ │ │ │ - * img - {HTMLImageElement} The image to use for this tile. │ │ │ │ │ + * Method: getLonLatFromViewPortPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ + * an object with a 'x' │ │ │ │ │ + * and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ + * port , translated into lon/lat │ │ │ │ │ + * by the current base layer. │ │ │ │ │ */ │ │ │ │ │ - setImage: function(img) { │ │ │ │ │ - this.imgDiv = img; │ │ │ │ │ + getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var lonlat = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ + } │ │ │ │ │ + return lonlat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initImage │ │ │ │ │ - * Creates the content for the frame on the tile. │ │ │ │ │ + * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ + * , translated into view port │ │ │ │ │ + * pixels by the current base layer. │ │ │ │ │ */ │ │ │ │ │ - initImage: function() { │ │ │ │ │ - if (!this.url && !this.imgDiv) { │ │ │ │ │ - // fast path out - if there is no tile url and no previous image │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent('beforeload'); │ │ │ │ │ - this.layer.div.appendChild(this.getTile()); │ │ │ │ │ - this.events.triggerEvent(this._loadEvent); │ │ │ │ │ - var img = this.getImage(); │ │ │ │ │ - var src = img.getAttribute('src') || ''; │ │ │ │ │ - if (this.url && OpenLayers.Util.isEquivalentUrl(src, this.url)) { │ │ │ │ │ - this._loadTimeout = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.onImageLoad, this), 0 │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - if (this.crossOriginKeyword) { │ │ │ │ │ - img.removeAttribute("crossorigin"); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.observe(img, "load", │ │ │ │ │ - OpenLayers.Function.bind(this.onImageLoad, this) │ │ │ │ │ - ); │ │ │ │ │ - OpenLayers.Event.observe(img, "error", │ │ │ │ │ - OpenLayers.Function.bind(this.onImageError, this) │ │ │ │ │ - ); │ │ │ │ │ - this.imageReloadAttempts = 0; │ │ │ │ │ - this.setImgSrc(this.url); │ │ │ │ │ + getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ + var px = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + px = this.baseLayer.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ } │ │ │ │ │ + return px; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setImgSrc │ │ │ │ │ - * Sets the source for the tile image │ │ │ │ │ + * Method: getZoomTargetCenter │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * url - {String} or undefined to hide the image │ │ │ │ │ + * xy - {} The zoom origin pixel location on the screen │ │ │ │ │ + * resolution - {Float} The resolution we want to get the center for │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The location of the map center after the │ │ │ │ │ + * transformation described by the origin xy and the target resolution. │ │ │ │ │ */ │ │ │ │ │ - setImgSrc: function(url) { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (url) { │ │ │ │ │ - img.style.visibility = 'hidden'; │ │ │ │ │ - img.style.opacity = 0; │ │ │ │ │ - // don't set crossOrigin if the url is a data URL │ │ │ │ │ - if (this.crossOriginKeyword) { │ │ │ │ │ - if (url.substr(0, 5) !== 'data:') { │ │ │ │ │ - img.setAttribute("crossorigin", this.crossOriginKeyword); │ │ │ │ │ - } else { │ │ │ │ │ - img.removeAttribute("crossorigin"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - img.src = url; │ │ │ │ │ - } else { │ │ │ │ │ - // Remove reference to the image, and leave it to the browser's │ │ │ │ │ - // caching and garbage collection. │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - if (img.parentNode) { │ │ │ │ │ - img.parentNode.removeChild(img); │ │ │ │ │ - } │ │ │ │ │ + getZoomTargetCenter: function(xy, resolution) { │ │ │ │ │ + var lonlat = null, │ │ │ │ │ + size = this.getSize(), │ │ │ │ │ + deltaX = size.w / 2 - xy.x, │ │ │ │ │ + deltaY = xy.y - size.h / 2, │ │ │ │ │ + zoomPoint = this.getLonLatFromPixel(xy); │ │ │ │ │ + if (zoomPoint) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat( │ │ │ │ │ + zoomPoint.lon + deltaX * resolution, │ │ │ │ │ + zoomPoint.lat + deltaY * resolution │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return lonlat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + // │ │ │ │ │ + // CONVENIENCE TRANSLATION FUNCTIONS FOR API │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: getTile │ │ │ │ │ - * Get the tile's markup. │ │ │ │ │ + * APIMethod: getLonLatFromPixel │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} An OpenLayers.Pixel or an object with │ │ │ │ │ + * a 'x' and 'y' properties. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The tile's markup │ │ │ │ │ + * {} An OpenLayers.LonLat corresponding to the given │ │ │ │ │ + * OpenLayers.Pixel, translated into lon/lat by the │ │ │ │ │ + * current base layer │ │ │ │ │ */ │ │ │ │ │ - getTile: function() { │ │ │ │ │ - return this.frame ? this.frame : this.getImage(); │ │ │ │ │ + getLonLatFromPixel: function(px) { │ │ │ │ │ + return this.getLonLatFromViewPortPx(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * Create a backbuffer for this tile. A backbuffer isn't exactly a clone │ │ │ │ │ - * of the tile's markup, because we want to avoid the reloading of the │ │ │ │ │ - * image. So we clone the frame, and steal the image from the tile. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getPixelFromLonLat │ │ │ │ │ + * Returns a pixel location given a map location. The map location is │ │ │ │ │ + * translated to an integer pixel location (in viewport pixel │ │ │ │ │ + * coordinates) by the current base layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} A map location. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.Pixel corresponding to the │ │ │ │ │ + * translated into view port pixels by the current │ │ │ │ │ + * base layer. │ │ │ │ │ + */ │ │ │ │ │ + getPixelFromLonLat: function(lonlat) { │ │ │ │ │ + var px = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + px.x = Math.round(px.x); │ │ │ │ │ + px.y = Math.round(px.y); │ │ │ │ │ + return px; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeodesicPixelSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} The pixel to get the geodesic length for. If │ │ │ │ │ + * not provided, the center pixel of the map viewport will be used. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ - * or if it's currently loading. │ │ │ │ │ + * {} The geodesic size of the pixel in kilometers. │ │ │ │ │ */ │ │ │ │ │ - createBackBuffer: function() { │ │ │ │ │ - if (!this.imgDiv || this.isLoading) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var backBuffer; │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - backBuffer = this.frame.cloneNode(false); │ │ │ │ │ - backBuffer.appendChild(this.imgDiv); │ │ │ │ │ - } else { │ │ │ │ │ - backBuffer = this.imgDiv; │ │ │ │ │ + getGeodesicPixelSize: function(px) { │ │ │ │ │ + var lonlat = px ? this.getLonLatFromPixel(px) : ( │ │ │ │ │ + this.getCachedCenter() || new OpenLayers.LonLat(0, 0)); │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + var left = lonlat.add(-res / 2, 0); │ │ │ │ │ + var right = lonlat.add(res / 2, 0); │ │ │ │ │ + var bottom = lonlat.add(0, -res / 2); │ │ │ │ │ + var top = lonlat.add(0, res / 2); │ │ │ │ │ + var dest = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + var source = this.getProjectionObject() || dest; │ │ │ │ │ + if (!source.equals(dest)) { │ │ │ │ │ + left.transform(source, dest); │ │ │ │ │ + right.transform(source, dest); │ │ │ │ │ + bottom.transform(source, dest); │ │ │ │ │ + top.transform(source, dest); │ │ │ │ │ } │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - return backBuffer; │ │ │ │ │ + │ │ │ │ │ + return new OpenLayers.Size( │ │ │ │ │ + OpenLayers.Util.distVincenty(left, right), │ │ │ │ │ + OpenLayers.Util.distVincenty(bottom, top) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: ViewPortPx <-> LayerPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageLoad │ │ │ │ │ - * Handler for the image onload event │ │ │ │ │ + * APIMethod: getViewPortPxFromLayerPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layerPx - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Layer Pixel translated into ViewPort Pixel │ │ │ │ │ + * coordinates │ │ │ │ │ */ │ │ │ │ │ - onImageLoad: function() { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - img.style.visibility = 'inherit'; │ │ │ │ │ - img.style.opacity = this.layer.opacity; │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.canvasContext = null; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - │ │ │ │ │ - if (this.layerAlphaHack === true) { │ │ │ │ │ - img.style.filter = │ │ │ │ │ - "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + │ │ │ │ │ - img.src + "', sizingMethod='scale')"; │ │ │ │ │ + getViewPortPxFromLayerPx: function(layerPx) { │ │ │ │ │ + var viewPortPx = null; │ │ │ │ │ + if (layerPx != null) { │ │ │ │ │ + var dX = this.layerContainerOriginPx.x; │ │ │ │ │ + var dY = this.layerContainerOriginPx.y; │ │ │ │ │ + viewPortPx = layerPx.add(dX, dY); │ │ │ │ │ } │ │ │ │ │ + return viewPortPx; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageError │ │ │ │ │ - * Handler for the image onerror event │ │ │ │ │ + * APIMethod: getLayerPxFromViewPortPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} ViewPort Pixel translated into Layer Pixel │ │ │ │ │ + * coordinates │ │ │ │ │ */ │ │ │ │ │ - onImageError: function() { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (img.src != null) { │ │ │ │ │ - this.imageReloadAttempts++; │ │ │ │ │ - if (this.imageReloadAttempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) { │ │ │ │ │ - this.setImgSrc(this.layer.getURL(this.bounds)); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Element.addClass(img, "olImageLoadError"); │ │ │ │ │ - this.events.triggerEvent("loaderror"); │ │ │ │ │ - this.onImageLoad(); │ │ │ │ │ + getLayerPxFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var layerPx = null; │ │ │ │ │ + if (viewPortPx != null) { │ │ │ │ │ + var dX = -this.layerContainerOriginPx.x; │ │ │ │ │ + var dY = -this.layerContainerOriginPx.y; │ │ │ │ │ + layerPx = viewPortPx.add(dX, dY); │ │ │ │ │ + if (isNaN(layerPx.x) || isNaN(layerPx.y)) { │ │ │ │ │ + layerPx = null; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + return layerPx; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: LonLat <-> LayerPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: stopLoading │ │ │ │ │ - * Stops a loading sequence so won't be executed. │ │ │ │ │ + * Method: getLonLatFromLayerPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - stopLoading: function() { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ - window.clearTimeout(this._loadTimeout); │ │ │ │ │ - delete this._loadTimeout; │ │ │ │ │ + getLonLatFromLayerPx: function(px) { │ │ │ │ │ + //adjust for displacement of layerContainerDiv │ │ │ │ │ + px = this.getViewPortPxFromLayerPx(px); │ │ │ │ │ + return this.getLonLatFromViewPortPx(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCanvasContext │ │ │ │ │ - * Returns a canvas context associated with the tile image (with │ │ │ │ │ - * the image drawn on it). │ │ │ │ │ - * Returns undefined if the browser does not support canvas, if │ │ │ │ │ - * the tile has no image or if it's currently loading. │ │ │ │ │ - * │ │ │ │ │ - * The function returns a canvas context instance but the │ │ │ │ │ - * underlying canvas is still available in the 'canvas' property: │ │ │ │ │ - * (code) │ │ │ │ │ - * var context = tile.getCanvasContext(); │ │ │ │ │ - * if (context) { │ │ │ │ │ - * var data = context.canvas.toDataURL('image/jpeg'); │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * APIMethod: getLayerPxFromLonLat │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} lonlat │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ + * , translated into layer pixels │ │ │ │ │ + * by the current base layer │ │ │ │ │ */ │ │ │ │ │ - getCanvasContext: function() { │ │ │ │ │ - if (OpenLayers.CANVAS_SUPPORTED && this.imgDiv && !this.isLoading) { │ │ │ │ │ - if (!this.canvasContext) { │ │ │ │ │ - var canvas = document.createElement("canvas"); │ │ │ │ │ - canvas.width = this.size.w; │ │ │ │ │ - canvas.height = this.size.h; │ │ │ │ │ - this.canvasContext = canvas.getContext("2d"); │ │ │ │ │ - this.canvasContext.drawImage(this.imgDiv, 0, 0); │ │ │ │ │ + getLayerPxFromLonLat: function(lonlat) { │ │ │ │ │ + //adjust for displacement of layerContainerDiv │ │ │ │ │ + var px = this.getPixelFromLonLat(lonlat); │ │ │ │ │ + return this.getLayerPxFromViewPortPx(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: applyTransform │ │ │ │ │ + * Applies the given transform to the . This method has │ │ │ │ │ + * a 2-stage fallback from translate3d/scale3d via translate/scale to plain │ │ │ │ │ + * style.left/style.top, in which case no scaling is supported. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Number} x parameter for the translation. Defaults to the x value of │ │ │ │ │ + * the map's │ │ │ │ │ + * y - {Number} y parameter for the translation. Defaults to the y value of │ │ │ │ │ + * the map's │ │ │ │ │ + * scale - {Number} scale. Defaults to 1 if not provided. │ │ │ │ │ + */ │ │ │ │ │ + applyTransform: function(x, y, scale) { │ │ │ │ │ + scale = scale || 1; │ │ │ │ │ + var origin = this.layerContainerOriginPx, │ │ │ │ │ + needTransform = scale !== 1; │ │ │ │ │ + x = x || origin.x; │ │ │ │ │ + y = y || origin.y; │ │ │ │ │ + │ │ │ │ │ + var style = this.layerContainerDiv.style, │ │ │ │ │ + transform = this.applyTransform.transform, │ │ │ │ │ + template = this.applyTransform.template; │ │ │ │ │ + │ │ │ │ │ + if (transform === undefined) { │ │ │ │ │ + transform = OpenLayers.Util.vendorPrefix.style('transform'); │ │ │ │ │ + this.applyTransform.transform = transform; │ │ │ │ │ + if (transform) { │ │ │ │ │ + // Try translate3d, but only if the viewPortDiv has a transform │ │ │ │ │ + // defined in a stylesheet │ │ │ │ │ + var computedStyle = OpenLayers.Element.getStyle(this.viewPortDiv, │ │ │ │ │ + OpenLayers.Util.vendorPrefix.css('transform')); │ │ │ │ │ + if (!computedStyle || computedStyle !== 'none') { │ │ │ │ │ + template = ['translate3d(', ',0) ', 'scale3d(', ',1)']; │ │ │ │ │ + style[transform] = [template[0], '0,0', template[1]].join(''); │ │ │ │ │ + } │ │ │ │ │ + // If no transform is defined in the stylesheet or translate3d │ │ │ │ │ + // does not stick, use translate and scale │ │ │ │ │ + if (!template || !~style[transform].indexOf(template[0])) { │ │ │ │ │ + template = ['translate(', ') ', 'scale(', ')']; │ │ │ │ │ + } │ │ │ │ │ + this.applyTransform.template = template; │ │ │ │ │ } │ │ │ │ │ - return this.canvasContext; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile.Image" │ │ │ │ │ + // If we do 3d transforms, we always want to use them. If we do 2d │ │ │ │ │ + // transforms, we only use them when we need to. │ │ │ │ │ + if (transform !== null && (template[0] === 'translate3d(' || needTransform === true)) { │ │ │ │ │ + // Our 2d transforms are combined with style.left and style.top, so │ │ │ │ │ + // adjust x and y values and set the origin as left and top │ │ │ │ │ + if (needTransform === true && template[0] === 'translate(') { │ │ │ │ │ + x -= origin.x; │ │ │ │ │ + y -= origin.y; │ │ │ │ │ + style.left = origin.x + 'px'; │ │ │ │ │ + style.top = origin.y + 'px'; │ │ │ │ │ + } │ │ │ │ │ + style[transform] = [ │ │ │ │ │ + template[0], x, 'px,', y, 'px', template[1], │ │ │ │ │ + template[2], scale, ',', scale, template[3] │ │ │ │ │ + ].join(''); │ │ │ │ │ + } else { │ │ │ │ │ + style.left = x + 'px'; │ │ │ │ │ + style.top = y + 'px'; │ │ │ │ │ + // We previously might have had needTransform, so remove transform │ │ │ │ │ + if (transform !== null) { │ │ │ │ │ + style[transform] = ''; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Map" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Tile.Image.IMAGE │ │ │ │ │ - * {HTMLImageElement} The image for a tile. │ │ │ │ │ +/** │ │ │ │ │ + * Constant: TILE_WIDTH │ │ │ │ │ + * {Integer} 256 Default tile width (unless otherwise specified) │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Tile.Image.IMAGE = (function() { │ │ │ │ │ - var img = new Image(); │ │ │ │ │ - img.className = "olTileImage"; │ │ │ │ │ - // avoid image gallery menu in IE6 │ │ │ │ │ - img.galleryImg = "no"; │ │ │ │ │ - return img; │ │ │ │ │ -}()); │ │ │ │ │ - │ │ │ │ │ +OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: TILE_HEIGHT │ │ │ │ │ + * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Grid.js │ │ │ │ │ + OpenLayers/Layer.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Map.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Grid │ │ │ │ │ - * Base class for layers that use a lattice of tiles. Create a new grid │ │ │ │ │ - * layer with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Layer │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileSize │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - tileSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileOriginCorner │ │ │ │ │ - * {String} If the property is not provided, the tile origin │ │ │ │ │ - * will be derived from the layer's . The corner of the │ │ │ │ │ - * used is determined by this property. Acceptable values │ │ │ │ │ - * are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br" │ │ │ │ │ - * (bottom right). Default is "bl". │ │ │ │ │ - */ │ │ │ │ │ - tileOriginCorner: "bl", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileOrigin │ │ │ │ │ - * {} Optional origin for aligning the grid of tiles. │ │ │ │ │ - * If provided, requests for tiles at all resolutions will be aligned │ │ │ │ │ - * with this location (no tiles shall overlap this location). If │ │ │ │ │ - * not provided, the grid of tiles will be aligned with the layer's │ │ │ │ │ - * . Default is ``null``. │ │ │ │ │ - */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ - │ │ │ │ │ - /** APIProperty: tileOptions │ │ │ │ │ - * {Object} optional configuration options for instances │ │ │ │ │ - * created by this Layer, if supported by the tile class. │ │ │ │ │ - */ │ │ │ │ │ - tileOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileClass │ │ │ │ │ - * {} The tile class to use for this layer. │ │ │ │ │ - * Defaults is OpenLayers.Tile.Image. │ │ │ │ │ - */ │ │ │ │ │ - tileClass: OpenLayers.Tile.Image, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: grid │ │ │ │ │ - * {Array(Array())} This is an array of rows, each row is │ │ │ │ │ - * an array of tiles. │ │ │ │ │ - */ │ │ │ │ │ - grid: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: singleTile │ │ │ │ │ - * {Boolean} Moves the layer into single-tile mode, meaning that one tile │ │ │ │ │ - * will be loaded. The tile's size will be determined by the 'ratio' │ │ │ │ │ - * property. When the tile is dragged such that it does not cover the │ │ │ │ │ - * entire viewport, it is reloaded. │ │ │ │ │ - */ │ │ │ │ │ - singleTile: false, │ │ │ │ │ - │ │ │ │ │ - /** APIProperty: ratio │ │ │ │ │ - * {Float} Used only when in single-tile mode, this specifies the │ │ │ │ │ - * ratio of the size of the single tile to the size of the map. │ │ │ │ │ - * Default value is 1.5. │ │ │ │ │ - */ │ │ │ │ │ - ratio: 1.5, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: buffer │ │ │ │ │ - * {Integer} Used only when in gridded mode, this specifies the number of │ │ │ │ │ - * extra rows and colums of tiles on each side which will │ │ │ │ │ - * surround the minimum grid tiles to cover the map. │ │ │ │ │ - * For very slow loading layers, a larger value may increase │ │ │ │ │ - * performance somewhat when dragging, but will increase bandwidth │ │ │ │ │ - * use significantly. │ │ │ │ │ - */ │ │ │ │ │ - buffer: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: transitionEffect │ │ │ │ │ - * {String} The transition effect to use when the map is zoomed. │ │ │ │ │ - * Two posible values: │ │ │ │ │ - * │ │ │ │ │ - * "resize" - Existing tiles are resized on zoom to provide a visual │ │ │ │ │ - * effect of the zoom having taken place immediately. As the │ │ │ │ │ - * new tiles become available, they are drawn on top of the │ │ │ │ │ - * resized tiles (this is the default setting). │ │ │ │ │ - * "map-resize" - Existing tiles are resized on zoom and placed below the │ │ │ │ │ - * base layer. New tiles for the base layer will cover existing tiles. │ │ │ │ │ - * This setting is recommended when having an overlay duplicated during │ │ │ │ │ - * the transition is undesirable (e.g. street labels or big transparent │ │ │ │ │ - * fills). │ │ │ │ │ - * null - No transition effect. │ │ │ │ │ - * │ │ │ │ │ - * Using "resize" on non-opaque layers can cause undesired visual │ │ │ │ │ - * effects. Set transitionEffect to null in this case. │ │ │ │ │ - */ │ │ │ │ │ - transitionEffect: "resize", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numLoadingTiles │ │ │ │ │ - * {Integer} How many tiles are still loading? │ │ │ │ │ - */ │ │ │ │ │ - numLoadingTiles: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: serverResolutions │ │ │ │ │ - * {Array(Number}} This property is documented in subclasses as │ │ │ │ │ - * an API property. │ │ │ │ │ - */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: loading │ │ │ │ │ - * {Boolean} Indicates if tiles are being loaded. │ │ │ │ │ - */ │ │ │ │ │ - loading: false, │ │ │ │ │ +OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: backBuffer │ │ │ │ │ - * {DOMElement} The back buffer. │ │ │ │ │ + * APIProperty: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - backBuffer: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: gridResolution │ │ │ │ │ - * {Number} The resolution of the current grid. Used for backbuffer and │ │ │ │ │ - * client zoom. This property is updated every time the grid is │ │ │ │ │ - * initialized. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - gridResolution: null, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: backBufferResolution │ │ │ │ │ - * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ - * updated each time a back buffer is created. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - backBufferResolution: null, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: backBufferLonLat │ │ │ │ │ - * {Object} The top-left corner of the current back buffer. Includes lon │ │ │ │ │ - * and lat properties. This object is updated each time a back buffer │ │ │ │ │ - * is created. │ │ │ │ │ + * APIProperty: opacity │ │ │ │ │ + * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ + * is 1. │ │ │ │ │ */ │ │ │ │ │ - backBufferLonLat: null, │ │ │ │ │ + opacity: 1, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: backBufferTimerId │ │ │ │ │ - * {Number} The id of the back buffer timer. This timer is used to │ │ │ │ │ - * delay the removal of the back buffer, thereby preventing │ │ │ │ │ - * flash effects caused by tile animation. │ │ │ │ │ + * APIProperty: alwaysInRange │ │ │ │ │ + * {Boolean} If a layer's display should not be scale-based, this should │ │ │ │ │ + * be set to true. This will cause the layer, as an overlay, to always │ │ │ │ │ + * be 'active', by always returning true from the calculateInRange() │ │ │ │ │ + * function. │ │ │ │ │ + * │ │ │ │ │ + * If not explicitly specified for a layer, its value will be │ │ │ │ │ + * determined on startup in initResolutions() based on whether or not │ │ │ │ │ + * any scale-specific properties have been set as options on the │ │ │ │ │ + * layer. If no scale-specific options have been set on the layer, we │ │ │ │ │ + * assume that it should always be in range. │ │ │ │ │ + * │ │ │ │ │ + * See #987 for more info. │ │ │ │ │ */ │ │ │ │ │ - backBufferTimerId: null, │ │ │ │ │ + alwaysInRange: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: removeBackBufferDelay │ │ │ │ │ - * {Number} Delay for removing the backbuffer when all tiles have finished │ │ │ │ │ - * loading. Can be set to 0 when no css opacity transitions for the │ │ │ │ │ - * olTileImage class are used. Default is 0 for layers, │ │ │ │ │ - * 2500 for tiled layers. See for more information on │ │ │ │ │ - * tile animation. │ │ │ │ │ + * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ + * {Array} The properties that are used for calculating resolutions │ │ │ │ │ + * information. │ │ │ │ │ */ │ │ │ │ │ - removeBackBufferDelay: null, │ │ │ │ │ + RESOLUTION_PROPERTIES: [ │ │ │ │ │ + 'scales', 'resolutions', │ │ │ │ │ + 'maxScale', 'minScale', │ │ │ │ │ + 'maxResolution', 'minResolution', │ │ │ │ │ + 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: className │ │ │ │ │ - * {String} Name of the class added to the layer div. If not set in the │ │ │ │ │ - * options passed to the constructor then className defaults to │ │ │ │ │ - * "olLayerGridSingleTile" for single tile layers (see ), │ │ │ │ │ - * and "olLayerGrid" for non single tile layers. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ * │ │ │ │ │ - * The displaying of tiles is not animated by default for single tile │ │ │ │ │ - * layers - OpenLayers' default theme (style.css) includes this: │ │ │ │ │ - * (code) │ │ │ │ │ - * .olLayerGrid .olTileImage { │ │ │ │ │ - * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ - * -moz-transition: opacity 0.2s linear; │ │ │ │ │ - * -o-transition: opacity 0.2s linear; │ │ │ │ │ - * transition: opacity 0.2s linear; │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * To animate tile displaying for any grid layer the following │ │ │ │ │ - * CSS rule can be used: │ │ │ │ │ - * (code) │ │ │ │ │ - * .olTileImage { │ │ │ │ │ - * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ - * -moz-transition: opacity 0.2s linear; │ │ │ │ │ - * -o-transition: opacity 0.2s linear; │ │ │ │ │ - * transition: opacity 0.2s linear; │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * In that case, to avoid flash effects, │ │ │ │ │ - * should not be zero. │ │ │ │ │ - */ │ │ │ │ │ - className: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ * Register a listener for a particular event with the following syntax: │ │ │ │ │ * (code) │ │ │ │ │ * layer.events.register(type, obj, listener); │ │ │ │ │ * (end) │ │ │ │ │ * │ │ │ │ │ * Listeners will be called with a reference to an event object. The │ │ │ │ │ * properties of this event depends on exactly what happened. │ │ │ │ │ * │ │ │ │ │ * All event objects have at least the following properties: │ │ │ │ │ * object - {Object} A reference to layer.events.object. │ │ │ │ │ * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * addtile - Triggered when a tile is added to this layer. Listeners receive │ │ │ │ │ - * an object as first argument, which has a tile property that │ │ │ │ │ - * references the tile that has been added. │ │ │ │ │ - * tileloadstart - Triggered when a tile starts loading. Listeners receive │ │ │ │ │ - * an object as first argument, which has a tile property that │ │ │ │ │ - * references the tile that starts loading. │ │ │ │ │ - * tileloaded - Triggered when each new tile is │ │ │ │ │ - * loaded, as a means of progress update to listeners. │ │ │ │ │ - * listeners can access 'numLoadingTiles' if they wish to keep │ │ │ │ │ - * track of the loading progress. Listeners are called with an object │ │ │ │ │ - * with a 'tile' property as first argument, making the loaded tile │ │ │ │ │ - * available to the listener, and an 'aborted' property, which will be │ │ │ │ │ - * true when loading was aborted and no tile data is available. │ │ │ │ │ - * tileerror - Triggered before the tileloaded event (i.e. when the tile is │ │ │ │ │ - * still hidden) if a tile failed to load. Listeners receive an object │ │ │ │ │ - * as first argument, which has a tile property that references the │ │ │ │ │ - * tile that could not be loaded. │ │ │ │ │ - * retile - Triggered when the layer recreates its tile grid. │ │ │ │ │ + * Supported map event types: │ │ │ │ │ + * loadstart - Triggered when layer loading starts. When using a Vector │ │ │ │ │ + * layer with a Fixed or BBOX strategy, the event object includes │ │ │ │ │ + * a *filter* property holding the OpenLayers.Filter used when │ │ │ │ │ + * calling read on the protocol. │ │ │ │ │ + * loadend - Triggered when layer loading ends. When using a Vector layer │ │ │ │ │ + * with a Fixed or BBOX strategy, the event object includes a │ │ │ │ │ + * *response* property holding an OpenLayers.Protocol.Response object. │ │ │ │ │ + * visibilitychanged - Triggered when the layer's visibility property is │ │ │ │ │ + * changed, e.g. by turning the layer on or off in the layer switcher. │ │ │ │ │ + * Note that the actual visibility of the layer can also change if it │ │ │ │ │ + * gets out of range (see ). If you also want to catch │ │ │ │ │ + * these cases, register for the map's 'changelayer' event instead. │ │ │ │ │ + * move - Triggered when layer moves (triggered with every mousemove │ │ │ │ │ + * during a drag). │ │ │ │ │ + * moveend - Triggered when layer is done moving, object passed as │ │ │ │ │ + * argument has a zoomChanged boolean property which tells that the │ │ │ │ │ + * zoom has changed. │ │ │ │ │ + * added - Triggered after the layer is added to a map. Listeners will │ │ │ │ │ + * receive an object with a *map* property referencing the map and a │ │ │ │ │ + * *layer* property referencing the layer. │ │ │ │ │ + * removed - Triggered after the layer is removed from the map. Listeners │ │ │ │ │ + * will receive an object with a *map* property referencing the map and │ │ │ │ │ + * a *layer* property referencing the layer. │ │ │ │ │ */ │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: gridLayout │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * APIProperty: map │ │ │ │ │ + * {} This variable is set when the layer is added to │ │ │ │ │ + * the map, via the accessor function setMap(). │ │ │ │ │ */ │ │ │ │ │ - gridLayout: null, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: rowSign │ │ │ │ │ - * {Number} 1 for grids starting at the top, -1 for grids starting at the │ │ │ │ │ - * bottom. This is used for several grid index and offset calculations. │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ + * individually by all subclasses. Default is false │ │ │ │ │ */ │ │ │ │ │ - rowSign: null, │ │ │ │ │ + isBaseLayer: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: transitionendEvents │ │ │ │ │ - * {Array} Event names for transitionend │ │ │ │ │ + * Property: alpha │ │ │ │ │ + * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ */ │ │ │ │ │ - transitionendEvents: [ │ │ │ │ │ - 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ - 'oTransitionEnd' │ │ │ │ │ - ], │ │ │ │ │ + alpha: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Grid │ │ │ │ │ - * Create a new grid layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {String} │ │ │ │ │ - * params - {Object} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - this.grid = []; │ │ │ │ │ - this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); │ │ │ │ │ - │ │ │ │ │ - this.initProperties(); │ │ │ │ │ - │ │ │ │ │ - this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; │ │ │ │ │ - }, │ │ │ │ │ + displayInLayerSwitcher: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initProperties │ │ │ │ │ - * Set any properties that depend on the value of singleTile. │ │ │ │ │ - * Currently sets removeBackBufferDelay and className │ │ │ │ │ + * APIProperty: visibility │ │ │ │ │ + * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ */ │ │ │ │ │ - initProperties: function() { │ │ │ │ │ - if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ - this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.options.className === undefined) { │ │ │ │ │ - this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ - 'olLayerGrid'; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + visibility: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ + * APIProperty: attribution │ │ │ │ │ + * {String} Attribution string, displayed when an │ │ │ │ │ + * has been added to the map. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ - OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ - }, │ │ │ │ │ + attribution: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * Called when the layer is removed from the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ + /** │ │ │ │ │ + * Property: inRange │ │ │ │ │ + * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ + * range. This is set in whenever the zoom │ │ │ │ │ + * changes. │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - }, │ │ │ │ │ + inRange: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct the layer and clear the grid. │ │ │ │ │ + * Propery: imageSize │ │ │ │ │ + * {} For layers with a gutter, the image is larger than │ │ │ │ │ + * the tile by twice the gutter in each dimension. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ + imageSize: null, │ │ │ │ │ │ │ │ │ │ - this.grid = null; │ │ │ │ │ - this.tileSize = null; │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + // OPTIONS │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * Refetches tiles with new params merged, keeping a backbuffer. Each │ │ │ │ │ - * loading new tile will have a css class of '.olTileReplacing'. If a │ │ │ │ │ - * stylesheet applies a 'display: none' style to that class, any fade-in │ │ │ │ │ - * transition will not apply, and backbuffers for each tile will be removed │ │ │ │ │ - * as soon as the tile is loaded. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ + /** │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} An optional object whose properties will be set on the layer. │ │ │ │ │ + * Any of the layer properties can be set as a property of the options │ │ │ │ │ + * object and sent to the constructor when the layer is created. │ │ │ │ │ */ │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearGrid │ │ │ │ │ - * Go through and remove all tiles from the grid, calling │ │ │ │ │ - * destroy() on each of them to kill circular references │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ */ │ │ │ │ │ - clearGrid: function() { │ │ │ │ │ - if (this.grid) { │ │ │ │ │ - for (var iRow = 0, len = this.grid.length; iRow < len; iRow++) { │ │ │ │ │ - var row = this.grid[iRow]; │ │ │ │ │ - for (var iCol = 0, clen = row.length; iCol < clen; iCol++) { │ │ │ │ │ - var tile = row[iCol]; │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.grid = []; │ │ │ │ │ - this.gridResolution = null; │ │ │ │ │ - this.gridLayout = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + eventListeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addOptions │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newOptions - {Object} │ │ │ │ │ - * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ - * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ - * sure that it is displayed with a valid resolution, and a │ │ │ │ │ - * changebaselayer event will be triggered. │ │ │ │ │ + * APIProperty: gutter │ │ │ │ │ + * {Integer} Determines the width (in pixels) of the gutter around image │ │ │ │ │ + * tiles to ignore. By setting this property to a non-zero value, │ │ │ │ │ + * images will be requested that are wider and taller than the tile │ │ │ │ │ + * size by a value of 2 x gutter. This allows artifacts of rendering │ │ │ │ │ + * at tile edges to be ignored. Set a gutter value that is equal to │ │ │ │ │ + * half the size of the widest symbol that needs to be displayed. │ │ │ │ │ + * Defaults to zero. Non-tiled layers always have zero gutter. │ │ │ │ │ */ │ │ │ │ │ - addOptions: function(newOptions, reinitialize) { │ │ │ │ │ - var singleTileChanged = newOptions.singleTile !== undefined && │ │ │ │ │ - newOptions.singleTile !== this.singleTile; │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); │ │ │ │ │ - if (this.map && singleTileChanged) { │ │ │ │ │ - this.initProperties(); │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - this.tileSize = this.options.tileSize; │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - this.moveTo(null, true); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + gutter: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Is this ever used? │ │ │ │ │ + * APIProperty: projection │ │ │ │ │ + * {} or {} Specifies the projection of the layer. │ │ │ │ │ + * Can be set in the layer options. If not specified in the layer options, │ │ │ │ │ + * it is set to the default projection specified in the map, │ │ │ │ │ + * when the layer is added to the map. │ │ │ │ │ + * Projection along with default maxExtent and resolutions │ │ │ │ │ + * are set automatically with commercial baselayers in EPSG:3857, │ │ │ │ │ + * such as Google, Bing and OpenStreetMap, and do not need to be specified. │ │ │ │ │ + * Otherwise, if specifying projection, also set maxExtent, │ │ │ │ │ + * maxResolution or resolutions as appropriate. │ │ │ │ │ + * When using vector layers with strategies, layer projection should be set │ │ │ │ │ + * to the projection of the source data if that is different from the map default. │ │ │ │ │ + * │ │ │ │ │ + * Can be either a string or an object; │ │ │ │ │ + * if a string is passed, will be converted to an object when │ │ │ │ │ + * the layer is added to the map. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - if (this.tileSize != null) { │ │ │ │ │ - obj.tileSize = this.tileSize.clone(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // we do not want to copy reference to grid, so we make a new array │ │ │ │ │ - obj.grid = []; │ │ │ │ │ - obj.gridResolution = null; │ │ │ │ │ - // same for backbuffer │ │ │ │ │ - obj.backBuffer = null; │ │ │ │ │ - obj.backBufferTimerId = null; │ │ │ │ │ - obj.loading = false; │ │ │ │ │ - obj.numLoadingTiles = 0; │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + projection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * This function is called whenever the map is moved. All the moving │ │ │ │ │ - * of actual 'tiles' is done by the map, but moveTo's role is to accept │ │ │ │ │ - * a bounds and make sure the data that that bounds requires is pre-loaded. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * APIProperty: units │ │ │ │ │ + * {String} The layer map units. Defaults to null. Possible values │ │ │ │ │ + * are 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'. │ │ │ │ │ + * Normally taken from the projection. │ │ │ │ │ + * Only required if both map and layers do not define a projection, │ │ │ │ │ + * or if they define a projection which does not define units. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - bounds = bounds || this.map.getExtent(); │ │ │ │ │ - │ │ │ │ │ - if (bounds != null) { │ │ │ │ │ - │ │ │ │ │ - // if grid is empty or zoom has changed, we *must* re-tile │ │ │ │ │ - var forceReTile = !this.grid.length || zoomChanged; │ │ │ │ │ - │ │ │ │ │ - // total bounds of the tiles │ │ │ │ │ - var tilesBounds = this.getTilesBounds(); │ │ │ │ │ - │ │ │ │ │ - // the new map resolution │ │ │ │ │ - var resolution = this.map.getResolution(); │ │ │ │ │ - │ │ │ │ │ - // the server-supported resolution for the new map resolution │ │ │ │ │ - var serverResolution = this.getServerResolution(resolution); │ │ │ │ │ - │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - │ │ │ │ │ - // We want to redraw whenever even the slightest part of the │ │ │ │ │ - // current bounds is not contained by our tile. │ │ │ │ │ - // (thus, we do not specify partial -- its default is false) │ │ │ │ │ - │ │ │ │ │ - if (forceReTile || │ │ │ │ │ - (!dragging && !tilesBounds.containsBounds(bounds))) { │ │ │ │ │ - │ │ │ │ │ - // In single tile mode with no transition effect, we insert │ │ │ │ │ - // a non-scaled backbuffer when the layer is moved. But if │ │ │ │ │ - // a zoom occurs right after a move, i.e. before the new │ │ │ │ │ - // image is received, we need to remove the backbuffer, or │ │ │ │ │ - // an ill-positioned image will be visible during the zoom │ │ │ │ │ - // transition. │ │ │ │ │ - │ │ │ │ │ - if (zoomChanged && this.transitionEffect !== 'resize') { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!zoomChanged || this.transitionEffect === 'resize') { │ │ │ │ │ - this.applyBackBuffer(resolution); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.initSingleTile(bounds); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - │ │ │ │ │ - // if the bounds have changed such that they are not even │ │ │ │ │ - // *partially* contained by our tiles (e.g. when user has │ │ │ │ │ - // programmatically panned to the other side of the earth on │ │ │ │ │ - // zoom level 18), then moveGriddedTiles could potentially have │ │ │ │ │ - // to run through thousands of cycles, so we want to reTile │ │ │ │ │ - // instead (thus, partial true). │ │ │ │ │ - forceReTile = forceReTile || │ │ │ │ │ - !tilesBounds.intersectsBounds(bounds, { │ │ │ │ │ - worldBounds: this.map.baseLayer.wrapDateLine && │ │ │ │ │ - this.map.getMaxExtent() │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (forceReTile) { │ │ │ │ │ - if (zoomChanged && (this.transitionEffect === 'resize' || │ │ │ │ │ - this.gridResolution === resolution)) { │ │ │ │ │ - this.applyBackBuffer(resolution); │ │ │ │ │ - } │ │ │ │ │ - this.initGriddedTiles(bounds); │ │ │ │ │ - } else { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + units: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileData │ │ │ │ │ - * Given a map location, retrieve a tile and the pixel offset within that │ │ │ │ │ - * tile corresponding to the location. If there is not an existing │ │ │ │ │ - * tile in the grid that covers the given location, null will be │ │ │ │ │ - * returned. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * loc - {} map location │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Object with the following properties: tile ({}), │ │ │ │ │ - * i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel │ │ │ │ │ - * offset from top left). │ │ │ │ │ - */ │ │ │ │ │ - getTileData: function(loc) { │ │ │ │ │ - var data = null, │ │ │ │ │ - x = loc.lon, │ │ │ │ │ - y = loc.lat, │ │ │ │ │ - numRows = this.grid.length; │ │ │ │ │ - │ │ │ │ │ - if (this.map && numRows) { │ │ │ │ │ - var res = this.map.getResolution(), │ │ │ │ │ - tileWidth = this.tileSize.w, │ │ │ │ │ - tileHeight = this.tileSize.h, │ │ │ │ │ - bounds = this.grid[0][0].bounds, │ │ │ │ │ - left = bounds.left, │ │ │ │ │ - top = bounds.top; │ │ │ │ │ - │ │ │ │ │ - if (x < left) { │ │ │ │ │ - // deal with multiple worlds │ │ │ │ │ - if (this.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var worldWidth = this.map.getMaxExtent().getWidth(); │ │ │ │ │ - var worldsAway = Math.ceil((left - x) / worldWidth); │ │ │ │ │ - x += worldWidth * worldsAway; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // tile distance to location (fractional number of tiles); │ │ │ │ │ - var dtx = (x - left) / (res * tileWidth); │ │ │ │ │ - var dty = (top - y) / (res * tileHeight); │ │ │ │ │ - // index of tile in grid │ │ │ │ │ - var col = Math.floor(dtx); │ │ │ │ │ - var row = Math.floor(dty); │ │ │ │ │ - if (row >= 0 && row < numRows) { │ │ │ │ │ - var tile = this.grid[row][col]; │ │ │ │ │ - if (tile) { │ │ │ │ │ - data = { │ │ │ │ │ - tile: tile, │ │ │ │ │ - // pixel index within tile │ │ │ │ │ - i: Math.floor((dtx - col) * tileWidth), │ │ │ │ │ - j: Math.floor((dty - row) * tileHeight) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return data; │ │ │ │ │ - }, │ │ │ │ │ + * APIProperty: scales │ │ │ │ │ + * {Array} An array of map scales in descending order. The values in the │ │ │ │ │ + * array correspond to the map scale denominator. Note that these │ │ │ │ │ + * values only make sense if the display (monitor) resolution of the │ │ │ │ │ + * client is correctly guessed by whomever is configuring the │ │ │ │ │ + * application. In addition, the units property must also be set. │ │ │ │ │ + * Use instead wherever possible. │ │ │ │ │ + */ │ │ │ │ │ + scales: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyTile │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + * APIProperty: resolutions │ │ │ │ │ + * {Array} A list of map resolutions (map units per pixel) in descending │ │ │ │ │ + * order. If this is not set in the layer constructor, it will be set │ │ │ │ │ + * based on other resolution related properties (maxExtent, │ │ │ │ │ + * maxResolution, maxScale, etc.). │ │ │ │ │ */ │ │ │ │ │ - destroyTile: function(tile) { │ │ │ │ │ - this.removeTileMonitoringHooks(tile); │ │ │ │ │ - tile.destroy(); │ │ │ │ │ - }, │ │ │ │ │ + resolutions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getServerResolution │ │ │ │ │ - * Return the closest server-supported resolution. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resolution - {Number} The base resolution. If undefined the │ │ │ │ │ - * map resolution is used. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The closest server resolution value. │ │ │ │ │ + * APIProperty: maxExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The maximum extent for the layer. Defaults to null. │ │ │ │ │ + * │ │ │ │ │ + * The center of these bounds will not stray outside │ │ │ │ │ + * of the viewport extent during panning. In addition, if │ │ │ │ │ + * is set to false, data will not be │ │ │ │ │ + * requested that falls completely outside of these bounds. │ │ │ │ │ */ │ │ │ │ │ - getServerResolution: function(resolution) { │ │ │ │ │ - var distance = Number.POSITIVE_INFINITY; │ │ │ │ │ - resolution = resolution || this.map.getResolution(); │ │ │ │ │ - if (this.serverResolutions && │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) { │ │ │ │ │ - var i, newDistance, newResolution, serverResolution; │ │ │ │ │ - for (i = this.serverResolutions.length - 1; i >= 0; i--) { │ │ │ │ │ - newResolution = this.serverResolutions[i]; │ │ │ │ │ - newDistance = Math.abs(newResolution - resolution); │ │ │ │ │ - if (newDistance > distance) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - distance = newDistance; │ │ │ │ │ - serverResolution = newResolution; │ │ │ │ │ - } │ │ │ │ │ - resolution = serverResolution; │ │ │ │ │ - } │ │ │ │ │ - return resolution; │ │ │ │ │ - }, │ │ │ │ │ + maxExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getServerZoom │ │ │ │ │ - * Return the zoom value corresponding to the best matching server │ │ │ │ │ - * resolution, taking into account and . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The closest server supported zoom. This is not the map zoom │ │ │ │ │ - * level, but an index of the server's resolutions array. │ │ │ │ │ + * APIProperty: minExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The minimum extent for the layer. Defaults to null. │ │ │ │ │ */ │ │ │ │ │ - getServerZoom: function() { │ │ │ │ │ - var resolution = this.getServerResolution(); │ │ │ │ │ - return this.serverResolutions ? │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ - this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ - }, │ │ │ │ │ + minExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: applyBackBuffer │ │ │ │ │ - * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resolution - {Number} The resolution to transition to. │ │ │ │ │ + * APIProperty: maxResolution │ │ │ │ │ + * {Float} Default max is 360 deg / 256 px, which corresponds to │ │ │ │ │ + * zoom level 0 on gmaps. Specify a different value in the layer │ │ │ │ │ + * options if you are not using the default │ │ │ │ │ + * and displaying the whole world. │ │ │ │ │ */ │ │ │ │ │ - applyBackBuffer: function(resolution) { │ │ │ │ │ - if (this.backBufferTimerId !== null) { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - } │ │ │ │ │ - var backBuffer = this.backBuffer; │ │ │ │ │ - if (!backBuffer) { │ │ │ │ │ - backBuffer = this.createBackBuffer(); │ │ │ │ │ - if (!backBuffer) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (resolution === this.gridResolution) { │ │ │ │ │ - this.div.insertBefore(backBuffer, this.div.firstChild); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.baseLayer.div.parentNode.insertBefore(backBuffer, this.map.baseLayer.div); │ │ │ │ │ - } │ │ │ │ │ - this.backBuffer = backBuffer; │ │ │ │ │ - │ │ │ │ │ - // set some information in the instance for subsequent │ │ │ │ │ - // calls to applyBackBuffer where the same back buffer │ │ │ │ │ - // is reused │ │ │ │ │ - var topLeftTileBounds = this.grid[0][0].bounds; │ │ │ │ │ - this.backBufferLonLat = { │ │ │ │ │ - lon: topLeftTileBounds.left, │ │ │ │ │ - lat: topLeftTileBounds.top │ │ │ │ │ - }; │ │ │ │ │ - this.backBufferResolution = this.gridResolution; │ │ │ │ │ - } │ │ │ │ │ + maxResolution: null, │ │ │ │ │ │ │ │ │ │ - var ratio = this.backBufferResolution / resolution; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minResolution │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minResolution: null, │ │ │ │ │ │ │ │ │ │ - // scale the tiles inside the back buffer │ │ │ │ │ - var tiles = backBuffer.childNodes, │ │ │ │ │ - tile; │ │ │ │ │ - for (var i = tiles.length - 1; i >= 0; --i) { │ │ │ │ │ - tile = tiles[i]; │ │ │ │ │ - tile.style.top = ((ratio * tile._i * tile._h) | 0) + 'px'; │ │ │ │ │ - tile.style.left = ((ratio * tile._j * tile._w) | 0) + 'px'; │ │ │ │ │ - tile.style.width = Math.round(ratio * tile._w) + 'px'; │ │ │ │ │ - tile.style.height = Math.round(ratio * tile._h) + 'px'; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ + numZoomLevels: null, │ │ │ │ │ │ │ │ │ │ - // and position it (based on the grid's top-left corner) │ │ │ │ │ - var position = this.getViewPortPxFromLonLat( │ │ │ │ │ - this.backBufferLonLat, resolution); │ │ │ │ │ - var leftOffset = this.map.layerContainerOriginPx.x; │ │ │ │ │ - var topOffset = this.map.layerContainerOriginPx.y; │ │ │ │ │ - backBuffer.style.left = Math.round(position.x - leftOffset) + 'px'; │ │ │ │ │ - backBuffer.style.top = Math.round(position.y - topOffset) + 'px'; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minScale: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * Create a back buffer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ - * grid isn't initialized yet. │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - createBackBuffer: function() { │ │ │ │ │ - var backBuffer; │ │ │ │ │ - if (this.grid.length > 0) { │ │ │ │ │ - backBuffer = document.createElement('div'); │ │ │ │ │ - backBuffer.id = this.div.id + '_bb'; │ │ │ │ │ - backBuffer.className = 'olBackBuffer'; │ │ │ │ │ - backBuffer.style.position = 'absolute'; │ │ │ │ │ - var map = this.map; │ │ │ │ │ - backBuffer.style.zIndex = this.transitionEffect === 'resize' ? │ │ │ │ │ - this.getZIndex() - 1 : │ │ │ │ │ - // 'map-resize': │ │ │ │ │ - map.Z_INDEX_BASE.BaseLayer - │ │ │ │ │ - (map.getNumLayers() - map.getLayerIndex(this)); │ │ │ │ │ - for (var i = 0, lenI = this.grid.length; i < lenI; i++) { │ │ │ │ │ - for (var j = 0, lenJ = this.grid[i].length; j < lenJ; j++) { │ │ │ │ │ - var tile = this.grid[i][j], │ │ │ │ │ - markup = this.grid[i][j].createBackBuffer(); │ │ │ │ │ - if (markup) { │ │ │ │ │ - markup._i = i; │ │ │ │ │ - markup._j = j; │ │ │ │ │ - markup._w = tile.size.w; │ │ │ │ │ - markup._h = tile.size.h; │ │ │ │ │ - markup.id = tile.id + '_bb'; │ │ │ │ │ - backBuffer.appendChild(markup); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return backBuffer; │ │ │ │ │ - }, │ │ │ │ │ + maxScale: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeBackBuffer │ │ │ │ │ - * Remove back buffer from DOM. │ │ │ │ │ + * APIProperty: displayOutsideMaxExtent │ │ │ │ │ + * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ + * extent for this layer. Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - removeBackBuffer: function() { │ │ │ │ │ - if (this._transitionElement) { │ │ │ │ │ - for (var i = this.transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ - OpenLayers.Event.stopObserving(this._transitionElement, │ │ │ │ │ - this.transitionendEvents[i], this._removeBackBuffer); │ │ │ │ │ - } │ │ │ │ │ - delete this._transitionElement; │ │ │ │ │ - } │ │ │ │ │ - if (this.backBuffer) { │ │ │ │ │ - if (this.backBuffer.parentNode) { │ │ │ │ │ - this.backBuffer.parentNode.removeChild(this.backBuffer); │ │ │ │ │ - } │ │ │ │ │ - this.backBuffer = null; │ │ │ │ │ - this.backBufferResolution = null; │ │ │ │ │ - if (this.backBufferTimerId !== null) { │ │ │ │ │ - window.clearTimeout(this.backBufferTimerId); │ │ │ │ │ - this.backBufferTimerId = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + displayOutsideMaxExtent: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} │ │ │ │ │ - * dy - {Number} │ │ │ │ │ + * APIProperty: wrapDateLine │ │ │ │ │ + * {Boolean} Wraps the world at the international dateline, so the map can │ │ │ │ │ + * be panned infinitely in longitudinal direction. Only use this on the │ │ │ │ │ + * base layer, and only if the layer's maxExtent equals the world bounds. │ │ │ │ │ + * #487 for more info. │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - if (!this.singleTile) { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + wrapDateLine: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Check if we are in singleTile mode and if so, set the size as a ratio │ │ │ │ │ - * of the map size (as specified by the layer's 'ratio' property). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + * Property: metadata │ │ │ │ │ + * {Object} This object can be used to store additional information on a │ │ │ │ │ + * layer object. │ │ │ │ │ */ │ │ │ │ │ - setTileSize: function(size) { │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - size.h = parseInt(size.h * this.ratio, 10); │ │ │ │ │ - size.w = parseInt(size.w * this.ratio, 10); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]); │ │ │ │ │ - }, │ │ │ │ │ + metadata: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTilesBounds │ │ │ │ │ - * Return the bounds of the tile grid. │ │ │ │ │ + * Constructor: OpenLayers.Layer │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object representing the bounds of all the │ │ │ │ │ - * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ - * onscreen). │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} The layer name │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - getTilesBounds: function() { │ │ │ │ │ - var bounds = null; │ │ │ │ │ + initialize: function(name, options) { │ │ │ │ │ │ │ │ │ │ - var length = this.grid.length; │ │ │ │ │ - if (length) { │ │ │ │ │ - var bottomLeftTileBounds = this.grid[length - 1][0].bounds, │ │ │ │ │ - width = this.grid[0].length * bottomLeftTileBounds.getWidth(), │ │ │ │ │ - height = this.grid.length * bottomLeftTileBounds.getHeight(); │ │ │ │ │ + this.metadata = {}; │ │ │ │ │ │ │ │ │ │ - bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ - bottomLeftTileBounds.bottom, │ │ │ │ │ - bottomLeftTileBounds.left + width, │ │ │ │ │ - bottomLeftTileBounds.bottom + height); │ │ │ │ │ + options = OpenLayers.Util.extend({}, options); │ │ │ │ │ + // make sure we respect alwaysInRange if set on the prototype │ │ │ │ │ + if (this.alwaysInRange != null) { │ │ │ │ │ + options.alwaysInRange = this.alwaysInRange; │ │ │ │ │ } │ │ │ │ │ - return bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: initSingleTile │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - initSingleTile: function(bounds) { │ │ │ │ │ - this.events.triggerEvent("retile"); │ │ │ │ │ + this.addOptions(options); │ │ │ │ │ │ │ │ │ │ - //determine new tile bounds │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ - var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ + this.name = name; │ │ │ │ │ │ │ │ │ │ - var tileBounds = │ │ │ │ │ - new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ - center.lat - (tileHeight / 2), │ │ │ │ │ - center.lon + (tileWidth / 2), │ │ │ │ │ - center.lat + (tileHeight / 2)); │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ - lon: tileBounds.left, │ │ │ │ │ - lat: tileBounds.top │ │ │ │ │ - }); │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ │ │ │ │ │ - if (!this.grid.length) { │ │ │ │ │ - this.grid[0] = []; │ │ │ │ │ - } │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.style.width = "100%"; │ │ │ │ │ + this.div.style.height = "100%"; │ │ │ │ │ + this.div.dir = "ltr"; │ │ │ │ │ │ │ │ │ │ - var tile = this.grid[0][0]; │ │ │ │ │ - if (!tile) { │ │ │ │ │ - tile = this.addTile(tileBounds, px); │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.addTileMonitoringHooks(tile); │ │ │ │ │ - tile.draw(); │ │ │ │ │ - this.grid[0][0] = tile; │ │ │ │ │ - } else { │ │ │ │ │ - tile.moveTo(tileBounds, px); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //remove all but our single tile │ │ │ │ │ - this.removeExcessTiles(1, 1); │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy is a destructor: this is to alleviate cyclic references which │ │ │ │ │ + * the Javascript garbage cleaner can not take care of on its own. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * setNewBaseLayer - {Boolean} Set a new base layer when this layer has │ │ │ │ │ + * been destroyed. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function(setNewBaseLayer) { │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ + } │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.removeLayer(this, setNewBaseLayer); │ │ │ │ │ + } │ │ │ │ │ + this.projection = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ + this.name = null; │ │ │ │ │ + this.div = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ │ │ │ │ │ - // store the resolution of the grid │ │ │ │ │ - this.gridResolution = this.getServerResolution(); │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateGridLayout │ │ │ │ │ - * Generate parameters for the grid layout. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {|Object} OpenLayers.Bounds or an │ │ │ │ │ - * object with a 'left' and 'top' properties. │ │ │ │ │ - * origin - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * resolution - {Number} │ │ │ │ │ + * obj - {} The layer to be cloned │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ */ │ │ │ │ │ - calculateGridLayout: function(bounds, origin, resolution) { │ │ │ │ │ - var tilelon = resolution * this.tileSize.w; │ │ │ │ │ - var tilelat = resolution * this.tileSize.h; │ │ │ │ │ - │ │ │ │ │ - var offsetlon = bounds.left - origin.lon; │ │ │ │ │ - var tilecol = Math.floor(offsetlon / tilelon) - this.buffer; │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - var rowSign = this.rowSign; │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var offsetlat = rowSign * (origin.lat - bounds.top + tilelat); │ │ │ │ │ - var tilerow = Math[~rowSign ? 'floor' : 'ceil'](offsetlat / tilelat) - this.buffer * rowSign; │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ │ │ │ │ │ - return { │ │ │ │ │ - tilelon: tilelon, │ │ │ │ │ - tilelat: tilelat, │ │ │ │ │ - startcol: tilecol, │ │ │ │ │ - startrow: tilerow │ │ │ │ │ - }; │ │ │ │ │ + // a cloned layer should never have its map property set │ │ │ │ │ + // because it has not been added to a map yet. │ │ │ │ │ + obj.map = null; │ │ │ │ │ │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileOrigin │ │ │ │ │ - * Determine the origin for aligning the grid of tiles. If a │ │ │ │ │ - * property is supplied, that will be returned. Otherwise, the origin │ │ │ │ │ - * will be derived from the layer's property. In this case, │ │ │ │ │ - * the tile origin will be the corner of the given by the │ │ │ │ │ - * property. │ │ │ │ │ - * │ │ │ │ │ + * Method: getOptions │ │ │ │ │ + * Extracts an object from the layer with the properties that were set as │ │ │ │ │ + * options, but updates them with the values currently set on the │ │ │ │ │ + * instance. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The tile origin. │ │ │ │ │ + * {Object} the of the layer, representing the current state. │ │ │ │ │ */ │ │ │ │ │ - getTileOrigin: function() { │ │ │ │ │ - var origin = this.tileOrigin; │ │ │ │ │ - if (!origin) { │ │ │ │ │ - var extent = this.getMaxExtent(); │ │ │ │ │ - var edges = ({ │ │ │ │ │ - "tl": ["left", "top"], │ │ │ │ │ - "tr": ["right", "top"], │ │ │ │ │ - "bl": ["left", "bottom"], │ │ │ │ │ - "br": ["right", "bottom"] │ │ │ │ │ - })[this.tileOriginCorner]; │ │ │ │ │ - origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]); │ │ │ │ │ + getOptions: function() { │ │ │ │ │ + var options = {}; │ │ │ │ │ + for (var o in this.options) { │ │ │ │ │ + options[o] = this[o]; │ │ │ │ │ } │ │ │ │ │ - return origin; │ │ │ │ │ + return options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getTileBoundsForGridIndex │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setName │ │ │ │ │ + * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ + * on the map. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * row - {Number} The row of the grid │ │ │ │ │ - * col - {Number} The column of the grid │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The bounds for the tile at (row, col) │ │ │ │ │ + * newName - {String} The new name. │ │ │ │ │ */ │ │ │ │ │ - getTileBoundsForGridIndex: function(row, col) { │ │ │ │ │ - var origin = this.getTileOrigin(); │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ + setName: function(newName) { │ │ │ │ │ + if (newName != this.name) { │ │ │ │ │ + this.name = newName; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "name" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initGriddedTiles │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * newOptions - {Object} │ │ │ │ │ + * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ + * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ + * sure that it is displayed with a valid resolution, and a │ │ │ │ │ + * changebaselayer event will be triggered. │ │ │ │ │ */ │ │ │ │ │ - initGriddedTiles: function(bounds) { │ │ │ │ │ - this.events.triggerEvent("retile"); │ │ │ │ │ - │ │ │ │ │ - // work out mininum number of rows and columns; this is the number of │ │ │ │ │ - // tiles required to cover the viewport plus at least one for panning │ │ │ │ │ - │ │ │ │ │ - var viewSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - var origin = this.getTileOrigin(); │ │ │ │ │ - var resolution = this.map.getResolution(), │ │ │ │ │ - serverResolution = this.getServerResolution(), │ │ │ │ │ - ratio = resolution / serverResolution, │ │ │ │ │ - tileSize = { │ │ │ │ │ - w: this.tileSize.w / ratio, │ │ │ │ │ - h: this.tileSize.h / ratio │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - var minRows = Math.ceil(viewSize.h / tileSize.h) + │ │ │ │ │ - 2 * this.buffer + 1; │ │ │ │ │ - var minCols = Math.ceil(viewSize.w / tileSize.w) + │ │ │ │ │ - 2 * this.buffer + 1; │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ │ │ │ │ │ - var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ - this.gridLayout = tileLayout; │ │ │ │ │ + if (this.options == null) { │ │ │ │ │ + this.options = {}; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var tilelon = tileLayout.tilelon; │ │ │ │ │ - var tilelat = tileLayout.tilelat; │ │ │ │ │ + if (newOptions) { │ │ │ │ │ + // make sure this.projection references a projection object │ │ │ │ │ + if (typeof newOptions.projection == "string") { │ │ │ │ │ + newOptions.projection = new OpenLayers.Projection(newOptions.projection); │ │ │ │ │ + } │ │ │ │ │ + if (newOptions.projection) { │ │ │ │ │ + // get maxResolution, units and maxExtent from projection defaults if │ │ │ │ │ + // they are not defined already │ │ │ │ │ + OpenLayers.Util.applyDefaults(newOptions, │ │ │ │ │ + OpenLayers.Projection.defaults[newOptions.projection.getCode()]); │ │ │ │ │ + } │ │ │ │ │ + // allow array for extents │ │ │ │ │ + if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent); │ │ │ │ │ + } │ │ │ │ │ + if (newOptions.minExtent && !(newOptions.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + newOptions.minExtent = new OpenLayers.Bounds(newOptions.minExtent); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ - var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ + // update our copy for clone │ │ │ │ │ + OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ │ │ │ │ │ - var tileBounds = this.getTileBoundsForGridIndex(0, 0); │ │ │ │ │ - var startPx = this.map.getViewPortPxFromLonLat( │ │ │ │ │ - new OpenLayers.LonLat(tileBounds.left, tileBounds.top) │ │ │ │ │ - ); │ │ │ │ │ - startPx.x = Math.round(startPx.x) - layerContainerDivLeft; │ │ │ │ │ - startPx.y = Math.round(startPx.y) - layerContainerDivTop; │ │ │ │ │ + // add new options to this │ │ │ │ │ + OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ │ │ │ │ │ - var tileData = [], │ │ │ │ │ - center = this.map.getCenter(); │ │ │ │ │ + // get the units from the projection, if we have a projection │ │ │ │ │ + // and it it has units │ │ │ │ │ + if (this.projection && this.projection.getUnits()) { │ │ │ │ │ + this.units = this.projection.getUnits(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var rowidx = 0; │ │ │ │ │ - do { │ │ │ │ │ - var row = this.grid[rowidx]; │ │ │ │ │ - if (!row) { │ │ │ │ │ - row = []; │ │ │ │ │ - this.grid.push(row); │ │ │ │ │ - } │ │ │ │ │ + // re-initialize resolutions if necessary, i.e. if any of the │ │ │ │ │ + // properties of the "properties" array defined below is set │ │ │ │ │ + // in the new options │ │ │ │ │ + if (this.map) { │ │ │ │ │ + // store current resolution so we can try to restore it later │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ + var properties = this.RESOLUTION_PROPERTIES.concat( │ │ │ │ │ + ["projection", "units", "minExtent", "maxExtent"] │ │ │ │ │ + ); │ │ │ │ │ + for (var o in newOptions) { │ │ │ │ │ + if (newOptions.hasOwnProperty(o) && │ │ │ │ │ + OpenLayers.Util.indexOf(properties, o) >= 0) { │ │ │ │ │ │ │ │ │ │ - var colidx = 0; │ │ │ │ │ - do { │ │ │ │ │ - tileBounds = this.getTileBoundsForGridIndex(rowidx, colidx); │ │ │ │ │ - var px = startPx.clone(); │ │ │ │ │ - px.x = px.x + colidx * Math.round(tileSize.w); │ │ │ │ │ - px.y = px.y + rowidx * Math.round(tileSize.h); │ │ │ │ │ - var tile = row[colidx]; │ │ │ │ │ - if (!tile) { │ │ │ │ │ - tile = this.addTile(tileBounds, px); │ │ │ │ │ - this.addTileMonitoringHooks(tile); │ │ │ │ │ - row.push(tile); │ │ │ │ │ - } else { │ │ │ │ │ - tile.moveTo(tileBounds, px, false); │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ + if (reinitialize && this.map.baseLayer === this) { │ │ │ │ │ + // update map position, and restore previous resolution │ │ │ │ │ + this.map.setCenter(this.map.getCenter(), │ │ │ │ │ + this.map.getZoomForResolution(resolution), │ │ │ │ │ + false, true │ │ │ │ │ + ); │ │ │ │ │ + // trigger a changebaselayer event to make sure that │ │ │ │ │ + // all controls (especially │ │ │ │ │ + // OpenLayers.Control.PanZoomBar) get notified of the │ │ │ │ │ + // new options │ │ │ │ │ + this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - var tileCenter = tileBounds.getCenterLonLat(); │ │ │ │ │ - tileData.push({ │ │ │ │ │ - tile: tile, │ │ │ │ │ - distance: Math.pow(tileCenter.lon - center.lon, 2) + │ │ │ │ │ - Math.pow(tileCenter.lat - center.lat, 2) │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - colidx += 1; │ │ │ │ │ - } while ((tileBounds.right <= bounds.right + tilelon * this.buffer) || │ │ │ │ │ - colidx < minCols); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: onMapResize │ │ │ │ │ + * This function can be implemented by subclasses │ │ │ │ │ + */ │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + //this function can be implemented by subclasses │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - rowidx += 1; │ │ │ │ │ - } while ((tileBounds.bottom >= bounds.bottom - tilelat * this.buffer) || │ │ │ │ │ - rowidx < minRows); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ + */ │ │ │ │ │ + redraw: function() { │ │ │ │ │ + var redrawn = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ │ │ │ │ │ - //shave off exceess rows and colums │ │ │ │ │ - this.removeExcessTiles(rowidx, colidx); │ │ │ │ │ + // min/max Range may have changed │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ │ │ │ │ │ - var resolution = this.getServerResolution(); │ │ │ │ │ - // store the resolution of the grid │ │ │ │ │ - this.gridResolution = resolution; │ │ │ │ │ + // map's center might not yet be set │ │ │ │ │ + var extent = this.getExtent(); │ │ │ │ │ │ │ │ │ │ - //now actually draw the tiles │ │ │ │ │ - tileData.sort(function(a, b) { │ │ │ │ │ - return a.distance - b.distance; │ │ │ │ │ - }); │ │ │ │ │ - for (var i = 0, ii = tileData.length; i < ii; ++i) { │ │ │ │ │ - tileData[i].tile.draw(); │ │ │ │ │ + if (extent && this.inRange && this.visibility) { │ │ │ │ │ + var zoomChanged = true; │ │ │ │ │ + this.moveTo(extent, zoomChanged, false); │ │ │ │ │ + this.events.triggerEvent("moveend", { │ │ │ │ │ + "zoomChanged": zoomChanged │ │ │ │ │ + }); │ │ │ │ │ + redrawn = true; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return redrawn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMaxExtent │ │ │ │ │ - * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ - * potential specific implementations in sub-classes.) │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ + * do some init work in that case. │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - getMaxExtent: function() { │ │ │ │ │ - return this.maxExtent; │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ + var display = this.visibility; │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + display = display && this.inRange; │ │ │ │ │ + } │ │ │ │ │ + this.display(display); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addTile │ │ │ │ │ - * Create a tile, initialize it, and add it to the layer div. │ │ │ │ │ - * │ │ │ │ │ - * Parameters │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * position - {} │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The added OpenLayers.Tile │ │ │ │ │ + * Parameters: │ │ │ │ │ + * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ + * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ */ │ │ │ │ │ - addTile: function(bounds, position) { │ │ │ │ │ - var tile = new this.tileClass( │ │ │ │ │ - this, position, bounds, null, this.tileSize, this.tileOptions │ │ │ │ │ - ); │ │ │ │ │ - this.events.triggerEvent("addtile", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - return tile; │ │ │ │ │ - }, │ │ │ │ │ + moveByPx: function(dx, dy) {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addTileMonitoringHooks │ │ │ │ │ - * This function takes a tile as input and adds the appropriate hooks to │ │ │ │ │ - * the tile so that the layer can keep track of the loading tiles. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the layer. This is done through an accessor │ │ │ │ │ + * so that subclasses can override this and take special action once │ │ │ │ │ + * they have their map variable set. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + * Here we take care to bring over any of the necessary default │ │ │ │ │ + * properties from the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - addTileMonitoringHooks: function(tile) { │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + if (this.map == null) { │ │ │ │ │ │ │ │ │ │ - var replacingCls = 'olTileReplacing'; │ │ │ │ │ + this.map = map; │ │ │ │ │ │ │ │ │ │ - tile.onLoadStart = function() { │ │ │ │ │ - //if that was first tile then trigger a 'loadstart' on the layer │ │ │ │ │ - if (this.loading === false) { │ │ │ │ │ - this.loading = true; │ │ │ │ │ - this.events.triggerEvent("loadstart"); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("tileloadstart", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - this.numLoadingTiles++; │ │ │ │ │ - if (!this.singleTile && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ - OpenLayers.Element.addClass(tile.getTile(), replacingCls); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ + // grab some essential layer data from the map if it hasn't already │ │ │ │ │ + // been set │ │ │ │ │ + this.maxExtent = this.maxExtent || this.map.maxExtent; │ │ │ │ │ + this.minExtent = this.minExtent || this.map.minExtent; │ │ │ │ │ │ │ │ │ │ - tile.onLoadEnd = function(evt) { │ │ │ │ │ - this.numLoadingTiles--; │ │ │ │ │ - var aborted = evt.type === 'unload'; │ │ │ │ │ - this.events.triggerEvent("tileloaded", { │ │ │ │ │ - tile: tile, │ │ │ │ │ - aborted: aborted │ │ │ │ │ - }); │ │ │ │ │ - if (!this.singleTile && !aborted && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ - var tileDiv = tile.getTile(); │ │ │ │ │ - if (OpenLayers.Element.getStyle(tileDiv, 'display') === 'none') { │ │ │ │ │ - var bufferTile = document.getElementById(tile.id + '_bb'); │ │ │ │ │ - if (bufferTile) { │ │ │ │ │ - bufferTile.parentNode.removeChild(bufferTile); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Element.removeClass(tileDiv, replacingCls); │ │ │ │ │ - } │ │ │ │ │ - //if that was the last tile, then trigger a 'loadend' on the layer │ │ │ │ │ - if (this.numLoadingTiles === 0) { │ │ │ │ │ - if (this.backBuffer) { │ │ │ │ │ - if (this.backBuffer.childNodes.length === 0) { │ │ │ │ │ - // no tiles transitioning, remove immediately │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - } else { │ │ │ │ │ - // wait until transition has ended or delay has passed │ │ │ │ │ - this._transitionElement = aborted ? │ │ │ │ │ - this.div.lastChild : tile.imgDiv; │ │ │ │ │ - var transitionendEvents = this.transitionendEvents; │ │ │ │ │ - for (var i = transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ - OpenLayers.Event.observe(this._transitionElement, │ │ │ │ │ - transitionendEvents[i], │ │ │ │ │ - this._removeBackBuffer); │ │ │ │ │ - } │ │ │ │ │ - // the removal of the back buffer is delayed to prevent │ │ │ │ │ - // flash effects due to the animation of tile displaying │ │ │ │ │ - this.backBufferTimerId = window.setTimeout( │ │ │ │ │ - this._removeBackBuffer, this.removeBackBufferDelay │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.loading = false; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ + this.projection = this.projection || this.map.projection; │ │ │ │ │ + if (typeof this.projection == "string") { │ │ │ │ │ + this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ │ │ │ │ │ - tile.onLoadError = function() { │ │ │ │ │ - this.events.triggerEvent("tileerror", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ + // Check the projection to see if we can get units -- if not, refer │ │ │ │ │ + // to properties. │ │ │ │ │ + this.units = this.projection.getUnits() || │ │ │ │ │ + this.units || this.map.units; │ │ │ │ │ │ │ │ │ │ - tile.events.on({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - "loaderror": tile.onLoadError, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ + │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ + var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ + this.div.style.display = show ? "" : "none"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // deal with gutters │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTileMonitoringHooks │ │ │ │ │ - * This function takes a tile as input and removes the tile hooks │ │ │ │ │ - * that were added in addTileMonitoringHooks() │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + /** │ │ │ │ │ + * Method: afterAdd │ │ │ │ │ + * Called at the end of the map.addLayer sequence. At this point, the map │ │ │ │ │ + * will have a base layer. To be overridden by subclasses. │ │ │ │ │ */ │ │ │ │ │ - removeTileMonitoringHooks: function(tile) { │ │ │ │ │ - tile.unload(); │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - "loaderror": tile.onLoadError, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + afterAdd: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveGriddedTiles │ │ │ │ │ + * APIMethod: removeMap │ │ │ │ │ + * Just as setMap() allows each layer the possibility to take a │ │ │ │ │ + * personalized action on being added to the map, removeMap() allows │ │ │ │ │ + * each layer to take a personalized action on being removed from it. │ │ │ │ │ + * For now, this will be mostly unused, except for the EventPane layer, │ │ │ │ │ + * which needs this hook so that it can remove the special invisible │ │ │ │ │ + * pane. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - moveGriddedTiles: function() { │ │ │ │ │ - var buffer = this.buffer + 1; │ │ │ │ │ - while (true) { │ │ │ │ │ - var tlTile = this.grid[0][0]; │ │ │ │ │ - var tlViewPort = { │ │ │ │ │ - x: tlTile.position.x + │ │ │ │ │ - this.map.layerContainerOriginPx.x, │ │ │ │ │ - y: tlTile.position.y + │ │ │ │ │ - this.map.layerContainerOriginPx.y │ │ │ │ │ - }; │ │ │ │ │ - var ratio = this.getServerResolution() / this.map.getResolution(); │ │ │ │ │ - var tileSize = { │ │ │ │ │ - w: Math.round(this.tileSize.w * ratio), │ │ │ │ │ - h: Math.round(this.tileSize.h * ratio) │ │ │ │ │ - }; │ │ │ │ │ - if (tlViewPort.x > -tileSize.w * (buffer - 1)) { │ │ │ │ │ - this.shiftColumn(true, tileSize); │ │ │ │ │ - } else if (tlViewPort.x < -tileSize.w * buffer) { │ │ │ │ │ - this.shiftColumn(false, tileSize); │ │ │ │ │ - } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) { │ │ │ │ │ - this.shiftRow(true, tileSize); │ │ │ │ │ - } else if (tlViewPort.y < -tileSize.h * buffer) { │ │ │ │ │ - this.shiftRow(false, tileSize); │ │ │ │ │ - } else { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + //to be overridden by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shiftRow │ │ │ │ │ - * Shifty grid work │ │ │ │ │ + * APIMethod: getImageSize │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ - * if false, then append to end │ │ │ │ │ - * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ + * bounds - {} optional tile bounds, can be used │ │ │ │ │ + * by subclasses that have to deal with different tile sizes at the │ │ │ │ │ + * layer extent edges (e.g. Zoomify) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The size that the image should be, taking into │ │ │ │ │ + * account gutters. │ │ │ │ │ */ │ │ │ │ │ - shiftRow: function(prepend, tileSize) { │ │ │ │ │ - var grid = this.grid; │ │ │ │ │ - var rowIndex = prepend ? 0 : (grid.length - 1); │ │ │ │ │ - var sign = prepend ? -1 : 1; │ │ │ │ │ - var rowSign = this.rowSign; │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - tileLayout.startrow += sign * rowSign; │ │ │ │ │ - │ │ │ │ │ - var modelRow = grid[rowIndex]; │ │ │ │ │ - var row = grid[prepend ? 'pop' : 'shift'](); │ │ │ │ │ - for (var i = 0, len = row.length; i < len; i++) { │ │ │ │ │ - var tile = row[i]; │ │ │ │ │ - var position = modelRow[i].position.clone(); │ │ │ │ │ - position.y += tileSize.h * sign; │ │ │ │ │ - tile.moveTo(this.getTileBoundsForGridIndex(rowIndex, i), position); │ │ │ │ │ - } │ │ │ │ │ - grid[prepend ? 'unshift' : 'push'](row); │ │ │ │ │ + getImageSize: function(bounds) { │ │ │ │ │ + return (this.imageSize || this.tileSize); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shiftColumn │ │ │ │ │ - * Shift grid work in the other dimension │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setTileSize │ │ │ │ │ + * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ + * or use by Tile.Image. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ - * if false, then append to end │ │ │ │ │ - * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ - shiftColumn: function(prepend, tileSize) { │ │ │ │ │ - var grid = this.grid; │ │ │ │ │ - var colIndex = prepend ? 0 : (grid[0].length - 1); │ │ │ │ │ - var sign = prepend ? -1 : 1; │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - tileLayout.startcol += sign; │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = grid.length; i < len; i++) { │ │ │ │ │ - var row = grid[i]; │ │ │ │ │ - var position = row[colIndex].position.clone(); │ │ │ │ │ - var tile = row[prepend ? 'pop' : 'shift'](); │ │ │ │ │ - position.x += tileSize.w * sign; │ │ │ │ │ - tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position); │ │ │ │ │ - row[prepend ? 'unshift' : 'push'](tile); │ │ │ │ │ + setTileSize: function(size) { │ │ │ │ │ + var tileSize = (size) ? size : │ │ │ │ │ + ((this.tileSize) ? this.tileSize : │ │ │ │ │ + this.map.getTileSize()); │ │ │ │ │ + this.tileSize = tileSize; │ │ │ │ │ + if (this.gutter) { │ │ │ │ │ + // layers with gutters need non-null tile sizes │ │ │ │ │ + //if(tileSize == null) { │ │ │ │ │ + // OpenLayers.console.error("Error in layer.setMap() for " + │ │ │ │ │ + // this.name + ": layers with " + │ │ │ │ │ + // "gutters need non-null tile sizes"); │ │ │ │ │ + //} │ │ │ │ │ + this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter), │ │ │ │ │ + tileSize.h + (2 * this.gutter)); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeExcessTiles │ │ │ │ │ - * When the size of the map or the buffer changes, we may need to │ │ │ │ │ - * remove some excess rows and columns. │ │ │ │ │ + * APIMethod: getVisibility │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * rows - {Integer} Maximum number of rows we want our grid to have. │ │ │ │ │ - * columns - {Integer} Maximum number of columns we want our grid to have. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ */ │ │ │ │ │ - removeExcessTiles: function(rows, columns) { │ │ │ │ │ - var i, l; │ │ │ │ │ + getVisibility: function() { │ │ │ │ │ + return this.visibility; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // remove extra rows │ │ │ │ │ - while (this.grid.length > rows) { │ │ │ │ │ - var row = this.grid.pop(); │ │ │ │ │ - for (i = 0, l = row.length; i < l; i++) { │ │ │ │ │ - var tile = row[i]; │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setVisibility │ │ │ │ │ + * Set the visibility flag for the layer and hide/show & redraw │ │ │ │ │ + * accordingly. Fire event unless otherwise specified │ │ │ │ │ + * │ │ │ │ │ + * Note that visibility is no longer simply whether or not the layer's │ │ │ │ │ + * style.display is set to "block". Now we store a 'visibility' state │ │ │ │ │ + * property on the layer class, this allows us to remember whether or │ │ │ │ │ + * not we *desire* for a layer to be visible. In the case where the │ │ │ │ │ + * map's resolution is out of the layer's range, this desire may be │ │ │ │ │ + * subverted. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * visibility - {Boolean} Whether or not to display the layer (if in range) │ │ │ │ │ + */ │ │ │ │ │ + setVisibility: function(visibility) { │ │ │ │ │ + if (visibility != this.visibility) { │ │ │ │ │ + this.visibility = visibility; │ │ │ │ │ + this.display(visibility); │ │ │ │ │ + this.redraw(); │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "visibility" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + this.events.triggerEvent("visibilitychanged"); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // remove extra columns │ │ │ │ │ - for (i = 0, l = this.grid.length; i < l; i++) { │ │ │ │ │ - while (this.grid[i].length > columns) { │ │ │ │ │ - var row = this.grid[i]; │ │ │ │ │ - var tile = row.pop(); │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: display │ │ │ │ │ + * Hide or show the Layer. This is designed to be used internally, and │ │ │ │ │ + * is not generally the way to enable or disable the layer. For that, │ │ │ │ │ + * use the setVisibility function instead.. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + if (display != (this.div.style.display != "none")) { │ │ │ │ │ + this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMapResize │ │ │ │ │ - * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ - * dimensions of the map pane. │ │ │ │ │ + * APIMethod: calculateInRange │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer is displayable at the current map's current │ │ │ │ │ + * resolution. Note that if 'alwaysInRange' is true for the layer, │ │ │ │ │ + * this function will always return true. │ │ │ │ │ */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ + calculateInRange: function() { │ │ │ │ │ + var inRange = false; │ │ │ │ │ + │ │ │ │ │ + if (this.alwaysInRange) { │ │ │ │ │ + inRange = true; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ + inRange = ((resolution >= this.minResolution) && │ │ │ │ │ + (resolution <= this.maxResolution)); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return inRange; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getTileBounds │ │ │ │ │ - * Returns The tile bounds for a layer given a pixel location. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setIsBaseLayer │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * viewPortPx - {} The location in the viewport. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Bounds of the tile at the given pixel location. │ │ │ │ │ + * isBaseLayer - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - getTileBounds: function(viewPortPx) { │ │ │ │ │ - var maxExtent = this.maxExtent; │ │ │ │ │ - var resolution = this.getResolution(); │ │ │ │ │ - var tileMapWidth = resolution * this.tileSize.w; │ │ │ │ │ - var tileMapHeight = resolution * this.tileSize.h; │ │ │ │ │ - var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ - var tileLeft = maxExtent.left + (tileMapWidth * │ │ │ │ │ - Math.floor((mapPoint.lon - │ │ │ │ │ - maxExtent.left) / │ │ │ │ │ - tileMapWidth)); │ │ │ │ │ - var tileBottom = maxExtent.bottom + (tileMapHeight * │ │ │ │ │ - Math.floor((mapPoint.lat - │ │ │ │ │ - maxExtent.bottom) / │ │ │ │ │ - tileMapHeight)); │ │ │ │ │ - return new OpenLayers.Bounds(tileLeft, tileBottom, │ │ │ │ │ - tileLeft + tileMapWidth, │ │ │ │ │ - tileBottom + tileMapHeight); │ │ │ │ │ + setIsBaseLayer: function(isBaseLayer) { │ │ │ │ │ + if (isBaseLayer != this.isBaseLayer) { │ │ │ │ │ + this.isBaseLayer = isBaseLayer; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/TileManager.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Baselayer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: initResolutions │ │ │ │ │ + * This method's responsibility is to set up the 'resolutions' array │ │ │ │ │ + * for the layer -- this array is what the layer will use to interface │ │ │ │ │ + * between the zoom levels of the map and the resolution display │ │ │ │ │ + * of the layer. │ │ │ │ │ + * │ │ │ │ │ + * The user has several options that determine how the array is set up. │ │ │ │ │ + * │ │ │ │ │ + * For a detailed explanation, see the following wiki from the │ │ │ │ │ + * openlayers.org homepage: │ │ │ │ │ + * http://trac.openlayers.org/wiki/SettingZoomLevels │ │ │ │ │ + */ │ │ │ │ │ + initResolutions: function() { │ │ │ │ │ │ │ │ │ │ + // ok we want resolutions, here's our strategy: │ │ │ │ │ + // │ │ │ │ │ + // 1. if resolutions are defined in the layer config, use them │ │ │ │ │ + // 2. else, if scales are defined in the layer config then derive │ │ │ │ │ + // resolutions from these scales │ │ │ │ │ + // 3. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ + // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ + // layer config │ │ │ │ │ + // 4. if we still don't have resolutions, and if resolutions │ │ │ │ │ + // are defined in the same, use them │ │ │ │ │ + // 5. else, if scales are defined in the map then derive │ │ │ │ │ + // resolutions from these scales │ │ │ │ │ + // 6. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ + // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ + // map │ │ │ │ │ + // 7. hope for the best! │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ - */ │ │ │ │ │ + var i, len, p; │ │ │ │ │ + var props = {}, │ │ │ │ │ + alwaysInRange = true; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.TileManager │ │ │ │ │ - * Provides queueing of image requests and caching of image elements. │ │ │ │ │ - * │ │ │ │ │ - * Queueing avoids unnecessary image requests while changing zoom levels │ │ │ │ │ - * quickly, and helps improve dragging performance on mobile devices that show │ │ │ │ │ - * a lag in dragging when loading of new images starts. and │ │ │ │ │ - * are the configuration options to control this behavior. │ │ │ │ │ - * │ │ │ │ │ - * Caching avoids setting the src on image elements for images that have already │ │ │ │ │ - * been used. Several maps can share a TileManager instance, in which case each │ │ │ │ │ - * map gets its own tile queue, but all maps share the same tile cache. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.TileManager = OpenLayers.Class({ │ │ │ │ │ + // get resolution data from layer config │ │ │ │ │ + // (we also set alwaysInRange in the layer as appropriate) │ │ │ │ │ + for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ + p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ + props[p] = this.options[p]; │ │ │ │ │ + if (alwaysInRange && this.options[p]) { │ │ │ │ │ + alwaysInRange = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.options.alwaysInRange == null) { │ │ │ │ │ + this.alwaysInRange = alwaysInRange; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: cacheSize │ │ │ │ │ - * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ - * cache for fast reuse. Default is 256. │ │ │ │ │ - */ │ │ │ │ │ - cacheSize: 256, │ │ │ │ │ + // if we don't have resolutions then attempt to derive them from scales │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tilesPerFrame │ │ │ │ │ - * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ - * Default is 2. │ │ │ │ │ - */ │ │ │ │ │ - tilesPerFrame: 2, │ │ │ │ │ + // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: frameDelay │ │ │ │ │ - * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ - * milliseconds. Default is 16. │ │ │ │ │ - */ │ │ │ │ │ - frameDelay: 16, │ │ │ │ │ + // if we couldn't calculate resolutions then we look at we have │ │ │ │ │ + // in the map │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ + p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ + props[p] = this.options[p] != null ? │ │ │ │ │ + this.options[p] : this.map[p]; │ │ │ │ │ + } │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ + } │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: moveDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ - * tiles. Default is 100. │ │ │ │ │ - */ │ │ │ │ │ - moveDelay: 100, │ │ │ │ │ + // ok, we new need to set properties in the instance │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ - * tiles. Default is 200. │ │ │ │ │ - */ │ │ │ │ │ - zoomDelay: 200, │ │ │ │ │ + // get maxResolution from the config if it's defined there │ │ │ │ │ + var maxResolution; │ │ │ │ │ + if (this.options.maxResolution && │ │ │ │ │ + this.options.maxResolution !== "auto") { │ │ │ │ │ + maxResolution = this.options.maxResolution; │ │ │ │ │ + } │ │ │ │ │ + if (this.options.minScale) { │ │ │ │ │ + maxResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.options.minScale, this.units); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: maps │ │ │ │ │ - * {Array()} The maps to manage tiles on. │ │ │ │ │ - */ │ │ │ │ │ - maps: null, │ │ │ │ │ + // get minResolution from the config if it's defined there │ │ │ │ │ + var minResolution; │ │ │ │ │ + if (this.options.minResolution && │ │ │ │ │ + this.options.minResolution !== "auto") { │ │ │ │ │ + minResolution = this.options.minResolution; │ │ │ │ │ + } │ │ │ │ │ + if (this.options.maxScale) { │ │ │ │ │ + minResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.options.maxScale, this.units); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueueId │ │ │ │ │ - * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueueId: null, │ │ │ │ │ + if (props.resolutions) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueue │ │ │ │ │ - * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ - * map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueue: null, │ │ │ │ │ + //sort resolutions array descendingly │ │ │ │ │ + props.resolutions.sort(function(a, b) { │ │ │ │ │ + return (b - a); │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileCache │ │ │ │ │ - * {Object} Cached image elements, keyed by URL. │ │ │ │ │ - */ │ │ │ │ │ - tileCache: null, │ │ │ │ │ + // if we still don't have a maxResolution get it from the │ │ │ │ │ + // resolutions array │ │ │ │ │ + if (!maxResolution) { │ │ │ │ │ + maxResolution = props.resolutions[0]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileCacheIndex │ │ │ │ │ - * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ - * used. │ │ │ │ │ - */ │ │ │ │ │ - tileCacheIndex: null, │ │ │ │ │ + // if we still don't have a minResolution get it from the │ │ │ │ │ + // resolutions array │ │ │ │ │ + if (!minResolution) { │ │ │ │ │ + var lastIdx = props.resolutions.length - 1; │ │ │ │ │ + minResolution = props.resolutions[lastIdx]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.TileManager │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Configuration for this instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.maps = []; │ │ │ │ │ - this.tileQueueId = {}; │ │ │ │ │ - this.tileQueue = {}; │ │ │ │ │ - this.tileCache = {}; │ │ │ │ │ - this.tileCacheIndex = []; │ │ │ │ │ + this.resolutions = props.resolutions; │ │ │ │ │ + if (this.resolutions) { │ │ │ │ │ + len = this.resolutions.length; │ │ │ │ │ + this.scales = new Array(len); │ │ │ │ │ + for (i = 0; i < len; i++) { │ │ │ │ │ + this.scales[i] = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + this.resolutions[i], this.units); │ │ │ │ │ + } │ │ │ │ │ + this.numZoomLevels = len; │ │ │ │ │ + } │ │ │ │ │ + this.minResolution = minResolution; │ │ │ │ │ + if (minResolution) { │ │ │ │ │ + this.maxScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + minResolution, this.units); │ │ │ │ │ + } │ │ │ │ │ + this.maxResolution = maxResolution; │ │ │ │ │ + if (maxResolution) { │ │ │ │ │ + this.minScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + maxResolution, this.units); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addMap │ │ │ │ │ - * Binds this instance to a map │ │ │ │ │ + * Method: resolutionsFromScales │ │ │ │ │ + * Derive resolutions from scales. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * scales - {Array(Number)} Scales │ │ │ │ │ + * │ │ │ │ │ + * Returns │ │ │ │ │ + * {Array(Number)} Resolutions │ │ │ │ │ */ │ │ │ │ │ - addMap: function(map) { │ │ │ │ │ - if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + resolutionsFromScales: function(scales) { │ │ │ │ │ + if (scales == null) { │ │ │ │ │ return; │ │ │ │ │ } │ │ │ │ │ - this.maps.push(map); │ │ │ │ │ - this.tileQueue[map.id] = []; │ │ │ │ │ - for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: map.layers[i] │ │ │ │ │ - }); │ │ │ │ │ + var resolutions, i, len; │ │ │ │ │ + len = scales.length; │ │ │ │ │ + resolutions = new Array(len); │ │ │ │ │ + for (i = 0; i < len; i++) { │ │ │ │ │ + resolutions[i] = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + scales[i], this.units); │ │ │ │ │ } │ │ │ │ │ - map.events.on({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + return resolutions; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * Unbinds this instance from a map │ │ │ │ │ + * Method: calculateResolutions │ │ │ │ │ + * Calculate resolutions based on the provided properties. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * props - {Object} Properties │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array({Number})} Array of resolutions. │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + calculateResolutions: function(props) { │ │ │ │ │ + │ │ │ │ │ + var viewSize, wRes, hRes; │ │ │ │ │ + │ │ │ │ │ + // determine maxResolution │ │ │ │ │ + var maxResolution = props.maxResolution; │ │ │ │ │ + if (props.minScale != null) { │ │ │ │ │ + maxResolution = │ │ │ │ │ + OpenLayers.Util.getResolutionFromScale(props.minScale, │ │ │ │ │ + this.units); │ │ │ │ │ + } else if (maxResolution == "auto" && this.maxExtent != null) { │ │ │ │ │ + viewSize = this.map.getSize(); │ │ │ │ │ + wRes = this.maxExtent.getWidth() / viewSize.w; │ │ │ │ │ + hRes = this.maxExtent.getHeight() / viewSize.h; │ │ │ │ │ + maxResolution = Math.max(wRes, hRes); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // determine minResolution │ │ │ │ │ + var minResolution = props.minResolution; │ │ │ │ │ + if (props.maxScale != null) { │ │ │ │ │ + minResolution = │ │ │ │ │ + OpenLayers.Util.getResolutionFromScale(props.maxScale, │ │ │ │ │ + this.units); │ │ │ │ │ + } else if (props.minResolution == "auto" && this.minExtent != null) { │ │ │ │ │ + viewSize = this.map.getSize(); │ │ │ │ │ + wRes = this.minExtent.getWidth() / viewSize.w; │ │ │ │ │ + hRes = this.minExtent.getHeight() / viewSize.h; │ │ │ │ │ + minResolution = Math.max(wRes, hRes); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (typeof maxResolution !== "number" && │ │ │ │ │ + typeof minResolution !== "number" && │ │ │ │ │ + this.maxExtent != null) { │ │ │ │ │ + // maxResolution for default grid sets assumes that at zoom │ │ │ │ │ + // level zero, the whole world fits on one tile. │ │ │ │ │ + var tileSize = this.map.getTileSize(); │ │ │ │ │ + maxResolution = Math.max( │ │ │ │ │ + this.maxExtent.getWidth() / tileSize.w, │ │ │ │ │ + this.maxExtent.getHeight() / tileSize.h │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // determine numZoomLevels │ │ │ │ │ + var maxZoomLevel = props.maxZoomLevel; │ │ │ │ │ + var numZoomLevels = props.numZoomLevels; │ │ │ │ │ + if (typeof minResolution === "number" && │ │ │ │ │ + typeof maxResolution === "number" && numZoomLevels === undefined) { │ │ │ │ │ + var ratio = maxResolution / minResolution; │ │ │ │ │ + numZoomLevels = Math.floor(Math.log(ratio) / Math.log(2)) + 1; │ │ │ │ │ + } else if (numZoomLevels === undefined && maxZoomLevel != null) { │ │ │ │ │ + numZoomLevels = maxZoomLevel + 1; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // are we able to calculate resolutions? │ │ │ │ │ + if (typeof numZoomLevels !== "number" || numZoomLevels <= 0 || │ │ │ │ │ + (typeof maxResolution !== "number" && │ │ │ │ │ + typeof minResolution !== "number")) { │ │ │ │ │ return; │ │ │ │ │ } │ │ │ │ │ - window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ - if (map.layers) { │ │ │ │ │ - for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: map.layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + // now we have numZoomLevels and at least one of maxResolution │ │ │ │ │ + // or minResolution, we can populate the resolutions array │ │ │ │ │ + │ │ │ │ │ + var resolutions = new Array(numZoomLevels); │ │ │ │ │ + var base = 2; │ │ │ │ │ + if (typeof minResolution == "number" && │ │ │ │ │ + typeof maxResolution == "number") { │ │ │ │ │ + // if maxResolution and minResolution are set, we calculate │ │ │ │ │ + // the base for exponential scaling that starts at │ │ │ │ │ + // maxResolution and ends at minResolution in numZoomLevels │ │ │ │ │ + // steps. │ │ │ │ │ + base = Math.pow( │ │ │ │ │ + (maxResolution / minResolution), │ │ │ │ │ + (1 / (numZoomLevels - 1)) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - if (map.events) { │ │ │ │ │ - map.events.un({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + │ │ │ │ │ + var i; │ │ │ │ │ + if (typeof maxResolution === "number") { │ │ │ │ │ + for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ + resolutions[i] = maxResolution / Math.pow(base, i); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ + resolutions[numZoomLevels - 1 - i] = │ │ │ │ │ + minResolution * Math.pow(base, i); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - delete this.tileQueue[map.id]; │ │ │ │ │ - delete this.tileQueueId[map.id]; │ │ │ │ │ - OpenLayers.Util.removeItem(this.maps, map); │ │ │ │ │ + │ │ │ │ │ + return resolutions; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handles the map's move event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + * APIMethod: getResolution │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ + * resolutions array, indexed by current zoom level. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + var zoom = this.map.getZoom(); │ │ │ │ │ + return this.getResolutionForZoom(zoom); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: zoomEnd │ │ │ │ │ - * Handles the map's zoomEnd event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ */ │ │ │ │ │ - zoomEnd: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ + // means it will user map's current center & resolution │ │ │ │ │ + // │ │ │ │ │ + return this.map.calculateBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: changeLayer │ │ │ │ │ - * Handles the map's changeLayer event │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getZoomForExtent │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + * extent - {} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ + * for the passed-in extent. We do this by calculating the ideal │ │ │ │ │ + * resolution for the given extent (based on the map size) and then │ │ │ │ │ + * calling getZoomForResolution(), passing along the 'closest' │ │ │ │ │ + * parameter. │ │ │ │ │ */ │ │ │ │ │ - changeLayer: function(evt) { │ │ │ │ │ - if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ - this.updateTimeout(evt.object, 0); │ │ │ │ │ - } │ │ │ │ │ + getZoomForExtent: function(extent, closest) { │ │ │ │ │ + var viewSize = this.map.getSize(); │ │ │ │ │ + var idealResolution = Math.max(extent.getWidth() / viewSize.w, │ │ │ │ │ + extent.getHeight() / viewSize.h); │ │ │ │ │ + │ │ │ │ │ + return this.getZoomForResolution(idealResolution, closest); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getDataExtent │ │ │ │ │ + * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ + * This function is to be implemented by subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getDataExtent: function() { │ │ │ │ │ + //to be implemented by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Handles the map's addlayer event │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - var layer = evt.layer; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - layer.events.on({ │ │ │ │ │ - addtile: this.addTile, │ │ │ │ │ - retile: this.clearTileQueue, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - var i, j, tile; │ │ │ │ │ - for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ - for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ - tile = layer.grid[i][j]; │ │ │ │ │ - this.addTile({ │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - if (tile.url && !tile.imgDiv) { │ │ │ │ │ - this.manageTileCache({ │ │ │ │ │ - object: tile │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getResolutionForZoom: function(zoom) { │ │ │ │ │ + zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1)); │ │ │ │ │ + var resolution; │ │ │ │ │ + if (this.map.fractionalZoom) { │ │ │ │ │ + var low = Math.floor(zoom); │ │ │ │ │ + var high = Math.ceil(zoom); │ │ │ │ │ + resolution = this.resolutions[low] - │ │ │ │ │ + ((zoom - low) * (this.resolutions[low] - this.resolutions[high])); │ │ │ │ │ + } else { │ │ │ │ │ + resolution = this.resolutions[Math.round(zoom)]; │ │ │ │ │ } │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Handles the map's preremovelayer event │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getZoomForResolution │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * resolution - {Float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ + * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ + * resolution is actually smaller than we would have desired (if this │ │ │ │ │ + * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ + * the returned zoom index might not actually contain the entire │ │ │ │ │ + * extent specified... but it'll be close). │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ + * that corresponds to the best fit resolution given the passed in │ │ │ │ │ + * value and the 'closest' specification. │ │ │ │ │ */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - var layer = evt.layer; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - this.clearTileQueue({ │ │ │ │ │ - object: layer │ │ │ │ │ - }); │ │ │ │ │ - if (layer.events) { │ │ │ │ │ - layer.events.un({ │ │ │ │ │ - addtile: this.addTile, │ │ │ │ │ - retile: this.clearTileQueue, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + getZoomForResolution: function(resolution, closest) { │ │ │ │ │ + var zoom, i, len; │ │ │ │ │ + if (this.map.fractionalZoom) { │ │ │ │ │ + var lowZoom = 0; │ │ │ │ │ + var highZoom = this.resolutions.length - 1; │ │ │ │ │ + var highRes = this.resolutions[lowZoom]; │ │ │ │ │ + var lowRes = this.resolutions[highZoom]; │ │ │ │ │ + var res; │ │ │ │ │ + for (i = 0, len = this.resolutions.length; i < len; ++i) { │ │ │ │ │ + res = this.resolutions[i]; │ │ │ │ │ + if (res >= resolution) { │ │ │ │ │ + highRes = res; │ │ │ │ │ + lowZoom = i; │ │ │ │ │ + } │ │ │ │ │ + if (res <= resolution) { │ │ │ │ │ + lowRes = res; │ │ │ │ │ + highZoom = i; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (layer.grid) { │ │ │ │ │ - var i, j, tile; │ │ │ │ │ - for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ - for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ - tile = layer.grid[i][j]; │ │ │ │ │ - this.unloadTile({ │ │ │ │ │ - object: tile │ │ │ │ │ - }); │ │ │ │ │ + var dRes = highRes - lowRes; │ │ │ │ │ + if (dRes > 0) { │ │ │ │ │ + zoom = lowZoom + ((highRes - resolution) / dRes); │ │ │ │ │ + } else { │ │ │ │ │ + zoom = lowZoom; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var diff; │ │ │ │ │ + var minDiff = Number.POSITIVE_INFINITY; │ │ │ │ │ + for (i = 0, len = this.resolutions.length; i < len; i++) { │ │ │ │ │ + if (closest) { │ │ │ │ │ + diff = Math.abs(this.resolutions[i] - resolution); │ │ │ │ │ + if (diff > minDiff) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + minDiff = diff; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.resolutions[i] < resolution) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + zoom = Math.max(0, i - 1); │ │ │ │ │ } │ │ │ │ │ + return zoom; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateTimeout │ │ │ │ │ - * Applies the or to the loop, │ │ │ │ │ - * and schedules more queue processing after if there are still │ │ │ │ │ - * tiles in the queue. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getLonLatFromViewPortPx │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} The map to update the timeout for │ │ │ │ │ - * delay - {Number} The delay to apply │ │ │ │ │ - * nice - {Boolean} If true, the timeout function will only be created if │ │ │ │ │ - * the tilequeue is not empty. This is used by the move handler to │ │ │ │ │ - * avoid impacts on dragging performance. For other events, the tile │ │ │ │ │ - * queue may not be populated yet, so we need to set the timer │ │ │ │ │ - * regardless of the queue size. │ │ │ │ │ - */ │ │ │ │ │ - updateTimeout: function(map, delay, nice) { │ │ │ │ │ - window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ - var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ - if (!nice || tileQueue.length) { │ │ │ │ │ - this.tileQueueId[map.id] = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.drawTilesFromQueue(map); │ │ │ │ │ - if (tileQueue.length) { │ │ │ │ │ - this.updateTimeout(map, this.frameDelay); │ │ │ │ │ - } │ │ │ │ │ - }, this), delay │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addTile │ │ │ │ │ - * Listener for the layer's addtile event │ │ │ │ │ + * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ + * an object with a 'x' │ │ │ │ │ + * and 'y' properties. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.LonLat which is the passed-in │ │ │ │ │ + * view port , translated into lon/lat by the layer. │ │ │ │ │ */ │ │ │ │ │ - addTile: function(evt) { │ │ │ │ │ - if (evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ - evt.tile.events.on({ │ │ │ │ │ - beforedraw: this.queueTileDraw, │ │ │ │ │ - beforeload: this.manageTileCache, │ │ │ │ │ - loadend: this.addToCache, │ │ │ │ │ - unload: this.unloadTile, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - // Layer has the wrong tile type, so don't handle it any longer │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: evt.tile.layer │ │ │ │ │ + getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var lonlat = null; │ │ │ │ │ + var map = this.map; │ │ │ │ │ + if (viewPortPx != null && map.minPx) { │ │ │ │ │ + var res = map.getResolution(); │ │ │ │ │ + var maxExtent = map.getMaxExtent({ │ │ │ │ │ + restricted: true │ │ │ │ │ }); │ │ │ │ │ + var lon = (viewPortPx.x - map.minPx.x) * res + maxExtent.left; │ │ │ │ │ + var lat = (map.minPx.y - viewPortPx.y) * res + maxExtent.top; │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ + │ │ │ │ │ + if (this.wrapDateLine) { │ │ │ │ │ + lonlat = lonlat.wrapDateLine(this.maxExtent); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return lonlat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unloadTile │ │ │ │ │ - * Listener for the tile's unload event │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ + * Returns a pixel location given a map location. This method will return │ │ │ │ │ + * fractional pixel values. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * lonlat - {|Object} An OpenLayers.LonLat or │ │ │ │ │ + * an object with a 'lon' │ │ │ │ │ + * and 'lat' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An which is the passed-in │ │ │ │ │ + * lonlat translated into view port pixels. │ │ │ │ │ */ │ │ │ │ │ - unloadTile: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - beforedraw: this.queueTileDraw, │ │ │ │ │ - beforeload: this.manageTileCache, │ │ │ │ │ - loadend: this.addToCache, │ │ │ │ │ - unload: this.unloadTile, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileQueue[tile.layer.map.id], tile); │ │ │ │ │ + getViewPortPxFromLonLat: function(lonlat, resolution) { │ │ │ │ │ + var px = null; │ │ │ │ │ + if (lonlat != null) { │ │ │ │ │ + resolution = resolution || this.map.getResolution(); │ │ │ │ │ + var extent = this.map.calculateBounds(null, resolution); │ │ │ │ │ + px = new OpenLayers.Pixel( │ │ │ │ │ + (1 / resolution * (lonlat.lon - extent.left)), │ │ │ │ │ + (1 / resolution * (extent.top - lonlat.lat)) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return px; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: queueTileDraw │ │ │ │ │ - * Adds a tile to the queue that will draw it. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setOpacity │ │ │ │ │ + * Sets the opacity for the entire layer (all images) │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ + * opacity - {Float} │ │ │ │ │ */ │ │ │ │ │ - queueTileDraw: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - var queued = false; │ │ │ │ │ - var layer = tile.layer; │ │ │ │ │ - var url = layer.getURL(tile.bounds); │ │ │ │ │ - var img = this.tileCache[url]; │ │ │ │ │ - if (img && img.className !== 'olTileImage') { │ │ │ │ │ - // cached image no longer valid, e.g. because we're olTileReplacing │ │ │ │ │ - delete this.tileCache[url]; │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileCacheIndex, url); │ │ │ │ │ - img = null; │ │ │ │ │ - } │ │ │ │ │ - // queue only if image with same url not cached already │ │ │ │ │ - if (layer.url && (layer.async || !img)) { │ │ │ │ │ - // add to queue only if not in queue already │ │ │ │ │ - var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ - if (!~OpenLayers.Util.indexOf(tileQueue, tile)) { │ │ │ │ │ - tileQueue.push(tile); │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + if (opacity != this.opacity) { │ │ │ │ │ + this.opacity = opacity; │ │ │ │ │ + var childNodes = this.div.childNodes; │ │ │ │ │ + for (var i = 0, len = childNodes.length; i < len; ++i) { │ │ │ │ │ + var element = childNodes[i].firstChild || childNodes[i]; │ │ │ │ │ + var lastChild = childNodes[i].lastChild; │ │ │ │ │ + //TODO de-uglify this │ │ │ │ │ + if (lastChild && lastChild.nodeName.toLowerCase() === "iframe") { │ │ │ │ │ + element = lastChild.parentNode; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.modifyDOMElement(element, null, null, null, │ │ │ │ │ + null, null, null, opacity); │ │ │ │ │ + } │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "opacity" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - queued = true; │ │ │ │ │ } │ │ │ │ │ - return !queued; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawTilesFromQueue │ │ │ │ │ - * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ + * Method: getZIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} the z-index of this layer │ │ │ │ │ */ │ │ │ │ │ - drawTilesFromQueue: function(map) { │ │ │ │ │ - var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ - var limit = this.tilesPerFrame; │ │ │ │ │ - var animating = map.zoomTween && map.zoomTween.playing; │ │ │ │ │ - while (!animating && tileQueue.length && limit) { │ │ │ │ │ - tileQueue.shift().draw(true); │ │ │ │ │ - --limit; │ │ │ │ │ - } │ │ │ │ │ + getZIndex: function() { │ │ │ │ │ + return this.div.style.zIndex; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: manageTileCache │ │ │ │ │ - * Adds, updates, removes and fetches cache entries. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ + * Method: setZIndex │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zIndex - {Integer} │ │ │ │ │ */ │ │ │ │ │ - manageTileCache: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - var img = this.tileCache[tile.url]; │ │ │ │ │ - if (img) { │ │ │ │ │ - // if image is on its layer's backbuffer, remove it from backbuffer │ │ │ │ │ - if (img.parentNode && │ │ │ │ │ - OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer')) { │ │ │ │ │ - img.parentNode.removeChild(img); │ │ │ │ │ - img.id = null; │ │ │ │ │ - } │ │ │ │ │ - // only use image from cache if it is not on a layer already │ │ │ │ │ - if (!img.parentNode) { │ │ │ │ │ - img.style.visibility = 'hidden'; │ │ │ │ │ - img.style.opacity = 0; │ │ │ │ │ - tile.setImage(img); │ │ │ │ │ - // LRU - move tile to the end of the array to mark it as the most │ │ │ │ │ - // recently used │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url); │ │ │ │ │ - this.tileCacheIndex.push(tile.url); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + setZIndex: function(zIndex) { │ │ │ │ │ + this.div.style.zIndex = zIndex; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addToCache │ │ │ │ │ - * │ │ │ │ │ + * Method: adjustBounds │ │ │ │ │ + * This function will take a bounds, and if wrapDateLine option is set │ │ │ │ │ + * on the layer, it will return a bounds which is wrapped around the │ │ │ │ │ + * world. We do not wrap for bounds which *cross* the │ │ │ │ │ + * maxExtent.left/right, only bounds which are entirely to the left │ │ │ │ │ + * or entirely to the right. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - addToCache: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - if (!this.tileCache[tile.url]) { │ │ │ │ │ - if (!OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError')) { │ │ │ │ │ - if (this.tileCacheIndex.length >= this.cacheSize) { │ │ │ │ │ - delete this.tileCache[this.tileCacheIndex[0]]; │ │ │ │ │ - this.tileCacheIndex.shift(); │ │ │ │ │ - } │ │ │ │ │ - this.tileCache[tile.url] = tile.imgDiv; │ │ │ │ │ - this.tileCacheIndex.push(tile.url); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + adjustBounds: function(bounds) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearTileQueue │ │ │ │ │ - * Clears the tile queue from tiles of a specific layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the layer's retile event │ │ │ │ │ - */ │ │ │ │ │ - clearTileQueue: function(evt) { │ │ │ │ │ - var layer = evt.object; │ │ │ │ │ - var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ - for (var i = tileQueue.length - 1; i >= 0; --i) { │ │ │ │ │ - if (tileQueue[i].layer === layer) { │ │ │ │ │ - tileQueue.splice(i, 1); │ │ │ │ │ - } │ │ │ │ │ + if (this.gutter) { │ │ │ │ │ + // Adjust the extent of a bounds in map units by the │ │ │ │ │ + // layer's gutter in pixels. │ │ │ │ │ + var mapGutter = this.gutter * this.map.getResolution(); │ │ │ │ │ + bounds = new OpenLayers.Bounds(bounds.left - mapGutter, │ │ │ │ │ + bounds.bottom - mapGutter, │ │ │ │ │ + bounds.right + mapGutter, │ │ │ │ │ + bounds.top + mapGutter); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = this.maps.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeMap(this.maps[i]); │ │ │ │ │ + if (this.wrapDateLine) { │ │ │ │ │ + // wrap around the date line, within the limits of rounding error │ │ │ │ │ + var wrappingOptions = { │ │ │ │ │ + 'rightTolerance': this.getResolution(), │ │ │ │ │ + 'leftTolerance': this.getResolution() │ │ │ │ │ + }; │ │ │ │ │ + bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions); │ │ │ │ │ + │ │ │ │ │ } │ │ │ │ │ - this.maps = null; │ │ │ │ │ - this.tileQueue = null; │ │ │ │ │ - this.tileQueueId = null; │ │ │ │ │ - this.tileCache = null; │ │ │ │ │ - this.tileCacheIndex = null; │ │ │ │ │ - this._destroyed = true; │ │ │ │ │ - } │ │ │ │ │ + return bounds; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Spherical.js │ │ │ │ │ + OpenLayers/Symbolizer.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Namespace: Spherical │ │ │ │ │ - * The OpenLayers.Spherical namespace includes utility functions for │ │ │ │ │ - * calculations on the basis of a spherical earth (ignoring ellipsoidal │ │ │ │ │ - * effects), which is accurate enough for most purposes. │ │ │ │ │ - * │ │ │ │ │ - * Relevant links: │ │ │ │ │ - * * http://www.movable-type.co.uk/scripts/latlong.html │ │ │ │ │ - * * http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical │ │ │ │ │ + * Class: OpenLayers.Symbolizer │ │ │ │ │ + * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ */ │ │ │ │ │ +OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ │ │ │ │ │ -OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zIndex │ │ │ │ │ + * {Number} The zIndex determines the rendering order for a symbolizer. │ │ │ │ │ + * Symbolizers with larger zIndex values are rendered over symbolizers │ │ │ │ │ + * with smaller zIndex values. Default is 0. │ │ │ │ │ + */ │ │ │ │ │ + zIndex: 0, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: computeDistanceBetween │ │ │ │ │ - * Computes the distance between two LonLats. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ - * a JavaScript literal with lon lat properties. │ │ │ │ │ - * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ - * JavaScript literal with lon lat properties. │ │ │ │ │ - * radius - {Float} The radius. Optional. Defaults to 6378137 meters. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The distance in meters. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Spherical.computeDistanceBetween = function(from, to, radius) { │ │ │ │ │ - var R = radius || OpenLayers.Spherical.DEFAULT_RADIUS; │ │ │ │ │ - var sinHalfDeltaLon = Math.sin(Math.PI * (to.lon - from.lon) / 360); │ │ │ │ │ - var sinHalfDeltaLat = Math.sin(Math.PI * (to.lat - from.lat) / 360); │ │ │ │ │ - var a = sinHalfDeltaLat * sinHalfDeltaLat + │ │ │ │ │ - sinHalfDeltaLon * sinHalfDeltaLon * Math.cos(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ - return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * A new symbolizer. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a copy of this symbolizer. │ │ │ │ │ + * │ │ │ │ │ + * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + var Type = eval(this.CLASS_NAME); │ │ │ │ │ + return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: computeHeading │ │ │ │ │ - * Computes the heading from one LonLat to another LonLat. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ - * a JavaScript literal with lon lat properties. │ │ │ │ │ - * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ - * JavaScript literal with lon lat properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The heading in degrees. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Spherical.computeHeading = function(from, to) { │ │ │ │ │ - var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ - var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) - │ │ │ │ │ - Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180); │ │ │ │ │ - return 180 * Math.atan2(y, x) / Math.PI; │ │ │ │ │ -}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Symbolizer/Point.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ @@ -33365,20153 +27827,16483 @@ │ │ │ │ │ } │ │ │ │ │ return new OpenLayers.Style2(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Marker.js │ │ │ │ │ + OpenLayers/Renderer.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Icon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Marker │ │ │ │ │ - * Instances of OpenLayers.Marker are a combination of a │ │ │ │ │ - * and an . │ │ │ │ │ - * │ │ │ │ │ - * Markers are generally added to a special layer called │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var markers = new OpenLayers.Layer.Markers( "Markers" ); │ │ │ │ │ - * map.addLayer(markers); │ │ │ │ │ - * │ │ │ │ │ - * var size = new OpenLayers.Size(21,25); │ │ │ │ │ - * var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); │ │ │ │ │ - * var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset); │ │ │ │ │ - * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon)); │ │ │ │ │ - * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone())); │ │ │ │ │ + * Class: OpenLayers.Renderer │ │ │ │ │ + * This is the base class for all renderers. │ │ │ │ │ * │ │ │ │ │ - * (end) │ │ │ │ │ + * This is based on a merger code written by Paul Spencer and Bertil Chapuis. │ │ │ │ │ + * It is largely composed of virtual functions that are to be implemented │ │ │ │ │ + * in technology-specific subclasses, but there is some generic code too. │ │ │ │ │ + * │ │ │ │ │ + * The functions that *are* implemented here merely deal with the maintenance │ │ │ │ │ + * of the size and extent variables, as well as the cached 'resolution' │ │ │ │ │ + * value. │ │ │ │ │ + * │ │ │ │ │ + * A note to the user that all subclasses should use getResolution() instead │ │ │ │ │ + * of directly accessing this.resolution in order to correctly use the │ │ │ │ │ + * cacheing system. │ │ │ │ │ * │ │ │ │ │ - * Note that if you pass an icon into the Marker constructor, it will take │ │ │ │ │ - * that icon and use it. This means that you should not share icons between │ │ │ │ │ - * markers -- you use them once, but you should clone() for any additional │ │ │ │ │ - * markers using that same icon. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: icon │ │ │ │ │ - * {} The icon used by this marker. │ │ │ │ │ - */ │ │ │ │ │ - icon: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} location of object │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ +OpenLayers.Renderer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} the event handler. │ │ │ │ │ + * Property: container │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + container: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} the map this marker is attached to │ │ │ │ │ + /** │ │ │ │ │ + * Property: root │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ + root: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Marker │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} the position of this marker │ │ │ │ │ - * icon - {} the icon for this marker │ │ │ │ │ + * Property: extent │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(lonlat, icon) { │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + extent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy the marker. You must first remove the marker from any │ │ │ │ │ - * layer which it has been added to, or you will get buggy behavior. │ │ │ │ │ - * (This can not be done within the marker since the marker does not │ │ │ │ │ - * know which layer it is attached to.) │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // erase any drawn features │ │ │ │ │ - this.erase(); │ │ │ │ │ - │ │ │ │ │ - this.map = null; │ │ │ │ │ - │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.destroy(); │ │ │ │ │ - this.icon = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Calls draw on the icon, and returns that output. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ - * location passed-in │ │ │ │ │ + * Property: locked │ │ │ │ │ + * {Boolean} If the renderer is currently in a state where many things │ │ │ │ │ + * are changing, the 'locked' property is set to true. This means │ │ │ │ │ + * that renderers can expect at least one more drawFeature event to be │ │ │ │ │ + * called with the 'locked' property set to 'true': In some renderers, │ │ │ │ │ + * this might make sense to use as a 'only update local information' │ │ │ │ │ + * flag. │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - return this.icon.draw(px); │ │ │ │ │ - }, │ │ │ │ │ + locked: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erases any drawn elements for this marker. │ │ │ │ │ - */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.erase(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Move the marker to the new location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.icon != null)) { │ │ │ │ │ - this.icon.moveTo(px); │ │ │ │ │ - } │ │ │ │ │ - this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ - }, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} cache of current map resolution │ │ │ │ │ */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ - return isDrawn; │ │ │ │ │ - }, │ │ │ │ │ + resolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: inflate │ │ │ │ │ - * Englarges the markers icon by the specified ratio. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ - * will double the size). │ │ │ │ │ - */ │ │ │ │ │ - inflate: function(inflate) { │ │ │ │ │ - if (this.icon) { │ │ │ │ │ - this.icon.setSize({ │ │ │ │ │ - w: this.icon.size.w * inflate, │ │ │ │ │ - h: this.icon.size.h * inflate │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the opacity of the marker by changin the opacity of │ │ │ │ │ - * its icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ + * Property: featureDx │ │ │ │ │ + * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ + * applied to the current feature while rendering (see │ │ │ │ │ + * ). │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - this.icon.setOpacity(opacity); │ │ │ │ │ - }, │ │ │ │ │ + featureDx: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * Change URL of the Icon Image. │ │ │ │ │ - * │ │ │ │ │ - * url - {String} │ │ │ │ │ - */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - this.icon.setUrl(url); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.icon.display(display); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Marker" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: defaultIcon │ │ │ │ │ - * Creates a default . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A default OpenLayers.Icon to use for a marker │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Marker.defaultIcon = function() { │ │ │ │ │ - return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"), { │ │ │ │ │ - w: 21, │ │ │ │ │ - h: 25 │ │ │ │ │ - }, { │ │ │ │ │ - x: -10.5, │ │ │ │ │ - y: -25 │ │ │ │ │ - }); │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Marker/Box.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Marker.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Marker.Box │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Marker.Box │ │ │ │ │ + * Constructor: OpenLayers.Renderer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * borderColor - {String} │ │ │ │ │ - * borderWidth - {int} │ │ │ │ │ + * containerID - {} │ │ │ │ │ + * options - {Object} options for this renderer. See sublcasses for │ │ │ │ │ + * supported options. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(bounds, borderColor, borderWidth) { │ │ │ │ │ - this.bounds = bounds; │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(); │ │ │ │ │ - this.div.style.overflow = 'hidden'; │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ - this.setBorder(borderColor, borderWidth); │ │ │ │ │ + initialize: function(containerID, options) { │ │ │ │ │ + this.container = OpenLayers.Util.getElement(containerID); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - this.div = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Marker.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBorder │ │ │ │ │ - * Allow the user to change the box's color and border width │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * color - {String} Default is "red" │ │ │ │ │ - * width - {int} Default is 2 │ │ │ │ │ - */ │ │ │ │ │ - setBorder: function(color, width) { │ │ │ │ │ - if (!color) { │ │ │ │ │ - color = "red"; │ │ │ │ │ - } │ │ │ │ │ - if (!width) { │ │ │ │ │ - width = 2; │ │ │ │ │ - } │ │ │ │ │ - this.div.style.border = width + "px solid " + color; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * sz - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ - * location passed-in │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px, sz) { │ │ │ │ │ - OpenLayers.Util.modifyDOMElement(this.div, null, px, sz); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Rreturn: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsBounds(this.bounds, true, true); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.div.style.display = (display) ? "" : "none"; │ │ │ │ │ + this.container = null; │ │ │ │ │ + this.extent = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Marker.Box" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Popup/Anchored.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Popup.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Popup.Anchored │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Popup.Anchored = │ │ │ │ │ - OpenLayers.Class(OpenLayers.Popup, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: relativePosition │ │ │ │ │ - * {String} Relative position of the popup ("br", "tr", "tl" or "bl"). │ │ │ │ │ - */ │ │ │ │ │ - relativePosition: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: keepInMap │ │ │ │ │ - * {Boolean} If panMapIfOutOfView is false, and this property is true, │ │ │ │ │ - * contrain the popup such that it always fits in the available map │ │ │ │ │ - * space. By default, this is set. If you are creating popups that are │ │ │ │ │ - * near map edges and not allowing pannning, and especially if you have │ │ │ │ │ - * a popup which has a fixedRelativePosition, setting this to false may │ │ │ │ │ - * be a smart thing to do. │ │ │ │ │ - * │ │ │ │ │ - * For anchored popups, default is true, since subclasses will │ │ │ │ │ - * usually want this functionality. │ │ │ │ │ - */ │ │ │ │ │ - keepInMap: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: anchor │ │ │ │ │ - * {Object} Object to which we'll anchor the popup. Must expose a │ │ │ │ │ - * 'size' () and 'offset' (). │ │ │ │ │ - */ │ │ │ │ │ - anchor: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Popup.Anchored │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * contentSize - {} │ │ │ │ │ - * contentHTML - {String} │ │ │ │ │ - * anchor - {Object} Object which must expose a 'size' │ │ │ │ │ - * and 'offset' (generally an ). │ │ │ │ │ - * closeBox - {Boolean} │ │ │ │ │ - * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(id, lonlat, contentSize, contentHTML, anchor, closeBox, │ │ │ │ │ - closeBoxCallback) { │ │ │ │ │ - var newArguments = [ │ │ │ │ │ - id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback │ │ │ │ │ - ]; │ │ │ │ │ - OpenLayers.Popup.prototype.initialize.apply(this, newArguments); │ │ │ │ │ - │ │ │ │ │ - this.anchor = (anchor != null) ? anchor : │ │ │ │ │ - { │ │ │ │ │ - size: new OpenLayers.Size(0, 0), │ │ │ │ │ - offset: new OpenLayers.Pixel(0, 0) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.anchor = null; │ │ │ │ │ - this.relativePosition = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Popup.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: show │ │ │ │ │ - * Overridden from Popup since user might hide popup and then show() it │ │ │ │ │ - * in a new location (meaning we might want to update the relative │ │ │ │ │ - * position on the show) │ │ │ │ │ - */ │ │ │ │ │ - show: function() { │ │ │ │ │ - this.updatePosition(); │ │ │ │ │ - OpenLayers.Popup.prototype.show.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Since the popup is moving to a new px, it might need also to be moved │ │ │ │ │ - * relative to where the marker is. We first calculate the new │ │ │ │ │ - * relativePosition, and then we calculate the new px where we will │ │ │ │ │ - * put the popup, based on the new relative position. │ │ │ │ │ - * │ │ │ │ │ - * If the relativePosition has changed, we must also call │ │ │ │ │ - * updateRelativePosition() to make any visual changes to the popup │ │ │ │ │ - * which are associated with putting it in a new relativePosition. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - var oldRelativePosition = this.relativePosition; │ │ │ │ │ - this.relativePosition = this.calculateRelativePosition(px); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Popup.prototype.moveTo.call(this, this.calculateNewPx(px)); │ │ │ │ │ - │ │ │ │ │ - //if this move has caused the popup to change its relative position, │ │ │ │ │ - // we need to make the appropriate cosmetic changes. │ │ │ │ │ - if (this.relativePosition != oldRelativePosition) { │ │ │ │ │ - this.updateRelativePosition(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * contentSize - {} the new size for the popup's │ │ │ │ │ - * contents div (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(contentSize) { │ │ │ │ │ - OpenLayers.Popup.prototype.setSize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if ((this.lonlat) && (this.map)) { │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateRelativePosition │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The relative position ("br" "tr" "tl" "bl") at which the popup │ │ │ │ │ - * should be placed. │ │ │ │ │ - */ │ │ │ │ │ - calculateRelativePosition: function(px) { │ │ │ │ │ - var lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ - │ │ │ │ │ - var extent = this.map.getExtent(); │ │ │ │ │ - var quadrant = extent.determineQuadrant(lonlat); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Bounds.oppositeQuadrant(quadrant); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateRelativePosition │ │ │ │ │ - * The popup has been moved to a new relative location, so we may want to │ │ │ │ │ - * make some cosmetic adjustments to it. │ │ │ │ │ - * │ │ │ │ │ - * Note that in the classic Anchored popup, there is nothing to do │ │ │ │ │ - * here, since the popup looks exactly the same in all four positions. │ │ │ │ │ - * Subclasses such as Framed, however, will want to do something │ │ │ │ │ - * special here. │ │ │ │ │ - */ │ │ │ │ │ - updateRelativePosition: function() { │ │ │ │ │ - //to be overridden by subclasses │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateNewPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The the new px position of the popup on the screen │ │ │ │ │ - * relative to the passed-in px. │ │ │ │ │ - */ │ │ │ │ │ - calculateNewPx: function(px) { │ │ │ │ │ - var newPx = px.offset(this.anchor.offset); │ │ │ │ │ - │ │ │ │ │ - //use contentSize if size is not already set │ │ │ │ │ - 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; │ │ │ │ │ - │ │ │ │ │ - return newPx; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup.Anchored" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Popup/Framed.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Popup/Anchored.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Popup.Framed │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Popup.Framed = │ │ │ │ │ - OpenLayers.Class(OpenLayers.Popup.Anchored, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageSrc │ │ │ │ │ - * {String} location of the image to be used as the popup frame │ │ │ │ │ - */ │ │ │ │ │ - imageSrc: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageSize │ │ │ │ │ - * {} Size (measured in pixels) of the image located │ │ │ │ │ - * by the 'imageSrc' property. │ │ │ │ │ - */ │ │ │ │ │ - imageSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isAlphaImage │ │ │ │ │ - * {Boolean} The image has some alpha and thus needs to use the alpha │ │ │ │ │ - * image hack. Note that setting this to true will have no noticeable │ │ │ │ │ - * effect in FF or IE7 browsers, but will all but crush the ie6 │ │ │ │ │ - * browser. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - isAlphaImage: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: positionBlocks │ │ │ │ │ - * {Object} Hash of different position blocks (Object/Hashs). Each block │ │ │ │ │ - * will be keyed by a two-character 'relativePosition' │ │ │ │ │ - * code string (ie "tl", "tr", "bl", "br"). Block properties are │ │ │ │ │ - * 'offset', 'padding' (self-explanatory), and finally the 'blocks' │ │ │ │ │ - * parameter, which is an array of the block objects. │ │ │ │ │ - * │ │ │ │ │ - * Each block object must have 'size', 'anchor', and 'position' │ │ │ │ │ - * properties. │ │ │ │ │ - * │ │ │ │ │ - * Note that positionBlocks should never be modified at runtime. │ │ │ │ │ - */ │ │ │ │ │ - positionBlocks: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: blocks │ │ │ │ │ - * {Array[Object]} Array of objects, each of which is one "block" of the │ │ │ │ │ - * popup. Each block has a 'div' and an 'image' property, both of │ │ │ │ │ - * which are DOMElements, and the latter of which is appended to the │ │ │ │ │ - * former. These are reused as the popup goes changing positions for │ │ │ │ │ - * great economy and elegance. │ │ │ │ │ - */ │ │ │ │ │ - blocks: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fixedRelativePosition │ │ │ │ │ - * {Boolean} We want the framed popup to work dynamically placed relative │ │ │ │ │ - * to its anchor but also in just one fixed position. A well designed │ │ │ │ │ - * framed popup will have the pixels and logic to display itself in │ │ │ │ │ - * any of the four relative positions, but (understandably), this will │ │ │ │ │ - * not be the case for all of them. By setting this property to 'true', │ │ │ │ │ - * framed popup will not recalculate for the best placement each time │ │ │ │ │ - * it's open, but will always open the same way. │ │ │ │ │ - * Note that if this is set to true, it is generally advisable to also │ │ │ │ │ - * set the 'panIntoView' property to true so that the popup can be │ │ │ │ │ - * scrolled into view (since it will often be offscreen on open) │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - fixedRelativePosition: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Popup.Framed │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * contentSize - {} │ │ │ │ │ - * contentHTML - {String} │ │ │ │ │ - * anchor - {Object} Object to which we'll anchor the popup. Must expose │ │ │ │ │ - * a 'size' () and 'offset' () │ │ │ │ │ - * (Note that this is generally an ). │ │ │ │ │ - * closeBox - {Boolean} │ │ │ │ │ - * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(id, lonlat, contentSize, contentHTML, anchor, closeBox, │ │ │ │ │ - closeBoxCallback) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (this.fixedRelativePosition) { │ │ │ │ │ - //based on our decided relativePostion, set the current padding │ │ │ │ │ - // this keeps us from getting into trouble │ │ │ │ │ - this.updateRelativePosition(); │ │ │ │ │ - │ │ │ │ │ - //make calculateRelativePosition always return the specified │ │ │ │ │ - // fixed position. │ │ │ │ │ - this.calculateRelativePosition = function(px) { │ │ │ │ │ - return this.relativePosition; │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.contentDiv.style.position = "absolute"; │ │ │ │ │ - this.contentDiv.style.zIndex = 1; │ │ │ │ │ - │ │ │ │ │ - if (closeBox) { │ │ │ │ │ - this.closeDiv.style.zIndex = 1; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.groupDiv.style.position = "absolute"; │ │ │ │ │ - this.groupDiv.style.top = "0px"; │ │ │ │ │ - this.groupDiv.style.left = "0px"; │ │ │ │ │ - this.groupDiv.style.height = "100%"; │ │ │ │ │ - this.groupDiv.style.width = "100%"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.imageSrc = null; │ │ │ │ │ - this.imageSize = null; │ │ │ │ │ - this.isAlphaImage = null; │ │ │ │ │ - │ │ │ │ │ - this.fixedRelativePosition = false; │ │ │ │ │ - this.positionBlocks = null; │ │ │ │ │ - │ │ │ │ │ - //remove our blocks │ │ │ │ │ - for (var i = 0; i < this.blocks.length; i++) { │ │ │ │ │ - var block = this.blocks[i]; │ │ │ │ │ - │ │ │ │ │ - if (block.image) { │ │ │ │ │ - block.div.removeChild(block.image); │ │ │ │ │ - } │ │ │ │ │ - block.image = null; │ │ │ │ │ - │ │ │ │ │ - if (block.div) { │ │ │ │ │ - this.groupDiv.removeChild(block.div); │ │ │ │ │ - } │ │ │ │ │ - block.div = null; │ │ │ │ │ - } │ │ │ │ │ - this.blocks = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Popup.Anchored.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setBackgroundColor │ │ │ │ │ - */ │ │ │ │ │ - setBackgroundColor: function(color) { │ │ │ │ │ - //does nothing since the framed popup's entire scheme is based on a │ │ │ │ │ - // an image -- changing the background color makes no sense. │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setBorder │ │ │ │ │ - */ │ │ │ │ │ - setBorder: function() { │ │ │ │ │ - //does nothing since the framed popup's entire scheme is based on a │ │ │ │ │ - // an image -- changing the popup's border makes no sense. │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Sets the opacity of the popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - //does nothing since we suppose that we'll never apply an opacity │ │ │ │ │ - // to a framed popup │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setSize │ │ │ │ │ - * Overridden here, because we need to update the blocks whenever the size │ │ │ │ │ - * of the popup has changed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * contentSize - {} the new size for the popup's │ │ │ │ │ - * contents div (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(contentSize) { │ │ │ │ │ - OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.updateBlocks(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateRelativePosition │ │ │ │ │ - * When the relative position changes, we need to set the new padding │ │ │ │ │ - * BBOX on the popup, reposition the close div, and update the blocks. │ │ │ │ │ - */ │ │ │ │ │ - updateRelativePosition: function() { │ │ │ │ │ - │ │ │ │ │ - //update the padding │ │ │ │ │ - this.padding = this.positionBlocks[this.relativePosition].padding; │ │ │ │ │ - │ │ │ │ │ - //update the position of our close box to new padding │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - // use the content div's css padding to determine if we should │ │ │ │ │ - // padd the close div │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - │ │ │ │ │ - this.closeDiv.style.right = contentDivPadding.right + │ │ │ │ │ - this.padding.right + "px"; │ │ │ │ │ - this.closeDiv.style.top = contentDivPadding.top + │ │ │ │ │ - this.padding.top + "px"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.updateBlocks(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateNewPx │ │ │ │ │ - * Besides the standard offset as determined by the Anchored class, our │ │ │ │ │ - * Framed popups have a special 'offset' property for each of their │ │ │ │ │ - * positions, which is used to offset the popup relative to its anchor. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The the new px position of the popup on the screen │ │ │ │ │ - * relative to the passed-in px. │ │ │ │ │ - */ │ │ │ │ │ - calculateNewPx: function(px) { │ │ │ │ │ - var newPx = OpenLayers.Popup.Anchored.prototype.calculateNewPx.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - newPx = newPx.offset(this.positionBlocks[this.relativePosition].offset); │ │ │ │ │ - │ │ │ │ │ - return newPx; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createBlocks │ │ │ │ │ - */ │ │ │ │ │ - createBlocks: function() { │ │ │ │ │ - this.blocks = []; │ │ │ │ │ - │ │ │ │ │ - //since all positions contain the same number of blocks, we can │ │ │ │ │ - // just pick the first position and use its blocks array to create │ │ │ │ │ - // our blocks array │ │ │ │ │ - var firstPosition = null; │ │ │ │ │ - for (var key in this.positionBlocks) { │ │ │ │ │ - firstPosition = key; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var position = this.positionBlocks[firstPosition]; │ │ │ │ │ - for (var i = 0; i < position.blocks.length; i++) { │ │ │ │ │ - │ │ │ │ │ - var block = {}; │ │ │ │ │ - this.blocks.push(block); │ │ │ │ │ - │ │ │ │ │ - var divId = this.id + '_FrameDecorationDiv_' + i; │ │ │ │ │ - block.div = OpenLayers.Util.createDiv(divId, │ │ │ │ │ - null, null, null, "absolute", null, "hidden", null │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - var imgId = this.id + '_FrameDecorationImg_' + i; │ │ │ │ │ - var imageCreator = │ │ │ │ │ - (this.isAlphaImage) ? OpenLayers.Util.createAlphaImageDiv : │ │ │ │ │ - OpenLayers.Util.createImage; │ │ │ │ │ - │ │ │ │ │ - block.image = imageCreator(imgId, │ │ │ │ │ - null, this.imageSize, this.imageSrc, │ │ │ │ │ - "absolute", null, null, null │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - block.div.appendChild(block.image); │ │ │ │ │ - this.groupDiv.appendChild(block.div); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateBlocks │ │ │ │ │ - * Internal method, called on initialize and when the popup's relative │ │ │ │ │ - * position has changed. This function takes care of re-positioning │ │ │ │ │ - * the popup's blocks in their appropropriate places. │ │ │ │ │ - */ │ │ │ │ │ - updateBlocks: function() { │ │ │ │ │ - if (!this.blocks) { │ │ │ │ │ - this.createBlocks(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.size && this.relativePosition) { │ │ │ │ │ - var position = this.positionBlocks[this.relativePosition]; │ │ │ │ │ - for (var i = 0; i < position.blocks.length; i++) { │ │ │ │ │ - │ │ │ │ │ - var positionBlock = position.blocks[i]; │ │ │ │ │ - var block = this.blocks[i]; │ │ │ │ │ - │ │ │ │ │ - // adjust sizes │ │ │ │ │ - var l = positionBlock.anchor.left; │ │ │ │ │ - var b = positionBlock.anchor.bottom; │ │ │ │ │ - var r = positionBlock.anchor.right; │ │ │ │ │ - var t = positionBlock.anchor.top; │ │ │ │ │ - │ │ │ │ │ - //note that we use the isNaN() test here because if the │ │ │ │ │ - // size object is initialized with a "auto" parameter, the │ │ │ │ │ - // size constructor calls parseFloat() on the string, │ │ │ │ │ - // which will turn it into NaN │ │ │ │ │ - // │ │ │ │ │ - var w = (isNaN(positionBlock.size.w)) ? this.size.w - (r + l) : │ │ │ │ │ - positionBlock.size.w; │ │ │ │ │ - │ │ │ │ │ - var h = (isNaN(positionBlock.size.h)) ? this.size.h - (b + t) : │ │ │ │ │ - positionBlock.size.h; │ │ │ │ │ - │ │ │ │ │ - block.div.style.width = (w < 0 ? 0 : w) + 'px'; │ │ │ │ │ - block.div.style.height = (h < 0 ? 0 : h) + 'px'; │ │ │ │ │ - │ │ │ │ │ - block.div.style.left = (l != null) ? l + 'px' : ''; │ │ │ │ │ - block.div.style.bottom = (b != null) ? b + 'px' : ''; │ │ │ │ │ - block.div.style.right = (r != null) ? r + 'px' : ''; │ │ │ │ │ - block.div.style.top = (t != null) ? t + 'px' : ''; │ │ │ │ │ - │ │ │ │ │ - block.image.style.left = positionBlock.position.x + 'px'; │ │ │ │ │ - block.image.style.top = positionBlock.position.y + 'px'; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.contentDiv.style.left = this.padding.left + "px"; │ │ │ │ │ - this.contentDiv.style.top = this.padding.top + "px"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup.Framed" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Popup/FramedCloud.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Popup/Framed.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Bounds.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Pixel.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Size.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Popup.FramedCloud │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Popup.FramedCloud = │ │ │ │ │ - OpenLayers.Class(OpenLayers.Popup.Framed, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentDisplayClass │ │ │ │ │ - * {String} The CSS class of the popup content div. │ │ │ │ │ - */ │ │ │ │ │ - contentDisplayClass: "olFramedCloudPopupContent", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoSize │ │ │ │ │ - * {Boolean} Framed Cloud is autosizing by default. │ │ │ │ │ - */ │ │ │ │ │ - autoSize: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: panMapIfOutOfView │ │ │ │ │ - * {Boolean} Framed Cloud does pan into view by default. │ │ │ │ │ - */ │ │ │ │ │ - panMapIfOutOfView: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: imageSize │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - imageSize: new OpenLayers.Size(1276, 736), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isAlphaImage │ │ │ │ │ - * {Boolean} The FramedCloud does not use an alpha image (in honor of the │ │ │ │ │ - * good ie6 folk out there) │ │ │ │ │ - */ │ │ │ │ │ - isAlphaImage: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fixedRelativePosition │ │ │ │ │ - * {Boolean} The Framed Cloud popup works in just one fixed position. │ │ │ │ │ - */ │ │ │ │ │ - fixedRelativePosition: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: positionBlocks │ │ │ │ │ - * {Object} Hash of differen position blocks, keyed by relativePosition │ │ │ │ │ - * two-character code string (ie "tl", "tr", "bl", "br") │ │ │ │ │ - */ │ │ │ │ │ - positionBlocks: { │ │ │ │ │ - "tl": { │ │ │ │ │ - 'offset': new OpenLayers.Pixel(44, 0), │ │ │ │ │ - 'padding': new OpenLayers.Bounds(8, 40, 8, 9), │ │ │ │ │ - 'blocks': [{ // top-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 51, 22, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(0, 0) │ │ │ │ │ - }, { //top-right │ │ │ │ │ - size: new OpenLayers.Size(22, 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 50, 0, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, 0) │ │ │ │ │ - }, { //bottom-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 19), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 32, 22, null), │ │ │ │ │ - position: new OpenLayers.Pixel(0, -631) │ │ │ │ │ - }, { //bottom-right │ │ │ │ │ - size: new OpenLayers.Size(22, 18), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 32, 0, null), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, -632) │ │ │ │ │ - }, { // stem │ │ │ │ │ - size: new OpenLayers.Size(81, 35), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 0, 0, null), │ │ │ │ │ - position: new OpenLayers.Pixel(0, -688) │ │ │ │ │ - }] │ │ │ │ │ - }, │ │ │ │ │ - "tr": { │ │ │ │ │ - 'offset': new OpenLayers.Pixel(-45, 0), │ │ │ │ │ - 'padding': new OpenLayers.Bounds(8, 40, 8, 9), │ │ │ │ │ - 'blocks': [{ // top-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 51, 22, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(0, 0) │ │ │ │ │ - }, { //top-right │ │ │ │ │ - size: new OpenLayers.Size(22, 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 50, 0, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, 0) │ │ │ │ │ - }, { //bottom-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 19), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 32, 22, null), │ │ │ │ │ - position: new OpenLayers.Pixel(0, -631) │ │ │ │ │ - }, { //bottom-right │ │ │ │ │ - size: new OpenLayers.Size(22, 19), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 32, 0, null), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, -631) │ │ │ │ │ - }, { // stem │ │ │ │ │ - size: new OpenLayers.Size(81, 35), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 0, null, null), │ │ │ │ │ - position: new OpenLayers.Pixel(-215, -687) │ │ │ │ │ - }] │ │ │ │ │ - }, │ │ │ │ │ - "bl": { │ │ │ │ │ - 'offset': new OpenLayers.Pixel(45, 0), │ │ │ │ │ - 'padding': new OpenLayers.Bounds(8, 9, 8, 40), │ │ │ │ │ - 'blocks': [{ // top-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 21, 22, 32), │ │ │ │ │ - position: new OpenLayers.Pixel(0, 0) │ │ │ │ │ - }, { //top-right │ │ │ │ │ - size: new OpenLayers.Size(22, 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 21, 0, 32), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, 0) │ │ │ │ │ - }, { //bottom-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 21), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 0, 22, null), │ │ │ │ │ - position: new OpenLayers.Pixel(0, -629) │ │ │ │ │ - }, { //bottom-right │ │ │ │ │ - size: new OpenLayers.Size(22, 21), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 0, 0, null), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, -629) │ │ │ │ │ - }, { // stem │ │ │ │ │ - size: new OpenLayers.Size(81, 33), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, null, 0, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(-101, -674) │ │ │ │ │ - }] │ │ │ │ │ - }, │ │ │ │ │ - "br": { │ │ │ │ │ - 'offset': new OpenLayers.Pixel(-44, 0), │ │ │ │ │ - 'padding': new OpenLayers.Bounds(8, 9, 8, 40), │ │ │ │ │ - 'blocks': [{ // top-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 21, 22, 32), │ │ │ │ │ - position: new OpenLayers.Pixel(0, 0) │ │ │ │ │ - }, { //top-right │ │ │ │ │ - size: new OpenLayers.Size(22, 'auto'), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 21, 0, 32), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, 0) │ │ │ │ │ - }, { //bottom-left │ │ │ │ │ - size: new OpenLayers.Size('auto', 21), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, 0, 22, null), │ │ │ │ │ - position: new OpenLayers.Pixel(0, -629) │ │ │ │ │ - }, { //bottom-right │ │ │ │ │ - size: new OpenLayers.Size(22, 21), │ │ │ │ │ - anchor: new OpenLayers.Bounds(null, 0, 0, null), │ │ │ │ │ - position: new OpenLayers.Pixel(-1238, -629) │ │ │ │ │ - }, { // stem │ │ │ │ │ - size: new OpenLayers.Size(81, 33), │ │ │ │ │ - anchor: new OpenLayers.Bounds(0, null, null, 0), │ │ │ │ │ - position: new OpenLayers.Pixel(-311, -674) │ │ │ │ │ - }] │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minSize │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - minSize: new OpenLayers.Size(105, 10), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxSize │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - maxSize: new OpenLayers.Size(1200, 660), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Popup.FramedCloud │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * contentSize - {} │ │ │ │ │ - * contentHTML - {String} │ │ │ │ │ - * anchor - {Object} Object to which we'll anchor the popup. Must expose │ │ │ │ │ - * a 'size' () and 'offset' () │ │ │ │ │ - * (Note that this is generally an ). │ │ │ │ │ - * closeBox - {Boolean} │ │ │ │ │ - * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(id, lonlat, contentSize, contentHTML, anchor, closeBox, │ │ │ │ │ - closeBoxCallback) { │ │ │ │ │ - │ │ │ │ │ - this.imageSrc = OpenLayers.Util.getImageLocation('cloud-popup-relative.png'); │ │ │ │ │ - OpenLayers.Popup.Framed.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.contentDiv.className = this.contentDisplayClass; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup.FramedCloud" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Drag.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Drag │ │ │ │ │ - * The drag handler is used to deal with sequences of browser events related │ │ │ │ │ - * to dragging. The handler is used by controls that want to know when │ │ │ │ │ - * a drag sequence begins, when a drag is happening, and when it has │ │ │ │ │ - * finished. │ │ │ │ │ - * │ │ │ │ │ - * Controls that use the drag handler typically construct it with callbacks │ │ │ │ │ - * for 'down', 'move', and 'done'. Callbacks for these keys are called │ │ │ │ │ - * when the drag begins, with each move, and when the drag is done. In │ │ │ │ │ - * addition, controls can have callbacks keyed to 'up' and 'out' if they │ │ │ │ │ - * care to differentiate between the types of events that correspond with │ │ │ │ │ - * the end of a drag sequence. If no drag actually occurs (no mouse move) │ │ │ │ │ - * the 'down' and 'up' callbacks will be called, but not the 'done' │ │ │ │ │ - * callback. │ │ │ │ │ - * │ │ │ │ │ - * Create a new drag handler with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: started │ │ │ │ │ - * {Boolean} When a mousedown or touchstart event is received, we want to │ │ │ │ │ - * record it, but not set 'dragging' until the mouse moves after starting. │ │ │ │ │ - */ │ │ │ │ │ - started: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ - * on the same element. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - dragging: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {} The last pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {} The first pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - start: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastMoveEvt │ │ │ │ │ - * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ - * position the map correctly when our "delay drag" │ │ │ │ │ - * timeout expired. │ │ │ │ │ - */ │ │ │ │ │ - lastMoveEvt: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: oldOnselectstart │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - oldOnselectstart: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} In order to increase performance, an interval (in │ │ │ │ │ - * milliseconds) can be set to reduce the number of drag events │ │ │ │ │ - * called. If set, a new drag event will not be set until the │ │ │ │ │ - * interval has passed. │ │ │ │ │ - * Defaults to 0, meaning no interval. │ │ │ │ │ - */ │ │ │ │ │ - interval: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: timeoutId │ │ │ │ │ - * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ - * This is "private", and should be left alone. │ │ │ │ │ - */ │ │ │ │ │ - timeoutId: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, the handler will also handle mouse moves when │ │ │ │ │ - * the cursor has moved out of the map viewport. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: documentEvents │ │ │ │ │ - * {Boolean} Are we currently observing document events? │ │ │ │ │ - */ │ │ │ │ │ - documentEvents: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ - * Returns OpenLayers.Handler.Drag │ │ │ │ │ + * APIMethod: supported │ │ │ │ │ + * This should be overridden by specific subclasses │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handlers setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object containing a single function to be │ │ │ │ │ - * called when the drag operation is finished. The callback should │ │ │ │ │ - * expect to recieve a single argument, the pixel location of the event. │ │ │ │ │ - * Callbacks for 'move' and 'done' are supported. You can also speficy │ │ │ │ │ - * callbacks for 'down', 'up', and 'out' to respond to those events. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - var me = this; │ │ │ │ │ - this._docMove = function(evt) { │ │ │ │ │ - me.mousemove({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ - }, │ │ │ │ │ - element: document │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - this._docUp = function(evt) { │ │ │ │ │ - me.mouseup({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: dragstart │ │ │ │ │ - * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ */ │ │ │ │ │ - dragstart: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - if (this.checkModifiers(evt) && │ │ │ │ │ - (OpenLayers.Event.isLeftClick(evt) || │ │ │ │ │ - OpenLayers.Event.isSingleTouch(evt))) { │ │ │ │ │ - this.started = true; │ │ │ │ │ - this.start = evt.xy; │ │ │ │ │ - this.last = evt.xy; │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.down(evt); │ │ │ │ │ - this.callback("down", [evt.xy]); │ │ │ │ │ - │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - │ │ │ │ │ - if (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart ? │ │ │ │ │ - document.onselectstart : OpenLayers.Function.True; │ │ │ │ │ - } │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - │ │ │ │ │ - propagate = !this.stopDown; │ │ │ │ │ - } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - } │ │ │ │ │ - return propagate; │ │ │ │ │ + supported: function() { │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragmove │ │ │ │ │ - * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * Method: setExtent │ │ │ │ │ + * Set the visible part of the layer. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - dragmove: function(evt) { │ │ │ │ │ - this.lastMoveEvt = evt; │ │ │ │ │ - if (this.started && !this.timeoutId && (evt.xy.x != this.last.x || │ │ │ │ │ - evt.xy.y != this.last.y)) { │ │ │ │ │ - if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ - if (evt.element === document) { │ │ │ │ │ - this.adjustXY(evt); │ │ │ │ │ - // do setEvent manually because the documentEvents are not │ │ │ │ │ - // registered with the map │ │ │ │ │ - this.setEvent(evt); │ │ │ │ │ - } else { │ │ │ │ │ - this.removeDocumentEvents(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.interval > 0) { │ │ │ │ │ - this.timeoutId = setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.removeTimeout, this), │ │ │ │ │ - this.interval); │ │ │ │ │ - } │ │ │ │ │ - this.dragging = true; │ │ │ │ │ - │ │ │ │ │ - this.move(evt); │ │ │ │ │ - this.callback("move", [evt.xy]); │ │ │ │ │ - if (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart; │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ - this.last = evt.xy; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: dragend │ │ │ │ │ - * This private method is factorized from mouseup and touchend methods │ │ │ │ │ + * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ + * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ + * next it is needed. │ │ │ │ │ + * We nullify the resolution cache (this.resolution) if resolutionChanged │ │ │ │ │ + * is set to true - this way it will be re-computed on the next │ │ │ │ │ + * getResolution() request. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * extent - {} │ │ │ │ │ + * resolutionChanged - {Boolean} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Boolean} true to notify the layer that the new extent does not exceed │ │ │ │ │ + * the coordinate range, and the features will not need to be redrawn. │ │ │ │ │ + * False otherwise. │ │ │ │ │ */ │ │ │ │ │ - dragend: function(evt) { │ │ │ │ │ - if (this.started) { │ │ │ │ │ - if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ - this.adjustXY(evt); │ │ │ │ │ - this.removeDocumentEvents(); │ │ │ │ │ - } │ │ │ │ │ - var dragged = (this.start != this.last); │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.up(evt); │ │ │ │ │ - this.callback("up", [evt.xy]); │ │ │ │ │ - if (dragged) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ - } │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + setExtent: function(extent, resolutionChanged) { │ │ │ │ │ + this.extent = extent.clone(); │ │ │ │ │ + if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ + var ratio = extent.getWidth() / this.map.getExtent().getWidth(), │ │ │ │ │ + extent = extent.scale(1 / ratio); │ │ │ │ │ + this.extent = extent.wrapDateLine(this.map.getMaxExtent()).scale(ratio); │ │ │ │ │ + } │ │ │ │ │ + if (resolutionChanged) { │ │ │ │ │ + this.resolution = null; │ │ │ │ │ } │ │ │ │ │ return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ - * to do their own processing related to these mouse events. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * This method is called during the handling of the mouse down event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse down event │ │ │ │ │ - */ │ │ │ │ │ - down: function(evt) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * This method is called during the handling of the mouse move event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse move event │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - move: function(evt) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * This method is called during the handling of the mouse up event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse up event │ │ │ │ │ - */ │ │ │ │ │ - up: function(evt) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: out │ │ │ │ │ - * This method is called during the handling of the mouse out event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse out event │ │ │ │ │ - */ │ │ │ │ │ - out: function(evt) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * The methods below are part of the magic of event handling. Because │ │ │ │ │ - * they are named like browser events, they are registered as listeners │ │ │ │ │ - * for the events they represent. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * Sets the size of the drawing surface. │ │ │ │ │ + * │ │ │ │ │ + * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ + * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ + * next it is needed. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + this.resolution = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mousemove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: getResolution │ │ │ │ │ + * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Float} The current map's resolution │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ + return this.resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Draw the feature. The optional style argument can be used │ │ │ │ │ + * to override the feature's own style. This method should only │ │ │ │ │ + * be called from layer.drawFeature(). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ + * feature - {} │ │ │ │ │ + * style - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTimeout │ │ │ │ │ - * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ + * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ + * undefined if the feature had no geometry │ │ │ │ │ */ │ │ │ │ │ - removeTimeout: function() { │ │ │ │ │ - this.timeoutId = null; │ │ │ │ │ - // if timeout expires while we're still dragging (mouseup │ │ │ │ │ - // hasn't occurred) then call mousemove to move to the │ │ │ │ │ - // correct position │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.mousemove(this.lastMoveEvt); │ │ │ │ │ + drawFeature: function(feature, style) { │ │ │ │ │ + if (style == null) { │ │ │ │ │ + style = feature.style; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + var bounds = feature.geometry.getBounds(); │ │ │ │ │ + if (bounds) { │ │ │ │ │ + var worldBounds; │ │ │ │ │ + if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ + worldBounds = this.map.getMaxExtent(); │ │ │ │ │ + } │ │ │ │ │ + if (!bounds.intersectsBounds(this.extent, { │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + })) { │ │ │ │ │ + style = { │ │ │ │ │ + display: "none" │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + this.calculateFeatureDx(bounds, worldBounds); │ │ │ │ │ + } │ │ │ │ │ + var rendered = this.drawGeometry(feature.geometry, style, feature.id); │ │ │ │ │ + if (style.display != "none" && style.label && rendered !== false) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + var location = feature.geometry.getCentroid(); │ │ │ │ │ + if (style.labelXOffset || style.labelYOffset) { │ │ │ │ │ + var xOffset = isNaN(style.labelXOffset) ? 0 : style.labelXOffset; │ │ │ │ │ + var yOffset = isNaN(style.labelYOffset) ? 0 : style.labelYOffset; │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + location.move(xOffset * res, yOffset * res); │ │ │ │ │ + } │ │ │ │ │ + this.drawText(feature.id, style, location); │ │ │ │ │ + } else { │ │ │ │ │ + this.removeText(feature.id); │ │ │ │ │ + } │ │ │ │ │ + return rendered; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ + * Method: calculateFeatureDx │ │ │ │ │ + * {Number} Calculates the feature offset in x direction. Looking at the │ │ │ │ │ + * center of the feature bounds and the renderer extent, we calculate how │ │ │ │ │ + * many world widths the two are away from each other. This distance is │ │ │ │ │ + * used to shift the feature as close as possible to the center of the │ │ │ │ │ + * current enderer extent, which ensures that the feature is visible in the │ │ │ │ │ + * current viewport. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * bounds - {} Bounds of the feature │ │ │ │ │ + * worldBounds - {} Bounds of the world │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - // override evt.xy with last position since touchend does not have │ │ │ │ │ - // any touch position │ │ │ │ │ - evt.xy = this.last; │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + calculateFeatureDx: function(bounds, worldBounds) { │ │ │ │ │ + this.featureDx = 0; │ │ │ │ │ + if (worldBounds) { │ │ │ │ │ + var worldWidth = worldBounds.getWidth(), │ │ │ │ │ + rendererCenterX = (this.extent.left + this.extent.right) / 2, │ │ │ │ │ + featureCenterX = (bounds.left + bounds.right) / 2, │ │ │ │ │ + worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth); │ │ │ │ │ + this.featureDx = worldsAway * worldWidth; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Handle mouseout events │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawGeometry │ │ │ │ │ + * │ │ │ │ │ + * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ + * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ + * virtual function │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * featureId - {} │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - this.addDocumentEvents(); │ │ │ │ │ - } else { │ │ │ │ │ - var dragged = (this.start != this.last); │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.out(evt); │ │ │ │ │ - this.callback("out", []); │ │ │ │ │ - if (dragged) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ - } │ │ │ │ │ - if (document.onselectstart) { │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * The drag handler captures the click event. If something else registers │ │ │ │ │ - * for clicks on the same element, its listener will not be called │ │ │ │ │ - * after a drag. │ │ │ │ │ + * Method: drawText │ │ │ │ │ + * Function for drawing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * featureId - {String} │ │ │ │ │ + * style - │ │ │ │ │ + * location - {} │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - // let the click event propagate only if the mouse moved │ │ │ │ │ - return (this.start == this.last); │ │ │ │ │ - }, │ │ │ │ │ + drawText: function(featureId, style, location) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ + * Method: removeText │ │ │ │ │ + * Function for removing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ + removeText: function(featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear all vectors from the renderer. │ │ │ │ │ + * virtual function. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ + clear: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: adjustXY │ │ │ │ │ - * Converts event coordinates that are relative to the document body to │ │ │ │ │ - * ones that are relative to the map viewport. The latter is the default in │ │ │ │ │ - * OpenLayers. │ │ │ │ │ + * Method: getFeatureIdFromEvent │ │ │ │ │ + * Returns a feature id from an event on the renderer. │ │ │ │ │ + * How this happens is specific to the renderer. This should be │ │ │ │ │ + * called from layer.getFeatureFromEvent(). │ │ │ │ │ + * Virtual function. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - adjustXY: function(evt) { │ │ │ │ │ - var pos = OpenLayers.Util.pagePosition(this.map.viewPortDiv); │ │ │ │ │ - evt.xy.x -= pos[0]; │ │ │ │ │ - evt.xy.y -= pos[1]; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addDocumentEvents │ │ │ │ │ - * Start observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor leaves the map viewport while dragging. │ │ │ │ │ - */ │ │ │ │ │ - addDocumentEvents: function() { │ │ │ │ │ - OpenLayers.Element.addClass(document.body, "olDragDown"); │ │ │ │ │ - this.documentEvents = true; │ │ │ │ │ - OpenLayers.Event.observe(document, "mousemove", this._docMove); │ │ │ │ │ - OpenLayers.Event.observe(document, "mouseup", this._docUp); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeDocumentEvents │ │ │ │ │ - * Stops observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor re-enters the map viewport while dragging. │ │ │ │ │ - */ │ │ │ │ │ - removeDocumentEvents: function() { │ │ │ │ │ - OpenLayers.Element.removeClass(document.body, "olDragDown"); │ │ │ │ │ - this.documentEvents = false; │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mousemove", this._docMove); │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mouseup", this._docUp); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Drag" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Box.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Box │ │ │ │ │ - * Handler for dragging a rectangle across the map. Box is displayed │ │ │ │ │ - * on mouse down, moves on mouse move, and is finished on mouse up. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragHandler │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - dragHandler: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: boxDivClassName │ │ │ │ │ - * {String} The CSS class to use for drawing the box. Default is │ │ │ │ │ - * olHandlerBoxZoomBox │ │ │ │ │ - */ │ │ │ │ │ - boxDivClassName: 'olHandlerBoxZoomBox', │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: boxOffsets │ │ │ │ │ - * {Object} Caches box offsets from css. This is used by the getBoxOffsets │ │ │ │ │ - * method. │ │ │ │ │ - */ │ │ │ │ │ - boxOffsets: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Box │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * start - Called when the box drag operation starts. │ │ │ │ │ - * done - Called when the box drag operation is finished. │ │ │ │ │ - * The callback should expect to receive a single argument, the box │ │ │ │ │ - * bounds or a pixel. If the box dragging didn't span more than a 5 │ │ │ │ │ - * pixel distance, a pixel will be returned instead of a bounds object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.dragHandler = new OpenLayers.Handler.Drag( │ │ │ │ │ - this, { │ │ │ │ │ - down: this.startBox, │ │ │ │ │ - move: this.moveBox, │ │ │ │ │ - out: this.removeBox, │ │ │ │ │ - up: this.endBox │ │ │ │ │ - }, { │ │ │ │ │ - keyMask: this.keyMask │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.destroy(); │ │ │ │ │ - this.dragHandler = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Handler.prototype.setMap.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: startBox │ │ │ │ │ + * evt - {} │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} │ │ │ │ │ - */ │ │ │ │ │ - startBox: function(xy) { │ │ │ │ │ - this.callback("start", []); │ │ │ │ │ - this.zoomBox = OpenLayers.Util.createDiv('zoomBox', { │ │ │ │ │ - x: -9999, │ │ │ │ │ - y: -9999 │ │ │ │ │ - }); │ │ │ │ │ - this.zoomBox.className = this.boxDivClassName; │ │ │ │ │ - this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; │ │ │ │ │ - │ │ │ │ │ - this.map.viewPortDiv.appendChild(this.zoomBox); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveBox │ │ │ │ │ - */ │ │ │ │ │ - moveBox: function(xy) { │ │ │ │ │ - var startX = this.dragHandler.start.x; │ │ │ │ │ - var startY = this.dragHandler.start.y; │ │ │ │ │ - var deltaX = Math.abs(startX - xy.x); │ │ │ │ │ - var deltaY = Math.abs(startY - xy.y); │ │ │ │ │ - │ │ │ │ │ - var offset = this.getBoxOffsets(); │ │ │ │ │ - this.zoomBox.style.width = (deltaX + offset.width + 1) + "px"; │ │ │ │ │ - this.zoomBox.style.height = (deltaY + offset.height + 1) + "px"; │ │ │ │ │ - this.zoomBox.style.left = (xy.x < startX ? │ │ │ │ │ - startX - deltaX - offset.left : startX - offset.left) + "px"; │ │ │ │ │ - this.zoomBox.style.top = (xy.y < startY ? │ │ │ │ │ - startY - deltaY - offset.top : startY - offset.top) + "px"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: endBox │ │ │ │ │ - */ │ │ │ │ │ - endBox: function(end) { │ │ │ │ │ - var result; │ │ │ │ │ - if (Math.abs(this.dragHandler.start.x - end.x) > 5 || │ │ │ │ │ - Math.abs(this.dragHandler.start.y - end.y) > 5) { │ │ │ │ │ - var start = this.dragHandler.start; │ │ │ │ │ - var top = Math.min(start.y, end.y); │ │ │ │ │ - var bottom = Math.max(start.y, end.y); │ │ │ │ │ - var left = Math.min(start.x, end.x); │ │ │ │ │ - var right = Math.max(start.x, end.x); │ │ │ │ │ - result = new OpenLayers.Bounds(left, bottom, right, top); │ │ │ │ │ - } else { │ │ │ │ │ - result = this.dragHandler.start.clone(); // i.e. OL.Pixel │ │ │ │ │ - } │ │ │ │ │ - this.removeBox(); │ │ │ │ │ - │ │ │ │ │ - this.callback("done", [result]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeBox │ │ │ │ │ - * Remove the zoombox from the screen and nullify our reference to it. │ │ │ │ │ - */ │ │ │ │ │ - removeBox: function() { │ │ │ │ │ - this.map.viewPortDiv.removeChild(this.zoomBox); │ │ │ │ │ - this.zoomBox = null; │ │ │ │ │ - this.boxOffsets = null; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragHandler.activate(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - if (this.dragHandler.deactivate()) { │ │ │ │ │ - if (this.zoomBox) { │ │ │ │ │ - this.removeBox(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getBoxOffsets │ │ │ │ │ - * Determines border offsets for a box, according to the box model. │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} an object with the following offsets: │ │ │ │ │ - * - left │ │ │ │ │ - * - right │ │ │ │ │ - * - top │ │ │ │ │ - * - bottom │ │ │ │ │ - * - width │ │ │ │ │ - * - height │ │ │ │ │ - */ │ │ │ │ │ - getBoxOffsets: function() { │ │ │ │ │ - if (!this.boxOffsets) { │ │ │ │ │ - // Determine the box model. If the testDiv's clientWidth is 3, then │ │ │ │ │ - // the borders are outside and we are dealing with the w3c box │ │ │ │ │ - // model. Otherwise, the browser uses the traditional box model and │ │ │ │ │ - // the borders are inside the box bounds, leaving us with a │ │ │ │ │ - // clientWidth of 1. │ │ │ │ │ - var testDiv = document.createElement("div"); │ │ │ │ │ - //testDiv.style.visibility = "hidden"; │ │ │ │ │ - testDiv.style.position = "absolute"; │ │ │ │ │ - testDiv.style.border = "1px solid black"; │ │ │ │ │ - testDiv.style.width = "3px"; │ │ │ │ │ - document.body.appendChild(testDiv); │ │ │ │ │ - var w3cBoxModel = testDiv.clientWidth == 3; │ │ │ │ │ - document.body.removeChild(testDiv); │ │ │ │ │ - │ │ │ │ │ - var left = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ - "border-left-width")); │ │ │ │ │ - var right = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ - this.zoomBox, "border-right-width")); │ │ │ │ │ - var top = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ - "border-top-width")); │ │ │ │ │ - var bottom = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ - this.zoomBox, "border-bottom-width")); │ │ │ │ │ - this.boxOffsets = { │ │ │ │ │ - left: left, │ │ │ │ │ - right: right, │ │ │ │ │ - top: top, │ │ │ │ │ - bottom: bottom, │ │ │ │ │ - width: w3cBoxModel === false ? left + right : 0, │ │ │ │ │ - height: w3cBoxModel === false ? top + bottom : 0 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - return this.boxOffsets; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Box" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Keyboard.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.handler.Keyboard │ │ │ │ │ - * A handler for keyboard events. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /* http://www.quirksmode.org/js/keys.html explains key x-browser │ │ │ │ │ - key handling quirks in pretty nice detail */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_EVENTS │ │ │ │ │ - * keydown, keypress, keyup │ │ │ │ │ - */ │ │ │ │ │ - KEY_EVENTS: ["keydown", "keyup"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: eventListener │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - eventListener: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: observeElement │ │ │ │ │ - * {DOMElement|String} The DOM element on which we listen for │ │ │ │ │ - * key events. Default to the document. │ │ │ │ │ + * {String} A feature id or undefined. │ │ │ │ │ */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ + getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ - * Returns a new keyboard handler. │ │ │ │ │ + * Method: eraseFeatures │ │ │ │ │ + * This is called by the layer to erase features │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handlers setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object containing a single function to be │ │ │ │ │ - * called when the drag operation is finished. The callback should │ │ │ │ │ - * expect to recieve a single argument, the pixel location of the event. │ │ │ │ │ - * Callbacks for 'keydown', 'keypress', and 'keyup' are supported. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * handler. │ │ │ │ │ + * features - {Array()} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - // cache the bound event listener method so it can be unobserved later │ │ │ │ │ - this.eventListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ - this.handleKeyEvent, this │ │ │ │ │ - ); │ │ │ │ │ + eraseFeatures: function(features) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ + features = [features]; │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + var feature = features[i]; │ │ │ │ │ + this.eraseGeometry(feature.geometry, feature.id); │ │ │ │ │ + this.removeText(feature.id); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: eraseGeometry │ │ │ │ │ + * Remove a geometry from the renderer (by id). │ │ │ │ │ + * virtual function. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.eventListener = null; │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: moveRoot │ │ │ │ │ + * moves this renderer's root to a (different) renderer. │ │ │ │ │ + * To be implemented by subclasses that require a common renderer root for │ │ │ │ │ + * feature selection. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * renderer - {} target renderer for the moved root │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.observeElement = this.observeElement || document; │ │ │ │ │ - for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ - OpenLayers.Event.observe( │ │ │ │ │ - this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + moveRoot: function(renderer) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: getRenderLayerId │ │ │ │ │ + * Gets the layer that this renderer's output appears on. If moveRoot was │ │ │ │ │ + * used, this will be different from the id of the layer containing the │ │ │ │ │ + * features rendered by this renderer. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} the id of the output layer. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ - OpenLayers.Event.stopObserving( │ │ │ │ │ - this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ - } │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + getRenderLayerId: function() { │ │ │ │ │ + return this.container.id; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleKeyEvent │ │ │ │ │ + * Method: applyDefaultSymbolizer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * symbolizer - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - handleKeyEvent: function(evt) { │ │ │ │ │ - if (this.checkModifiers(evt)) { │ │ │ │ │ - this.callback(evt.type, [evt]); │ │ │ │ │ + applyDefaultSymbolizer: function(symbolizer) { │ │ │ │ │ + var result = OpenLayers.Util.extend({}, │ │ │ │ │ + OpenLayers.Renderer.defaultSymbolizer); │ │ │ │ │ + if (symbolizer.stroke === false) { │ │ │ │ │ + delete result.strokeWidth; │ │ │ │ │ + delete result.strokeColor; │ │ │ │ │ } │ │ │ │ │ + if (symbolizer.fill === false) { │ │ │ │ │ + delete result.fillColor; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.extend(result, symbolizer); │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Keyboard" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Renderer" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Renderer.defaultSymbolizer │ │ │ │ │ + * {Object} Properties from this symbolizer will be applied to symbolizers │ │ │ │ │ + * with missing properties. This can also be used to set a global │ │ │ │ │ + * symbolizer default in OpenLayers. To be SLD 1.x compliant, add the │ │ │ │ │ + * following code before rendering any vector features: │ │ │ │ │ + * (code) │ │ │ │ │ + * OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ + * fillColor: "#808080", │ │ │ │ │ + * fillOpacity: 1, │ │ │ │ │ + * strokeColor: "#000000", │ │ │ │ │ + * strokeOpacity: 1, │ │ │ │ │ + * strokeWidth: 1, │ │ │ │ │ + * pointRadius: 3, │ │ │ │ │ + * graphicName: "square" │ │ │ │ │ + * }; │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ + fillColor: "#000000", │ │ │ │ │ + strokeColor: "#000000", │ │ │ │ │ + strokeWidth: 2, │ │ │ │ │ + fillOpacity: 1, │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + pointRadius: 0, │ │ │ │ │ + labelAlign: 'cm' │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Renderer.symbol │ │ │ │ │ + * Coordinate arrays for well known (named) symbols. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Renderer.symbol = { │ │ │ │ │ + "star": [350, 75, 379, 161, 469, 161, 397, 215, 423, 301, 350, 250, 277, 301, │ │ │ │ │ + 303, 215, 231, 161, 321, 161, 350, 75 │ │ │ │ │ + ], │ │ │ │ │ + "cross": [4, 0, 6, 0, 6, 4, 10, 4, 10, 6, 6, 6, 6, 10, 4, 10, 4, 6, 0, 6, 0, 4, 4, 4, │ │ │ │ │ + 4, 0 │ │ │ │ │ + ], │ │ │ │ │ + "x": [0, 0, 25, 0, 50, 35, 75, 0, 100, 0, 65, 50, 100, 100, 75, 100, 50, 65, 25, 100, 0, 100, 35, 50, 0, 0], │ │ │ │ │ + "square": [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], │ │ │ │ │ + "triangle": [0, 10, 10, 10, 5, 0, 0, 10] │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Point.js │ │ │ │ │ + OpenLayers/Icon.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Point │ │ │ │ │ - * Handler to draw a point on the map. Point is displayed on activation, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. The handler triggers │ │ │ │ │ - * callbacks for 'done', 'cancel', and 'modify'. The modify callback is │ │ │ │ │ - * called with each change in the sketch and will receive the latest point │ │ │ │ │ - * drawn. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Icon │ │ │ │ │ + * │ │ │ │ │ + * The icon represents a graphical icon on the screen. Typically used in │ │ │ │ │ + * conjunction with a to represent markers on a screen. │ │ │ │ │ + * │ │ │ │ │ + * An icon has a url, size and position. It also contains an offset which │ │ │ │ │ + * allows the center point to be represented correctly. This can be │ │ │ │ │ + * provided either as a fixed offset or a function provided to calculate │ │ │ │ │ + * the desired offset. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: point │ │ │ │ │ - * {} The currently drawn point │ │ │ │ │ - */ │ │ │ │ │ - point: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The temporary drawing layer │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ +OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multi │ │ │ │ │ - * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ - * layer. Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} image url │ │ │ │ │ */ │ │ │ │ │ - multi: false, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: citeCompliant │ │ │ │ │ - * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ - * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ - citeCompliant: false, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: mouseDown │ │ │ │ │ - * {Boolean} The mouse is down │ │ │ │ │ + /** │ │ │ │ │ + * Property: offset │ │ │ │ │ + * {|Object} distance in pixels to offset the │ │ │ │ │ + * image when being rendered. An OpenLayers.Pixel or an object │ │ │ │ │ + * with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - mouseDown: false, │ │ │ │ │ + offset: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: stoppedDown │ │ │ │ │ - * {Boolean} Indicate whether the last mousedown stopped the event │ │ │ │ │ - * propagation. │ │ │ │ │ + /** │ │ │ │ │ + * Property: calculateOffset │ │ │ │ │ + * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ */ │ │ │ │ │ - stoppedDown: null, │ │ │ │ │ + calculateOffset: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastDown │ │ │ │ │ - * {} Location of the last mouse down │ │ │ │ │ + /** │ │ │ │ │ + * Property: imageDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - lastDown: null, │ │ │ │ │ + imageDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastUp │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: px │ │ │ │ │ + * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ + * with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - lastUp: null, │ │ │ │ │ + px: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Leave the feature rendered until destroyFeature is called. │ │ │ │ │ - * Default is false. If set to true, the feature remains rendered until │ │ │ │ │ - * destroyFeature is called, typically by deactivating the handler or │ │ │ │ │ - * starting another drawing. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Icon │ │ │ │ │ + * Creates an icon, which is an image tag in a div. │ │ │ │ │ + * │ │ │ │ │ + * url - {String} │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or an │ │ │ │ │ + * object with a 'w' and 'h' │ │ │ │ │ + * properties. │ │ │ │ │ + * offset - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ + * object with a 'x' and 'y' │ │ │ │ │ + * properties. │ │ │ │ │ + * calculateOffset - {Function} │ │ │ │ │ */ │ │ │ │ │ - persist: false, │ │ │ │ │ + initialize: function(url, size, offset, calculateOffset) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + this.size = size || { │ │ │ │ │ + w: 20, │ │ │ │ │ + h: 20 │ │ │ │ │ + }; │ │ │ │ │ + this.offset = offset || { │ │ │ │ │ + x: -(this.size.w / 2), │ │ │ │ │ + y: -(this.size.h / 2) │ │ │ │ │ + }; │ │ │ │ │ + this.calculateOffset = calculateOffset; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: stopDown │ │ │ │ │ - * {Boolean} Stop event propagation on mousedown. Must be false to │ │ │ │ │ - * allow "pan while drawing". Defaults to false. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: false, │ │ │ │ │ + var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ + this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIPropery: stopUp │ │ │ │ │ - * {Boolean} Stop event propagation on mouse. Must be false to │ │ │ │ │ - * allow "pan while dragging". Defaults to fase. │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Nullify references and remove event listeners to prevent circular │ │ │ │ │ + * references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - stopUp: false, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // erase any drawn elements │ │ │ │ │ + this.erase(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerOptions │ │ │ │ │ - * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ - */ │ │ │ │ │ - layerOptions: null, │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ + this.imageDiv.innerHTML = ""; │ │ │ │ │ + this.imageDiv = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Number} Maximum number of pixels between down and up (mousedown │ │ │ │ │ - * and mouseup, or touchstart and touchend) for the handler to │ │ │ │ │ - * add a new point. If set to an integer value, if the │ │ │ │ │ - * displacement between down and up is great to this value │ │ │ │ │ - * no point will be added. Default value is 5. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A fresh copy of the icon. │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: 5, │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Icon(this.url, │ │ │ │ │ + this.size, │ │ │ │ │ + this.offset, │ │ │ │ │ + this.calculateOffset); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastTouchPx │ │ │ │ │ - * {} The last pixel used to know the distance between │ │ │ │ │ - * two touches (for double touch). │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ - lastTouchPx: null, │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + if (size != null) { │ │ │ │ │ + this.size = size; │ │ │ │ │ + } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Point │ │ │ │ │ - * Create a new point handler. │ │ │ │ │ - * │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the point geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - if (!(options && options.layerOptions && options.layerOptions.styleMap)) { │ │ │ │ │ - this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + if (url != null) { │ │ │ │ │ + this.url = url; │ │ │ │ │ } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Move the div to the given pixel. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ + * object with a 'x' and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A new DOM Image of this icon set at the location passed-in │ │ │ │ │ + */ │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + this.size, │ │ │ │ │ + this.url, │ │ │ │ │ + "absolute"); │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + return this.imageDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * turn on the handler │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erase the underlying image element. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - return false; │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ + OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ } │ │ │ │ │ - // create temporary vector layer for rendering geometry sketch │ │ │ │ │ - // TBD: this could be moved to initialize/destroy - setting visibility here │ │ │ │ │ - var options = OpenLayers.Util.extend({ │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - // indicate that the temp vector layer will never be out of range │ │ │ │ │ - // without this, resolution properties must be specified at the │ │ │ │ │ - // map-level for this temporary layer to init its resolutions │ │ │ │ │ - // correctly │ │ │ │ │ - calculateInRange: OpenLayers.Function.True, │ │ │ │ │ - wrapDateLine: this.citeCompliant │ │ │ │ │ - }, this.layerOptions); │ │ │ │ │ - this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ - this.map.addLayer(this.layer); │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary features │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the icon's opacity │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} A pixel location on the map. │ │ │ │ │ + * opacity - {float} │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.point]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ + null, null, null, null, opacity); │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * turn off the handler │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * move icon to passed in px. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - return false; │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + //if no px passed in, use stored location │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.px = px; │ │ │ │ │ } │ │ │ │ │ - this.cancel(); │ │ │ │ │ - // If a layer's map property is set to null, it means that that layer │ │ │ │ │ - // isn't added to the map. Since we ourself added the layer to the map │ │ │ │ │ - // in activate(), we can assume that if this.layer.map is null it means │ │ │ │ │ - // that the layer has been destroyed (as a result of map.destroy() for │ │ │ │ │ - // example. │ │ │ │ │ - if (this.layer.map != null) { │ │ │ │ │ - this.destroyFeature(true); │ │ │ │ │ - this.layer.destroy(false); │ │ │ │ │ + │ │ │ │ │ + if (this.imageDiv != null) { │ │ │ │ │ + if (this.px == null) { │ │ │ │ │ + this.display(false); │ │ │ │ │ + } else { │ │ │ │ │ + if (this.calculateOffset) { │ │ │ │ │ + this.offset = this.calculateOffset(this.size); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { │ │ │ │ │ + x: this.px.x + this.offset.x, │ │ │ │ │ + y: this.px.y + this.offset.y │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy the temporary geometries │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - if (this.layer && (force || !this.persist)) { │ │ │ │ │ - this.layer.destroyFeatures(); │ │ │ │ │ - } │ │ │ │ │ - this.point = null; │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyPersistedFeature │ │ │ │ │ - * Destroy the persisted feature. │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ */ │ │ │ │ │ - destroyPersistedFeature: function() { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - if (layer && layer.features.length > 1) { │ │ │ │ │ - this.layer.features[0].destroy(); │ │ │ │ │ - } │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + // nodeType 11 for ie, whose nodes *always* have a parentNode │ │ │ │ │ + // (of type document fragment) │ │ │ │ │ + var isDrawn = (this.imageDiv && this.imageDiv.parentNode && │ │ │ │ │ + (this.imageDiv.parentNode.nodeType != 11)); │ │ │ │ │ + │ │ │ │ │ + return isDrawn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: finalize │ │ │ │ │ - * Finish the geometry and call the "done" callback. │ │ │ │ │ + CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Marker.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Icon.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Marker │ │ │ │ │ + * Instances of OpenLayers.Marker are a combination of a │ │ │ │ │ + * and an . │ │ │ │ │ + * │ │ │ │ │ + * Markers are generally added to a special layer called │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * var markers = new OpenLayers.Layer.Markers( "Markers" ); │ │ │ │ │ + * map.addLayer(markers); │ │ │ │ │ + * │ │ │ │ │ + * var size = new OpenLayers.Size(21,25); │ │ │ │ │ + * var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); │ │ │ │ │ + * var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset); │ │ │ │ │ + * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon)); │ │ │ │ │ + * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone())); │ │ │ │ │ + * │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Note that if you pass an icon into the Marker constructor, it will take │ │ │ │ │ + * that icon and use it. This means that you should not share icons between │ │ │ │ │ + * markers -- you use them once, but you should clone() for any additional │ │ │ │ │ + * markers using that same icon. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: icon │ │ │ │ │ + * {} The icon used by this marker. │ │ │ │ │ + */ │ │ │ │ │ + icon: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} location of object │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} the event handler. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} the map this marker is attached to │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Marker │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * cancel - {Boolean} Call cancel instead of done callback. Default │ │ │ │ │ - * is false. │ │ │ │ │ + * lonlat - {} the position of this marker │ │ │ │ │ + * icon - {} the icon for this marker │ │ │ │ │ */ │ │ │ │ │ - finalize: function(cancel) { │ │ │ │ │ - var key = cancel ? "cancel" : "done"; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - this.lastDown = null; │ │ │ │ │ - this.lastUp = null; │ │ │ │ │ - this.lastTouchPx = null; │ │ │ │ │ - this.callback(key, [this.geometryClone()]); │ │ │ │ │ - this.destroyFeature(cancel); │ │ │ │ │ + initialize: function(lonlat, icon) { │ │ │ │ │ + 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy the marker. You must first remove the marker from any │ │ │ │ │ + * layer which it has been added to, or you will get buggy behavior. │ │ │ │ │ + * (This can not be done within the marker since the marker does not │ │ │ │ │ + * know which layer it is attached to.) │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.finalize(true); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // erase any drawn features │ │ │ │ │ + this.erase(); │ │ │ │ │ + │ │ │ │ │ + this.map = null; │ │ │ │ │ + │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.destroy(); │ │ │ │ │ + this.icon = null; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * Handle clicks. Clicks are stopped from propagating to other listeners │ │ │ │ │ - * on map.events or other dom elements. │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Calls draw on the icon, and returns that output. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ + * location passed-in │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - return false; │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + return this.icon.draw(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle double-clicks. Double-clicks are stopped from propagating to other │ │ │ │ │ - * listeners on map.events or other dom elements. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erases any drawn elements for this marker. │ │ │ │ │ */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - return false; │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.erase(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: modifyFeature │ │ │ │ │ - * Modify the existing geometry given a pixel location. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Move the marker to the new location. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} A pixel location on the map. │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - modifyFeature: function(pixel) { │ │ │ │ │ - if (!this.point) { │ │ │ │ │ - this.createFeature(pixel); │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.icon != null)) { │ │ │ │ │ + this.icon.moveTo(px); │ │ │ │ │ } │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point.geometry.x = lonlat.lon; │ │ │ │ │ - this.point.geometry.y = lonlat.lat; │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.point, false]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ + this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render features on the temporary layer. │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ + return isDrawn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ + * Method: onScreen │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.point && this.point.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiPoint([geometry]); │ │ │ │ │ + onScreen: function() { │ │ │ │ │ + │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var screenBounds = this.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ } │ │ │ │ │ - return geometry; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: geometryClone │ │ │ │ │ - * Return a clone of the relevant geometry. │ │ │ │ │ + * Method: inflate │ │ │ │ │ + * Englarges the markers icon by the specified ratio. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ + * will double the size). │ │ │ │ │ */ │ │ │ │ │ - geometryClone: function() { │ │ │ │ │ - var geom = this.getGeometry(); │ │ │ │ │ - return geom && geom.clone(); │ │ │ │ │ + inflate: function(inflate) { │ │ │ │ │ + if (this.icon) { │ │ │ │ │ + this.icon.setSize({ │ │ │ │ │ + w: this.icon.size.w * inflate, │ │ │ │ │ + h: this.icon.size.h * inflate │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the opacity of the marker by changin the opacity of │ │ │ │ │ + * its icon │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.down(evt); │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + this.icon.setOpacity(opacity); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart. │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * Change URL of the Icon Image. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - this.lastTouchPx = evt.xy; │ │ │ │ │ - return this.down(evt); │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + this.icon.setUrl(url); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mousemove. │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.move(evt); │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.icon.display(display); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Marker" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Function: defaultIcon │ │ │ │ │ + * Creates a default . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A default OpenLayers.Icon to use for a marker │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Marker.defaultIcon = function() { │ │ │ │ │ + return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"), { │ │ │ │ │ + w: 21, │ │ │ │ │ + h: 25 │ │ │ │ │ + }, { │ │ │ │ │ + x: -10.5, │ │ │ │ │ + y: -25 │ │ │ │ │ + }); │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Layer.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: URL_HASH_FACTOR │ │ │ │ │ + * {Float} Used to hash URL param strings for multi-WMS server selection. │ │ │ │ │ + * Set to the Golden Ratio per Knuth's recommendation. │ │ │ │ │ + */ │ │ │ │ │ + URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ + * a single url string. │ │ │ │ │ + */ │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: params │ │ │ │ │ + * {Object} Hashtable of key/value parameters │ │ │ │ │ + */ │ │ │ │ │ + params: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: reproject │ │ │ │ │ + * *Deprecated*. See http://docs.openlayers.org/library/spherical_mercator.html │ │ │ │ │ + * for information on the replacement for this functionality. │ │ │ │ │ + * {Boolean} Whether layer should reproject itself based on base layer │ │ │ │ │ + * locations. This allows reprojection onto commercial layers. │ │ │ │ │ + * Default is false: Most layers can't reproject, but layers │ │ │ │ │ + * which can create non-square geographic pixels can, like WMS. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + reproject: false, │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove. │ │ │ │ │ + * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {Array(String) or String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.lastTouchPx = evt.xy; │ │ │ │ │ - return this.move(evt); │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); │ │ │ │ │ + this.url = url; │ │ │ │ │ + if (!this.params) { │ │ │ │ │ + this.params = OpenLayers.Util.extend({}, params); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.up(evt); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.url = null; │ │ │ │ │ + this.params = null; │ │ │ │ │ + OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * obj - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - evt.xy = this.lastTouchPx; │ │ │ │ │ - return this.up(evt); │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.HTTPRequest(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ + │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Handle mousedown and touchstart. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setUrl │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * newUrl - {String} │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - this.mouseDown = true; │ │ │ │ │ - this.lastDown = evt.xy; │ │ │ │ │ - if (!this.touch) { // no point displayed until up on touch devices │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - return !this.stopDown; │ │ │ │ │ + setUrl: function(newUrl) { │ │ │ │ │ + this.url = newUrl; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - if (!this.touch // no point displayed until up on touch devices │ │ │ │ │ - && │ │ │ │ │ - (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ + mergeNewParams: function(newParams) { │ │ │ │ │ + this.params = OpenLayers.Util.extend(this.params, newParams); │ │ │ │ │ + var ret = this.redraw(); │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "params" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return ret; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Handle mouseup and touchend. Send the latest point in the geometry to the control. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - │ │ │ │ │ - // check keyboard modifiers │ │ │ │ │ - if (!this.checkModifiers(evt)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - // ignore double-clicks │ │ │ │ │ - if (this.lastUp && this.lastUp.equals(evt.xy)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance)) { │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.lastUp = evt.xy; │ │ │ │ │ - this.finalize(); │ │ │ │ │ - return !this.stopUp; │ │ │ │ │ + redraw: function(force) { │ │ │ │ │ + if (force) { │ │ │ │ │ + return this.mergeNewParams({ │ │ │ │ │ + "_olSalt": Math.random() │ │ │ │ │ + }); │ │ │ │ │ } else { │ │ │ │ │ - return true; │ │ │ │ │ + return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Handle mouse out. For better user experience reset mouseDown │ │ │ │ │ - * and stoppedDown when the mouse leaves the map viewport. │ │ │ │ │ + * Method: selectUrl │ │ │ │ │ + * selectUrl() implements the standard floating-point multiplicative │ │ │ │ │ + * hash function described by Knuth, and hashes the contents of the │ │ │ │ │ + * given param string into a float between 0 and 1. This float is then │ │ │ │ │ + * scaled to the size of the provided urls array, and used to select │ │ │ │ │ + * a URL. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * paramString - {String} │ │ │ │ │ + * urls - {Array(String)} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ + * on the paramString. │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ + selectUrl: function(paramString, urls) { │ │ │ │ │ + var product = 1; │ │ │ │ │ + for (var i = 0, len = paramString.length; i < len; i++) { │ │ │ │ │ + product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR; │ │ │ │ │ + product -= Math.floor(product); │ │ │ │ │ } │ │ │ │ │ + return urls[Math.floor(product * urls.length)]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the event is within the optional pixel tolerance. │ │ │ │ │ + /** │ │ │ │ │ + * Method: getFullRequestString │ │ │ │ │ + * Combine url with layer's params and these newParams. │ │ │ │ │ + * │ │ │ │ │ + * does checking on the serverPath variable, allowing for cases when it │ │ │ │ │ + * is supplied with trailing ? or &, as well as cases where not. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The event is within the pixel tolerance (if specified). │ │ │ │ │ + * return in formatted string like this: │ │ │ │ │ + * "server?key1=value1&key2=value2&key3=value3" │ │ │ │ │ + * │ │ │ │ │ + * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - passesTolerance: function(pixel1, pixel2, tolerance) { │ │ │ │ │ - var passes = true; │ │ │ │ │ + getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ │ │ │ │ │ - if (tolerance != null && pixel1 && pixel2) { │ │ │ │ │ - var dist = pixel1.distanceTo(pixel2); │ │ │ │ │ - if (dist > tolerance) { │ │ │ │ │ - passes = false; │ │ │ │ │ + // if not altUrl passed in, use layer's url │ │ │ │ │ + var url = altUrl || this.url; │ │ │ │ │ + │ │ │ │ │ + // create a new params hashtable with all the layer params and the │ │ │ │ │ + // new params together. then convert to string │ │ │ │ │ + var allParams = OpenLayers.Util.extend({}, this.params); │ │ │ │ │ + allParams = OpenLayers.Util.extend(allParams, newParams); │ │ │ │ │ + var paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ + │ │ │ │ │ + // if url is not a string, it should be an array of strings, │ │ │ │ │ + // in which case we will deterministically select one of them in │ │ │ │ │ + // order to evenly distribute requests to different urls. │ │ │ │ │ + // │ │ │ │ │ + if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ + url = this.selectUrl(paramsString, url); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // ignore parameters that are already in the url search string │ │ │ │ │ + var urlParams = │ │ │ │ │ + OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); │ │ │ │ │ + for (var key in allParams) { │ │ │ │ │ + if (key.toUpperCase() in urlParams) { │ │ │ │ │ + delete allParams[key]; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ + paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ + │ │ │ │ │ + return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Point" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.HTTPRequest" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Path.js │ │ │ │ │ + OpenLayers/Tile/Image.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Tile.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Path │ │ │ │ │ - * Handler to draw a path on the map. Path is displayed on mouse down, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. │ │ │ │ │ + * Class: OpenLayers.Tile.Image │ │ │ │ │ + * Instances of OpenLayers.Tile.Image are used to manage the image tiles │ │ │ │ │ + * used by various layers. Create a new image tile with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { │ │ │ │ │ +OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: line │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the tile. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * tile.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to the events): │ │ │ │ │ + * beforeload - Triggered before an image is prepared for loading, when the │ │ │ │ │ + * url for the image is known already. Listeners may call on │ │ │ │ │ + * the tile instance. If they do so, that image will be used and no new │ │ │ │ │ + * one will be created. │ │ │ │ │ */ │ │ │ │ │ - line: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxVertices │ │ │ │ │ - * {Number} The maximum number of vertices which can be drawn by this │ │ │ │ │ - * handler. When the number of vertices reaches maxVertices, the │ │ │ │ │ - * geometry is automatically finalized. Default is null. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} The URL of the image being requested. No default. Filled in by │ │ │ │ │ + * layer.getURL() function. May be modified by loadstart listeners. │ │ │ │ │ */ │ │ │ │ │ - maxVertices: null, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: doubleTouchTolerance │ │ │ │ │ - * {Number} Maximum number of pixels between two touches for │ │ │ │ │ - * the gesture to be considered a "finalize feature" action. │ │ │ │ │ - * Default is 20. │ │ │ │ │ + /** │ │ │ │ │ + * Property: imgDiv │ │ │ │ │ + * {HTMLImageElement} The image for this tile. │ │ │ │ │ */ │ │ │ │ │ - doubleTouchTolerance: 20, │ │ │ │ │ + imgDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: freehand │ │ │ │ │ - * {Boolean} In freehand mode, the handler starts the path on mouse down, │ │ │ │ │ - * adds a point for every mouse move, and finishes the path on mouse up. │ │ │ │ │ - * Outside of freehand mode, a point is added to the path on every mouse │ │ │ │ │ - * click and double-click finishes the path. │ │ │ │ │ + * Property: frame │ │ │ │ │ + * {DOMElement} The image element is appended to the frame. Any gutter on │ │ │ │ │ + * the image will be hidden behind the frame. If no gutter is set, │ │ │ │ │ + * this will be null. │ │ │ │ │ */ │ │ │ │ │ - freehand: false, │ │ │ │ │ + frame: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: freehandToggle │ │ │ │ │ - * {String} If set, freehandToggle is checked on mouse events and will set │ │ │ │ │ - * the freehand mode to the opposite of this.freehand. To disallow │ │ │ │ │ - * toggling between freehand and non-freehand mode, set freehandToggle to │ │ │ │ │ - * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and 'altKey'. │ │ │ │ │ + /** │ │ │ │ │ + * Property: imageReloadAttempts │ │ │ │ │ + * {Integer} Attempts to load the image. │ │ │ │ │ */ │ │ │ │ │ - freehandToggle: 'shiftKey', │ │ │ │ │ + imageReloadAttempts: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Integer} The timer used to test the double touch. │ │ │ │ │ + * Property: layerAlphaHack │ │ │ │ │ + * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + layerAlphaHack: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: redoStack │ │ │ │ │ - * {Array} Stack containing points removed with . │ │ │ │ │ + * Property: asyncRequestId │ │ │ │ │ + * {Integer} ID of an request to see if request is still valid. This is a │ │ │ │ │ + * number which increments by 1 for each asynchronous request. │ │ │ │ │ */ │ │ │ │ │ - redoStack: null, │ │ │ │ │ + asyncRequestId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Path │ │ │ │ │ - * Create a new path hander │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ + * APIProperty: maxGetUrlLength │ │ │ │ │ + * {Number} If set, requests that would result in GET urls with more │ │ │ │ │ + * characters than the number provided will be made using form-encoded │ │ │ │ │ + * HTTP POST. It is good practice to avoid urls that are longer than 2048 │ │ │ │ │ + * characters. │ │ │ │ │ * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the linestring geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + * Caution: │ │ │ │ │ + * Older versions of Gecko based browsers (e.g. Firefox < 3.5) and most │ │ │ │ │ + * Opera versions do not fully support this option. On all browsers, │ │ │ │ │ + * transition effects are not supported if POST requests are used. │ │ │ │ │ */ │ │ │ │ │ + maxGetUrlLength: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The initial pixel location for the new │ │ │ │ │ - * feature. │ │ │ │ │ + * Property: canvasContext │ │ │ │ │ + * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ + * the tile image. │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LineString([this.point.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.line, this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + canvasContext: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * APIProperty: crossOriginKeyword │ │ │ │ │ + * The value of the crossorigin keyword to use when loading images. This is │ │ │ │ │ + * only relevant when using for tiles from remote │ │ │ │ │ + * origins and should be set to either 'anonymous' or 'use-credentials' │ │ │ │ │ + * for servers that send Access-Control-Allow-Origin headers with their │ │ │ │ │ + * tiles. │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - OpenLayers.Handler.Point.prototype.destroyFeature.call( │ │ │ │ │ - this, force); │ │ │ │ │ - this.line = null; │ │ │ │ │ - }, │ │ │ │ │ + crossOriginKeyword: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPersistedFeature │ │ │ │ │ - * Destroy the persisted feature. │ │ │ │ │ + /** TBD 3.0 - reorder the parameters to the init function to remove │ │ │ │ │ + * URL. the getUrl() function on the layer gets called on │ │ │ │ │ + * each draw(), so no need to specify it here. │ │ │ │ │ */ │ │ │ │ │ - destroyPersistedFeature: function() { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - if (layer && layer.features.length > 2) { │ │ │ │ │ - this.layer.features[0].destroy(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removePoint │ │ │ │ │ - * Destroy the temporary point. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile.Image │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} layer that the tile will go in. │ │ │ │ │ + * position - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ + * size - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - removePoint: function() { │ │ │ │ │ - if (this.point) { │ │ │ │ │ - this.layer.removeFeatures([this.point]); │ │ │ │ │ + initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ + OpenLayers.Tile.prototype.initialize.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + this.url = url; //deprecated remove me │ │ │ │ │ + │ │ │ │ │ + this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); │ │ │ │ │ + │ │ │ │ │ + if (this.maxGetUrlLength != null || this.layer.gutter || this.layerAlphaHack) { │ │ │ │ │ + // only create frame if it's needed │ │ │ │ │ + this.frame = document.createElement("div"); │ │ │ │ │ + this.frame.style.position = "absolute"; │ │ │ │ │ + this.frame.style.overflow = "hidden"; │ │ │ │ │ + } │ │ │ │ │ + if (this.maxGetUrlLength != null) { │ │ │ │ │ + OpenLayers.Util.extend(this, OpenLayers.Tile.Image.IFrame); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addPoint │ │ │ │ │ - * Add point to geometry. Send the point index to override │ │ │ │ │ - * the behavior of LinearRing that disregards adding duplicate points. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The pixel location for the new point. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - addPoint: function(pixel) { │ │ │ │ │ - this.layer.removeFeatures([this.point]); │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) │ │ │ │ │ - ); │ │ │ │ │ - this.line.geometry.addComponent( │ │ │ │ │ - this.point.geometry, this.line.geometry.components.length │ │ │ │ │ - ); │ │ │ │ │ - this.layer.addFeatures([this.point]); │ │ │ │ │ - this.callback("point", [this.point.geometry, this.getGeometry()]); │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - delete this.redoStack; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.imgDiv) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + this.frame = null; │ │ │ │ │ + } │ │ │ │ │ + // don't handle async requests any more │ │ │ │ │ + this.asyncRequestId = null; │ │ │ │ │ + OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: insertXY │ │ │ │ │ - * Insert a point in the current sketch given x & y coordinates. The new │ │ │ │ │ - * point is inserted immediately before the most recently drawn point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Number} The x-coordinate of the point. │ │ │ │ │ - * y - {Number} The y-coordinate of the point. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Check that a tile should be drawn, and draw it. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Was a tile drawn? Or null if a beforedraw listener returned │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - insertXY: function(x, y) { │ │ │ │ │ - this.line.geometry.addComponent( │ │ │ │ │ - new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ - this.getCurrentPointIndex() │ │ │ │ │ - ); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - delete this.redoStack; │ │ │ │ │ + draw: function() { │ │ │ │ │ + var shouldDraw = OpenLayers.Tile.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (shouldDraw) { │ │ │ │ │ + // The layer's reproject option is deprecated. │ │ │ │ │ + if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { │ │ │ │ │ + // getBoundsFromBaseLayer is defined in deprecated.js. │ │ │ │ │ + this.bounds = this.getBoundsFromBaseLayer(this.position); │ │ │ │ │ + } │ │ │ │ │ + if (this.isLoading) { │ │ │ │ │ + //if we're already loading, send 'reload' instead of 'loadstart'. │ │ │ │ │ + this._loadEvent = "reload"; │ │ │ │ │ + } else { │ │ │ │ │ + this.isLoading = true; │ │ │ │ │ + this._loadEvent = "loadstart"; │ │ │ │ │ + } │ │ │ │ │ + this.renderTile(); │ │ │ │ │ + this.positionTile(); │ │ │ │ │ + } else if (shouldDraw === false) { │ │ │ │ │ + this.unload(); │ │ │ │ │ + } │ │ │ │ │ + return shouldDraw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: insertDeltaXY │ │ │ │ │ - * Insert a point given offsets from the previously inserted point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} The x-coordinate offset of the point. │ │ │ │ │ - * dy - {Number} The y-coordinate offset of the point. │ │ │ │ │ + * Method: renderTile │ │ │ │ │ + * Internal function to actually initialize the image tile, │ │ │ │ │ + * position it correctly, and set its url. │ │ │ │ │ */ │ │ │ │ │ - insertDeltaXY: function(dx, dy) { │ │ │ │ │ - var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ - var p0 = this.line.geometry.components[previousIndex]; │ │ │ │ │ - if (p0 && !isNaN(p0.x) && !isNaN(p0.y)) { │ │ │ │ │ - this.insertXY(p0.x + dx, p0.y + dy); │ │ │ │ │ + renderTile: function() { │ │ │ │ │ + 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); │ │ │ │ │ + this.initImage(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: insertDirectionLength │ │ │ │ │ - * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * Method: positionTile │ │ │ │ │ + * Using the properties currenty set on the layer, position the tile correctly. │ │ │ │ │ + * This method is used both by the async and non-async versions of the Tile.Image │ │ │ │ │ + * code. │ │ │ │ │ */ │ │ │ │ │ - insertDirectionLength: function(direction, length) { │ │ │ │ │ - direction *= Math.PI / 180; │ │ │ │ │ - var dx = length * Math.cos(direction); │ │ │ │ │ - var dy = length * Math.sin(direction); │ │ │ │ │ - this.insertDeltaXY(dx, dy); │ │ │ │ │ + positionTile: function() { │ │ │ │ │ + var style = this.getTile().style, │ │ │ │ │ + size = this.frame ? this.size : │ │ │ │ │ + this.layer.getImageSize(this.bounds), │ │ │ │ │ + ratio = 1; │ │ │ │ │ + if (this.layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + ratio = this.layer.getServerResolution() / this.layer.map.getResolution(); │ │ │ │ │ + } │ │ │ │ │ + style.left = this.position.x + "px"; │ │ │ │ │ + style.top = this.position.y + "px"; │ │ │ │ │ + style.width = Math.round(ratio * size.w) + "px"; │ │ │ │ │ + style.height = Math.round(ratio * size.h) + "px"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: insertDeflectionLength │ │ │ │ │ - * Insert a point in the current sketch given a deflection and a length. │ │ │ │ │ - * The deflection should be degrees clockwise from the previously │ │ │ │ │ - * digitized segment. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * deflection - {Number} Degrees clockwise from the previous segment. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Remove the tile from the DOM, clear it of any image related data so that │ │ │ │ │ + * it can be reused in a new location. │ │ │ │ │ */ │ │ │ │ │ - insertDeflectionLength: function(deflection, length) { │ │ │ │ │ - var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ - if (previousIndex > 0) { │ │ │ │ │ - var p1 = this.line.geometry.components[previousIndex]; │ │ │ │ │ - var p0 = this.line.geometry.components[previousIndex - 1]; │ │ │ │ │ - var theta = Math.atan2(p1.y - p0.y, p1.x - p0.x); │ │ │ │ │ - this.insertDirectionLength( │ │ │ │ │ - (theta * 180 / Math.PI) + deflection, length │ │ │ │ │ - ); │ │ │ │ │ + clear: function() { │ │ │ │ │ + OpenLayers.Tile.prototype.clear.apply(this, arguments); │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (img) { │ │ │ │ │ + var tile = this.getTile(); │ │ │ │ │ + if (tile.parentNode === this.layer.div) { │ │ │ │ │ + this.layer.div.removeChild(tile); │ │ │ │ │ + } │ │ │ │ │ + this.setImgSrc(); │ │ │ │ │ + if (this.layerAlphaHack === true) { │ │ │ │ │ + img.style.filter = ""; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Element.removeClass(img, "olImageLoadError"); │ │ │ │ │ } │ │ │ │ │ + this.canvasContext = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentPointIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The index of the most recently drawn point. │ │ │ │ │ + * Method: getImage │ │ │ │ │ + * Returns or creates and returns the tile image. │ │ │ │ │ */ │ │ │ │ │ - getCurrentPointIndex: function() { │ │ │ │ │ - return this.line.geometry.components.length - 1; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ + getImage: function() { │ │ │ │ │ + if (!this.imgDiv) { │ │ │ │ │ + this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: undo │ │ │ │ │ - * Remove the most recently added point in the sketch geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A point was removed. │ │ │ │ │ - */ │ │ │ │ │ - undo: function() { │ │ │ │ │ - var geometry = this.line.geometry; │ │ │ │ │ - var components = geometry.components; │ │ │ │ │ - var index = this.getCurrentPointIndex() - 1; │ │ │ │ │ - var target = components[index]; │ │ │ │ │ - var undone = geometry.removeComponent(target); │ │ │ │ │ - if (undone) { │ │ │ │ │ - // On touch devices, set the current ("mouse location") point to │ │ │ │ │ - // match the last digitized point. │ │ │ │ │ - if (this.touch && index > 0) { │ │ │ │ │ - components = geometry.components; // safety │ │ │ │ │ - var lastpt = components[index - 1]; │ │ │ │ │ - var curptidx = this.getCurrentPointIndex(); │ │ │ │ │ - var curpt = components[curptidx]; │ │ │ │ │ - curpt.x = lastpt.x; │ │ │ │ │ - curpt.y = lastpt.y; │ │ │ │ │ + var style = this.imgDiv.style; │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + var left = 0, │ │ │ │ │ + top = 0; │ │ │ │ │ + if (this.layer.gutter) { │ │ │ │ │ + left = this.layer.gutter / this.layer.tileSize.w * 100; │ │ │ │ │ + top = this.layer.gutter / this.layer.tileSize.h * 100; │ │ │ │ │ + } │ │ │ │ │ + style.left = -left + "%"; │ │ │ │ │ + style.top = -top + "%"; │ │ │ │ │ + style.width = (2 * left + 100) + "%"; │ │ │ │ │ + style.height = (2 * top + 100) + "%"; │ │ │ │ │ } │ │ │ │ │ - if (!this.redoStack) { │ │ │ │ │ - this.redoStack = []; │ │ │ │ │ + style.visibility = "hidden"; │ │ │ │ │ + style.opacity = 0; │ │ │ │ │ + if (this.layer.opacity < 1) { │ │ │ │ │ + style.filter = 'alpha(opacity=' + │ │ │ │ │ + (this.layer.opacity * 100) + │ │ │ │ │ + ')'; │ │ │ │ │ + } │ │ │ │ │ + style.position = "absolute"; │ │ │ │ │ + if (this.layerAlphaHack) { │ │ │ │ │ + // move the image out of sight │ │ │ │ │ + style.paddingTop = style.height; │ │ │ │ │ + style.height = "0"; │ │ │ │ │ + style.width = "100%"; │ │ │ │ │ + } │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + this.frame.appendChild(this.imgDiv); │ │ │ │ │ } │ │ │ │ │ - this.redoStack.push(target); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ } │ │ │ │ │ - return undone; │ │ │ │ │ + │ │ │ │ │ + return this.imgDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: redo │ │ │ │ │ - * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ - * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ + * APIMethod: setImage │ │ │ │ │ + * Sets the image element for this tile. This method should only be called │ │ │ │ │ + * from beforeload listeners. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A point was added. │ │ │ │ │ + * Parameters │ │ │ │ │ + * img - {HTMLImageElement} The image to use for this tile. │ │ │ │ │ */ │ │ │ │ │ - redo: function() { │ │ │ │ │ - var target = this.redoStack && this.redoStack.pop(); │ │ │ │ │ - if (target) { │ │ │ │ │ - this.line.geometry.addComponent(target, this.getCurrentPointIndex()); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - } │ │ │ │ │ - return !!target; │ │ │ │ │ + setImage: function(img) { │ │ │ │ │ + this.imgDiv = img; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: freehandMode │ │ │ │ │ - * Determine whether to behave in freehand mode or not. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Method: initImage │ │ │ │ │ + * Creates the content for the frame on the tile. │ │ │ │ │ */ │ │ │ │ │ - freehandMode: function(evt) { │ │ │ │ │ - return (this.freehandToggle && evt[this.freehandToggle]) ? │ │ │ │ │ - !this.freehand : this.freehand; │ │ │ │ │ + initImage: function() { │ │ │ │ │ + if (!this.url && !this.imgDiv) { │ │ │ │ │ + // fast path out - if there is no tile url and no previous image │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent('beforeload'); │ │ │ │ │ + this.layer.div.appendChild(this.getTile()); │ │ │ │ │ + this.events.triggerEvent(this._loadEvent); │ │ │ │ │ + var img = this.getImage(); │ │ │ │ │ + var src = img.getAttribute('src') || ''; │ │ │ │ │ + if (this.url && OpenLayers.Util.isEquivalentUrl(src, this.url)) { │ │ │ │ │ + this._loadTimeout = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(this.onImageLoad, this), 0 │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + if (this.crossOriginKeyword) { │ │ │ │ │ + img.removeAttribute("crossorigin"); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.observe(img, "load", │ │ │ │ │ + OpenLayers.Function.bind(this.onImageLoad, this) │ │ │ │ │ + ); │ │ │ │ │ + OpenLayers.Event.observe(img, "error", │ │ │ │ │ + OpenLayers.Function.bind(this.onImageError, this) │ │ │ │ │ + ); │ │ │ │ │ + this.imageReloadAttempts = 0; │ │ │ │ │ + this.setImgSrc(this.url); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: modifyFeature │ │ │ │ │ - * Modify the existing geometry given the new point │ │ │ │ │ + * Method: setImgSrc │ │ │ │ │ + * Sets the source for the tile image │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} The updated pixel location for the latest │ │ │ │ │ - * point. │ │ │ │ │ - * drawing - {Boolean} Indicate if we're currently drawing. │ │ │ │ │ + * url - {String} or undefined to hide the image │ │ │ │ │ */ │ │ │ │ │ - modifyFeature: function(pixel, drawing) { │ │ │ │ │ - if (!this.line) { │ │ │ │ │ - this.createFeature(pixel); │ │ │ │ │ + setImgSrc: function(url) { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (url) { │ │ │ │ │ + img.style.visibility = 'hidden'; │ │ │ │ │ + img.style.opacity = 0; │ │ │ │ │ + // don't set crossOrigin if the url is a data URL │ │ │ │ │ + if (this.crossOriginKeyword) { │ │ │ │ │ + if (url.substr(0, 5) !== 'data:') { │ │ │ │ │ + img.setAttribute("crossorigin", this.crossOriginKeyword); │ │ │ │ │ + } else { │ │ │ │ │ + img.removeAttribute("crossorigin"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + img.src = url; │ │ │ │ │ + } else { │ │ │ │ │ + // Remove reference to the image, and leave it to the browser's │ │ │ │ │ + // caching and garbage collection. │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + if (img.parentNode) { │ │ │ │ │ + img.parentNode.removeChild(img); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point.geometry.x = lonlat.lon; │ │ │ │ │ - this.point.geometry.y = lonlat.lat; │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.getSketch(), drawing]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render geometries on the temporary layer. │ │ │ │ │ - */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.line, this.style); │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSketch │ │ │ │ │ - * Return the sketch feature. │ │ │ │ │ + * Method: getTile │ │ │ │ │ + * Get the tile's markup. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {DOMElement} The tile's markup │ │ │ │ │ */ │ │ │ │ │ - getSketch: function() { │ │ │ │ │ - return this.line; │ │ │ │ │ + getTile: function() { │ │ │ │ │ + return this.frame ? this.frame : this.getImage(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ + * Method: createBackBuffer │ │ │ │ │ + * Create a backbuffer for this tile. A backbuffer isn't exactly a clone │ │ │ │ │ + * of the tile's markup, because we want to avoid the reloading of the │ │ │ │ │ + * image. So we clone the frame, and steal the image from the tile. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ + * or if it's currently loading. │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.line && this.line.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiLineString([geometry]); │ │ │ │ │ + createBackBuffer: function() { │ │ │ │ │ + if (!this.imgDiv || this.isLoading) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * method: touchstart │ │ │ │ │ - * handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * parameters: │ │ │ │ │ - * evt - {event} the browser event │ │ │ │ │ - * │ │ │ │ │ - * returns: │ │ │ │ │ - * {boolean} allow event propagation │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - if (this.timerId && │ │ │ │ │ - this.passesTolerance(this.lastTouchPx, evt.xy, │ │ │ │ │ - this.doubleTouchTolerance)) { │ │ │ │ │ - // double-tap, finalize the geometry │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - return false; │ │ │ │ │ + var backBuffer; │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + backBuffer = this.frame.cloneNode(false); │ │ │ │ │ + backBuffer.appendChild(this.imgDiv); │ │ │ │ │ } else { │ │ │ │ │ - if (this.timerId) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - }, this), 300); │ │ │ │ │ - return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt); │ │ │ │ │ + backBuffer = this.imgDiv; │ │ │ │ │ } │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + return backBuffer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Handle mousedown and touchstart. Add a new point to the geometry and │ │ │ │ │ - * render it. Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Method: onImageLoad │ │ │ │ │ + * Handler for the image onload event │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - var stopDown = this.stopDown; │ │ │ │ │ - if (this.freehandMode(evt)) { │ │ │ │ │ - stopDown = true; │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!this.touch && (!this.lastDown || │ │ │ │ │ - !this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance))) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ - } │ │ │ │ │ - this.mouseDown = true; │ │ │ │ │ - this.lastDown = evt.xy; │ │ │ │ │ - this.stoppedDown = stopDown; │ │ │ │ │ - return !stopDown; │ │ │ │ │ - }, │ │ │ │ │ + onImageLoad: function() { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + img.style.visibility = 'inherit'; │ │ │ │ │ + img.style.opacity = this.layer.opacity; │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + this.canvasContext = null; │ │ │ │ │ + this.events.triggerEvent("loadend"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ - */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - if (this.maxVertices && this.line && │ │ │ │ │ - this.line.geometry.components.length === this.maxVertices) { │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - } else { │ │ │ │ │ - this.addPoint(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (!this.touch && (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ + if (this.layerAlphaHack === true) { │ │ │ │ │ + img.style.filter = │ │ │ │ │ + "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + │ │ │ │ │ + img.src + "', sizingMethod='scale')"; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Handle mouseup and touchend. Send the latest point in the geometry to │ │ │ │ │ - * the control. Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Method: onImageError │ │ │ │ │ + * Handler for the image onerror event │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - if (this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) { │ │ │ │ │ - if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ + onImageError: function() { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (img.src != null) { │ │ │ │ │ + this.imageReloadAttempts++; │ │ │ │ │ + if (this.imageReloadAttempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) { │ │ │ │ │ + this.setImgSrc(this.layer.getURL(this.bounds)); │ │ │ │ │ } else { │ │ │ │ │ - if (this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance)) { │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - if (this.lastUp == null && this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.addPoint(evt.xy); │ │ │ │ │ - this.lastUp = evt.xy; │ │ │ │ │ - if (this.line.geometry.components.length === this.maxVertices + 1) { │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Element.addClass(img, "olImageLoadError"); │ │ │ │ │ + this.events.triggerEvent("loaderror"); │ │ │ │ │ + this.onImageLoad(); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - return !this.stopUp; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: finishGeometry │ │ │ │ │ - * Finish the geometry and send it back to the control. │ │ │ │ │ + * Method: stopLoading │ │ │ │ │ + * Stops a loading sequence so won't be executed. │ │ │ │ │ */ │ │ │ │ │ - finishGeometry: function() { │ │ │ │ │ - var index = this.line.geometry.components.length - 1; │ │ │ │ │ - this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ + stopLoading: function() { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ + window.clearTimeout(this._loadTimeout); │ │ │ │ │ + delete this._loadTimeout; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle double-clicks. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * APIMethod: getCanvasContext │ │ │ │ │ + * Returns a canvas context associated with the tile image (with │ │ │ │ │ + * the image drawn on it). │ │ │ │ │ + * Returns undefined if the browser does not support canvas, if │ │ │ │ │ + * the tile has no image or if it's currently loading. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * The function returns a canvas context instance but the │ │ │ │ │ + * underlying canvas is still available in the 'canvas' property: │ │ │ │ │ + * (code) │ │ │ │ │ + * var context = tile.getCanvasContext(); │ │ │ │ │ + * if (context) { │ │ │ │ │ + * var data = context.canvas.toDataURL('image/jpeg'); │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - if (!this.freehandMode(evt)) { │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ + getCanvasContext: function() { │ │ │ │ │ + if (OpenLayers.CANVAS_SUPPORTED && this.imgDiv && !this.isLoading) { │ │ │ │ │ + if (!this.canvasContext) { │ │ │ │ │ + var canvas = document.createElement("canvas"); │ │ │ │ │ + canvas.width = this.size.w; │ │ │ │ │ + canvas.height = this.size.h; │ │ │ │ │ + this.canvasContext = canvas.getContext("2d"); │ │ │ │ │ + this.canvasContext.drawImage(this.imgDiv, 0, 0); │ │ │ │ │ + } │ │ │ │ │ + return this.canvasContext; │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Path" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tile.Image" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Tile.Image.IMAGE │ │ │ │ │ + * {HTMLImageElement} The image for a tile. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Tile.Image.IMAGE = (function() { │ │ │ │ │ + var img = new Image(); │ │ │ │ │ + img.className = "olTileImage"; │ │ │ │ │ + // avoid image gallery menu in IE6 │ │ │ │ │ + img.galleryImg = "no"; │ │ │ │ │ + return img; │ │ │ │ │ +}()); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Polygon.js │ │ │ │ │ + OpenLayers/Layer/Grid.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ + * @requires OpenLayers/Tile/Image.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Polygon │ │ │ │ │ - * Handler to draw a polygon on the map. Polygon is displayed on mouse down, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. │ │ │ │ │ + * Class: OpenLayers.Layer.Grid │ │ │ │ │ + * Base class for layers that use a lattice of tiles. Create a new grid │ │ │ │ │ + * layer with the constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { │ │ │ │ │ +OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: holeModifier │ │ │ │ │ - * {String} Key modifier to trigger hole digitizing. Acceptable values are │ │ │ │ │ - * "altKey", "shiftKey", or "ctrlKey". If not set, no hole digitizing │ │ │ │ │ - * will take place. Default is null. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tileSize │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - holeModifier: null, │ │ │ │ │ + tileSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: drawingHole │ │ │ │ │ - * {Boolean} Currently drawing an interior ring. │ │ │ │ │ + * Property: tileOriginCorner │ │ │ │ │ + * {String} If the property is not provided, the tile origin │ │ │ │ │ + * will be derived from the layer's . The corner of the │ │ │ │ │ + * used is determined by this property. Acceptable values │ │ │ │ │ + * are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br" │ │ │ │ │ + * (bottom right). Default is "bl". │ │ │ │ │ */ │ │ │ │ │ - drawingHole: false, │ │ │ │ │ + tileOriginCorner: "bl", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: polygon │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: tileOrigin │ │ │ │ │ + * {} Optional origin for aligning the grid of tiles. │ │ │ │ │ + * If provided, requests for tiles at all resolutions will be aligned │ │ │ │ │ + * with this location (no tiles shall overlap this location). If │ │ │ │ │ + * not provided, the grid of tiles will be aligned with the layer's │ │ │ │ │ + * . Default is ``null``. │ │ │ │ │ */ │ │ │ │ │ - polygon: null, │ │ │ │ │ + tileOrigin: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Polygon │ │ │ │ │ - * Create a Polygon Handler. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the polygon geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + /** APIProperty: tileOptions │ │ │ │ │ + * {Object} optional configuration options for instances │ │ │ │ │ + * created by this Layer, if supported by the tile class. │ │ │ │ │ */ │ │ │ │ │ + tileOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The initial pixel location for the new │ │ │ │ │ - * feature. │ │ │ │ │ + * APIProperty: tileClass │ │ │ │ │ + * {} The tile class to use for this layer. │ │ │ │ │ + * Defaults is OpenLayers.Tile.Image. │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LinearRing([this.point.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.polygon = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Polygon([this.line.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.polygon, this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + tileClass: OpenLayers.Tile.Image, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addPoint │ │ │ │ │ - * Add point to geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The pixel location for the new point. │ │ │ │ │ + * Property: grid │ │ │ │ │ + * {Array(Array())} This is an array of rows, each row is │ │ │ │ │ + * an array of tiles. │ │ │ │ │ */ │ │ │ │ │ - addPoint: function(pixel) { │ │ │ │ │ - if (!this.drawingHole && this.holeModifier && │ │ │ │ │ - this.evt && this.evt[this.holeModifier]) { │ │ │ │ │ - var geometry = this.point.geometry; │ │ │ │ │ - var features = this.control.layer.features; │ │ │ │ │ - var candidate, polygon; │ │ │ │ │ - // look for intersections, last drawn gets priority │ │ │ │ │ - for (var i = features.length - 1; i >= 0; --i) { │ │ │ │ │ - candidate = features[i].geometry; │ │ │ │ │ - if ((candidate instanceof OpenLayers.Geometry.Polygon || │ │ │ │ │ - candidate instanceof OpenLayers.Geometry.MultiPolygon) && │ │ │ │ │ - candidate.intersects(geometry)) { │ │ │ │ │ - polygon = features[i]; │ │ │ │ │ - this.control.layer.removeFeatures([polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.control.layer.events.registerPriority( │ │ │ │ │ - "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ - ); │ │ │ │ │ - this.control.layer.events.registerPriority( │ │ │ │ │ - "sketchmodified", this, this.enforceTopology │ │ │ │ │ - ); │ │ │ │ │ - polygon.geometry.addComponent(this.line.geometry); │ │ │ │ │ - this.polygon = polygon; │ │ │ │ │ - this.drawingHole = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + grid: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentPointIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The index of the most recently drawn point. │ │ │ │ │ + * APIProperty: singleTile │ │ │ │ │ + * {Boolean} Moves the layer into single-tile mode, meaning that one tile │ │ │ │ │ + * will be loaded. The tile's size will be determined by the 'ratio' │ │ │ │ │ + * property. When the tile is dragged such that it does not cover the │ │ │ │ │ + * entire viewport, it is reloaded. │ │ │ │ │ */ │ │ │ │ │ - getCurrentPointIndex: function() { │ │ │ │ │ - return this.line.geometry.components.length - 2; │ │ │ │ │ - }, │ │ │ │ │ + singleTile: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: enforceTopology │ │ │ │ │ - * Simple topology enforcement for drawing interior rings. Ensures vertices │ │ │ │ │ - * of interior rings are contained by exterior ring. Other topology │ │ │ │ │ - * rules are enforced in to allow drawing of │ │ │ │ │ - * rings that intersect only during the sketch (e.g. a "C" shaped ring │ │ │ │ │ - * that nearly encloses another ring). │ │ │ │ │ + /** APIProperty: ratio │ │ │ │ │ + * {Float} Used only when in single-tile mode, this specifies the │ │ │ │ │ + * ratio of the size of the single tile to the size of the map. │ │ │ │ │ + * Default value is 1.5. │ │ │ │ │ */ │ │ │ │ │ - enforceTopology: function(event) { │ │ │ │ │ - var point = event.vertex; │ │ │ │ │ - var components = this.line.geometry.components; │ │ │ │ │ - // ensure that vertices of interior ring are contained by exterior ring │ │ │ │ │ - if (!this.polygon.geometry.intersects(point)) { │ │ │ │ │ - var last = components[components.length - 3]; │ │ │ │ │ - point.x = last.x; │ │ │ │ │ - point.y = last.y; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + ratio: 1.5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finishGeometry │ │ │ │ │ - * Finish the geometry and send it back to the control. │ │ │ │ │ + * APIProperty: buffer │ │ │ │ │ + * {Integer} Used only when in gridded mode, this specifies the number of │ │ │ │ │ + * extra rows and colums of tiles on each side which will │ │ │ │ │ + * surround the minimum grid tiles to cover the map. │ │ │ │ │ + * For very slow loading layers, a larger value may increase │ │ │ │ │ + * performance somewhat when dragging, but will increase bandwidth │ │ │ │ │ + * use significantly. │ │ │ │ │ */ │ │ │ │ │ - finishGeometry: function() { │ │ │ │ │ - var index = this.line.geometry.components.length - 2; │ │ │ │ │ - this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - }, │ │ │ │ │ + buffer: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finalizeInteriorRing │ │ │ │ │ - * Enforces that new ring has some area and doesn't contain vertices of any │ │ │ │ │ - * other rings. │ │ │ │ │ + * APIProperty: transitionEffect │ │ │ │ │ + * {String} The transition effect to use when the map is zoomed. │ │ │ │ │ + * Two posible values: │ │ │ │ │ + * │ │ │ │ │ + * "resize" - Existing tiles are resized on zoom to provide a visual │ │ │ │ │ + * effect of the zoom having taken place immediately. As the │ │ │ │ │ + * new tiles become available, they are drawn on top of the │ │ │ │ │ + * resized tiles (this is the default setting). │ │ │ │ │ + * "map-resize" - Existing tiles are resized on zoom and placed below the │ │ │ │ │ + * base layer. New tiles for the base layer will cover existing tiles. │ │ │ │ │ + * This setting is recommended when having an overlay duplicated during │ │ │ │ │ + * the transition is undesirable (e.g. street labels or big transparent │ │ │ │ │ + * fills). │ │ │ │ │ + * null - No transition effect. │ │ │ │ │ + * │ │ │ │ │ + * Using "resize" on non-opaque layers can cause undesired visual │ │ │ │ │ + * effects. Set transitionEffect to null in this case. │ │ │ │ │ */ │ │ │ │ │ - finalizeInteriorRing: function() { │ │ │ │ │ - var ring = this.line.geometry; │ │ │ │ │ - // ensure that ring has some area │ │ │ │ │ - var modified = (ring.getArea() !== 0); │ │ │ │ │ - if (modified) { │ │ │ │ │ - // ensure that new ring doesn't intersect any other rings │ │ │ │ │ - var rings = this.polygon.geometry.components; │ │ │ │ │ - for (var i = rings.length - 2; i >= 0; --i) { │ │ │ │ │ - if (ring.intersects(rings[i])) { │ │ │ │ │ - modified = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (modified) { │ │ │ │ │ - // ensure that new ring doesn't contain any other rings │ │ │ │ │ - var target; │ │ │ │ │ - outer: for (var i = rings.length - 2; i > 0; --i) { │ │ │ │ │ - var points = rings[i].components; │ │ │ │ │ - for (var j = 0, jj = points.length; j < jj; ++j) { │ │ │ │ │ - if (ring.containsPoint(points[j])) { │ │ │ │ │ - modified = false; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (modified) { │ │ │ │ │ - if (this.polygon.state !== OpenLayers.State.INSERT) { │ │ │ │ │ - this.polygon.state = OpenLayers.State.UPDATE; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.polygon.geometry.removeComponent(ring); │ │ │ │ │ - } │ │ │ │ │ - this.restoreFeature(); │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + transitionEffect: "resize", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * APIProperty: numLoadingTiles │ │ │ │ │ + * {Integer} How many tiles are still loading? │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - if (this.drawingHole) { │ │ │ │ │ - this.polygon.geometry.removeComponent(this.line.geometry); │ │ │ │ │ - this.restoreFeature(true); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + numLoadingTiles: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: restoreFeature │ │ │ │ │ - * Move the feature from the sketch layer to the target layer. │ │ │ │ │ - * │ │ │ │ │ - * Properties: │ │ │ │ │ - * cancel - {Boolean} Cancel drawing. If falsey, the "sketchcomplete" event │ │ │ │ │ - * will be fired. │ │ │ │ │ + * Property: serverResolutions │ │ │ │ │ + * {Array(Number}} This property is documented in subclasses as │ │ │ │ │ + * an API property. │ │ │ │ │ */ │ │ │ │ │ - restoreFeature: function(cancel) { │ │ │ │ │ - this.control.layer.events.unregister( │ │ │ │ │ - "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ - ); │ │ │ │ │ - this.control.layer.events.unregister( │ │ │ │ │ - "sketchmodified", this, this.enforceTopology │ │ │ │ │ - ); │ │ │ │ │ - this.layer.removeFeatures([this.polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.control.layer.addFeatures([this.polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.drawingHole = false; │ │ │ │ │ - if (!cancel) { │ │ │ │ │ - // Re-trigger "sketchcomplete" so other listeners can do their │ │ │ │ │ - // business. While this is somewhat sloppy (if a listener is │ │ │ │ │ - // registered with registerPriority - not common - between the start │ │ │ │ │ - // and end of a single ring drawing - very uncommon - it will be │ │ │ │ │ - // called twice). │ │ │ │ │ - // TODO: In 3.0, collapse sketch handlers into geometry specific │ │ │ │ │ - // drawing controls. │ │ │ │ │ - this.control.layer.events.triggerEvent( │ │ │ │ │ - "sketchcomplete", { │ │ │ │ │ - feature: this.polygon │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + serverResolutions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * Property: loading │ │ │ │ │ + * {Boolean} Indicates if tiles are being loaded. │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - OpenLayers.Handler.Path.prototype.destroyFeature.call( │ │ │ │ │ - this, force); │ │ │ │ │ - this.polygon = null; │ │ │ │ │ - }, │ │ │ │ │ + loading: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render geometries on the temporary layer. │ │ │ │ │ + * Property: backBuffer │ │ │ │ │ + * {DOMElement} The back buffer. │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.polygon, this.style); │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ - }, │ │ │ │ │ + backBuffer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSketch │ │ │ │ │ - * Return the sketch feature. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: gridResolution │ │ │ │ │ + * {Number} The resolution of the current grid. Used for backbuffer and │ │ │ │ │ + * client zoom. This property is updated every time the grid is │ │ │ │ │ + * initialized. │ │ │ │ │ */ │ │ │ │ │ - getSketch: function() { │ │ │ │ │ - return this.polygon; │ │ │ │ │ - }, │ │ │ │ │ + gridResolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: backBufferResolution │ │ │ │ │ + * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ + * updated each time a back buffer is created. │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.polygon && this.polygon.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiPolygon([geometry]); │ │ │ │ │ - } │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Polygon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Hover.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + backBufferResolution: null, │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: backBufferLonLat │ │ │ │ │ + * {Object} The top-left corner of the current back buffer. Includes lon │ │ │ │ │ + * and lat properties. This object is updated each time a back buffer │ │ │ │ │ + * is created. │ │ │ │ │ + */ │ │ │ │ │ + backBufferLonLat: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: backBufferTimerId │ │ │ │ │ + * {Number} The id of the back buffer timer. This timer is used to │ │ │ │ │ + * delay the removal of the back buffer, thereby preventing │ │ │ │ │ + * flash effects caused by tile animation. │ │ │ │ │ + */ │ │ │ │ │ + backBufferTimerId: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Hover │ │ │ │ │ - * The hover handler is to be used to emulate mouseovers on objects │ │ │ │ │ - * on the map that aren't DOM elements. For example one can use │ │ │ │ │ - * this handler to send WMS/GetFeatureInfo requests as the user │ │ │ │ │ - * moves the mouve over the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: removeBackBufferDelay │ │ │ │ │ + * {Number} Delay for removing the backbuffer when all tiles have finished │ │ │ │ │ + * loading. Can be set to 0 when no css opacity transitions for the │ │ │ │ │ + * olTileImage class are used. Default is 0 for layers, │ │ │ │ │ + * 2500 for tiled layers. See for more information on │ │ │ │ │ + * tile animation. │ │ │ │ │ + */ │ │ │ │ │ + removeBackBufferDelay: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: delay │ │ │ │ │ - * {Integer} - Number of milliseconds between mousemoves before │ │ │ │ │ - * the event is considered a hover. Default is 500. │ │ │ │ │ + * APIProperty: className │ │ │ │ │ + * {String} Name of the class added to the layer div. If not set in the │ │ │ │ │ + * options passed to the constructor then className defaults to │ │ │ │ │ + * "olLayerGridSingleTile" for single tile layers (see ), │ │ │ │ │ + * and "olLayerGrid" for non single tile layers. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * │ │ │ │ │ + * The displaying of tiles is not animated by default for single tile │ │ │ │ │ + * layers - OpenLayers' default theme (style.css) includes this: │ │ │ │ │ + * (code) │ │ │ │ │ + * .olLayerGrid .olTileImage { │ │ │ │ │ + * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ + * -moz-transition: opacity 0.2s linear; │ │ │ │ │ + * -o-transition: opacity 0.2s linear; │ │ │ │ │ + * transition: opacity 0.2s linear; │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * To animate tile displaying for any grid layer the following │ │ │ │ │ + * CSS rule can be used: │ │ │ │ │ + * (code) │ │ │ │ │ + * .olTileImage { │ │ │ │ │ + * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ + * -moz-transition: opacity 0.2s linear; │ │ │ │ │ + * -o-transition: opacity 0.2s linear; │ │ │ │ │ + * transition: opacity 0.2s linear; │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * In that case, to avoid flash effects, │ │ │ │ │ + * should not be zero. │ │ │ │ │ */ │ │ │ │ │ - delay: 500, │ │ │ │ │ + className: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ - * an event to be considered a hover. Default is null. │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to layer.events.object. │ │ │ │ │ + * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * addtile - Triggered when a tile is added to this layer. Listeners receive │ │ │ │ │ + * an object as first argument, which has a tile property that │ │ │ │ │ + * references the tile that has been added. │ │ │ │ │ + * tileloadstart - Triggered when a tile starts loading. Listeners receive │ │ │ │ │ + * an object as first argument, which has a tile property that │ │ │ │ │ + * references the tile that starts loading. │ │ │ │ │ + * tileloaded - Triggered when each new tile is │ │ │ │ │ + * loaded, as a means of progress update to listeners. │ │ │ │ │ + * listeners can access 'numLoadingTiles' if they wish to keep │ │ │ │ │ + * track of the loading progress. Listeners are called with an object │ │ │ │ │ + * with a 'tile' property as first argument, making the loaded tile │ │ │ │ │ + * available to the listener, and an 'aborted' property, which will be │ │ │ │ │ + * true when loading was aborted and no tile data is available. │ │ │ │ │ + * tileerror - Triggered before the tileloaded event (i.e. when the tile is │ │ │ │ │ + * still hidden) if a tile failed to load. Listeners receive an object │ │ │ │ │ + * as first argument, which has a tile property that references the │ │ │ │ │ + * tile that could not be loaded. │ │ │ │ │ + * retile - Triggered when the layer recreates its tile grid. │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopMove │ │ │ │ │ - * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: gridLayout │ │ │ │ │ + * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ + * startrow │ │ │ │ │ */ │ │ │ │ │ - stopMove: false, │ │ │ │ │ + gridLayout: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {} - The location of the last mousemove, expressed │ │ │ │ │ - * in pixels. │ │ │ │ │ + * Property: rowSign │ │ │ │ │ + * {Number} 1 for grids starting at the top, -1 for grids starting at the │ │ │ │ │ + * bottom. This is used for several grid index and offset calculations. │ │ │ │ │ */ │ │ │ │ │ - px: null, │ │ │ │ │ + rowSign: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} - The id of the timer. │ │ │ │ │ + * Property: transitionendEvents │ │ │ │ │ + * {Array} Event names for transitionend │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + transitionendEvents: [ │ │ │ │ │ + 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ + 'oTransitionEnd' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ - * Construct a hover handler. │ │ │ │ │ + * Constructor: OpenLayers.Layer.Grid │ │ │ │ │ + * Create a new grid layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} The control that initialized this │ │ │ │ │ - * handler. The control is assumed to have a valid map property; that │ │ │ │ │ - * map is used in the handler's own setMap method. │ │ │ │ │ - * callbacks - {Object} An object with keys corresponding to callbacks │ │ │ │ │ - * that will be called by the handler. The callbacks should │ │ │ │ │ - * expect to receive a single argument, the event. Callbacks for │ │ │ │ │ - * 'move', the mouse is moving, and 'pause', the mouse is pausing, │ │ │ │ │ - * are supported. │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the handler. │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + this.grid = []; │ │ │ │ │ + this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); │ │ │ │ │ + │ │ │ │ │ + this.initProperties(); │ │ │ │ │ + │ │ │ │ │ + this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Called when the mouse moves on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Method: initProperties │ │ │ │ │ + * Set any properties that depend on the value of singleTile. │ │ │ │ │ + * Currently sets removeBackBufferDelay and className │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - if (this.passesTolerance(evt.xy)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('move', [evt]); │ │ │ │ │ - this.px = evt.xy; │ │ │ │ │ - // clone the evt so original properties can be accessed even │ │ │ │ │ - // if the browser deletes them during the delay │ │ │ │ │ - evt = OpenLayers.Util.extend({}, evt); │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ - this.delay │ │ │ │ │ - ); │ │ │ │ │ + initProperties: function() { │ │ │ │ │ + if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ + this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.options.className === undefined) { │ │ │ │ │ + this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ + 'olLayerGrid'; │ │ │ │ │ } │ │ │ │ │ - return !this.stopMove; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Called when the mouse goes out of the map. │ │ │ │ │ + * Method: setMap │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * map - {} The map. │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('move', [evt]); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Called when the layer is removed from the map. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ + * map - {} The map. │ │ │ │ │ + */ │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Deconstruct the layer and clear the grid. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + │ │ │ │ │ + this.grid = null; │ │ │ │ │ + this.tileSize = null; │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ + * Refetches tiles with new params merged, keeping a backbuffer. Each │ │ │ │ │ + * loading new tile will have a css class of '.olTileReplacing'. If a │ │ │ │ │ + * stylesheet applies a 'display: none' style to that class, any fade-in │ │ │ │ │ + * transition will not apply, and backbuffers for each tile will be removed │ │ │ │ │ + * as soon as the tile is loaded. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - passesTolerance: function(px) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.pixelTolerance && this.px) { │ │ │ │ │ - var dpx = Math.sqrt( │ │ │ │ │ - Math.pow(this.px.x - px.x, 2) + │ │ │ │ │ - Math.pow(this.px.y - px.y, 2) │ │ │ │ │ - ); │ │ │ │ │ - if (dpx < this.pixelTolerance) { │ │ │ │ │ - passes = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return passes; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: clearGrid │ │ │ │ │ + * Go through and remove all tiles from the grid, calling │ │ │ │ │ + * destroy() on each of them to kill circular references │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ + clearGrid: function() { │ │ │ │ │ + if (this.grid) { │ │ │ │ │ + for (var iRow = 0, len = this.grid.length; iRow < len; iRow++) { │ │ │ │ │ + var row = this.grid[iRow]; │ │ │ │ │ + for (var iCol = 0, clen = row.length; iCol < clen; iCol++) { │ │ │ │ │ + var tile = row[iCol]; │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.grid = []; │ │ │ │ │ + this.gridResolution = null; │ │ │ │ │ + this.gridLayout = null; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Triggers pause callback. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * newOptions - {Object} │ │ │ │ │ + * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ + * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ + * sure that it is displayed with a valid resolution, and a │ │ │ │ │ + * changebaselayer event will be triggered. │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.callback('pause', [evt]); │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ + var singleTileChanged = newOptions.singleTile !== undefined && │ │ │ │ │ + newOptions.singleTile !== this.singleTile; │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); │ │ │ │ │ + if (this.map && singleTileChanged) { │ │ │ │ │ + this.initProperties(); │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + this.tileSize = this.options.tileSize; │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ + this.moveTo(null, true); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a clone of this layer │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} Is this ever used? │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Hover" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/RegularPolygon.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); │ │ │ │ │ │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + if (this.tileSize != null) { │ │ │ │ │ + obj.tileSize = this.tileSize.clone(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - */ │ │ │ │ │ + // we do not want to copy reference to grid, so we make a new array │ │ │ │ │ + obj.grid = []; │ │ │ │ │ + obj.gridResolution = null; │ │ │ │ │ + // same for backbuffer │ │ │ │ │ + obj.backBuffer = null; │ │ │ │ │ + obj.backBufferTimerId = null; │ │ │ │ │ + obj.loading = false; │ │ │ │ │ + obj.numLoadingTiles = 0; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.RegularPolygon │ │ │ │ │ - * Handler to draw a regular polygon on the map. Polygon is displayed on mouse │ │ │ │ │ - * down, moves or is modified on mouse move, and is finished on mouse up. │ │ │ │ │ - * The handler triggers callbacks for 'done' and 'cancel'. Create a new │ │ │ │ │ - * instance with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, { │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: sides │ │ │ │ │ - * {Integer} Number of sides for the regular polygon. Needs to be greater │ │ │ │ │ - * than 2. Defaults to 4. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * This function is called whenever the map is moved. All the moving │ │ │ │ │ + * of actual 'tiles' is done by the map, but moveTo's role is to accept │ │ │ │ │ + * a bounds and make sure the data that that bounds requires is pre-loaded. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - sides: 4, │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: radius │ │ │ │ │ - * {Float} Optional radius in map units of the regular polygon. If this is │ │ │ │ │ - * set to some non-zero value, a polygon with a fixed radius will be │ │ │ │ │ - * drawn and dragged with mose movements. If this property is not │ │ │ │ │ - * set, dragging changes the radius of the polygon. Set to null by │ │ │ │ │ - * default. │ │ │ │ │ - */ │ │ │ │ │ - radius: null, │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: snapAngle │ │ │ │ │ - * {Float} If set to a non-zero value, the handler will snap the polygon │ │ │ │ │ - * rotation to multiples of the snapAngle. Value is an angle measured │ │ │ │ │ - * in degrees counterclockwise from the positive x-axis. │ │ │ │ │ - */ │ │ │ │ │ - snapAngle: null, │ │ │ │ │ + bounds = bounds || this.map.getExtent(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: snapToggle │ │ │ │ │ - * {String} If set, snapToggle is checked on mouse events and will set │ │ │ │ │ - * the snap mode to the opposite of what it currently is. To disallow │ │ │ │ │ - * toggling between snap and non-snap mode, set freehandToggle to │ │ │ │ │ - * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and │ │ │ │ │ - * 'altKey'. Snap mode is only possible if this.snapAngle is set to a │ │ │ │ │ - * non-zero value. │ │ │ │ │ - */ │ │ │ │ │ - snapToggle: 'shiftKey', │ │ │ │ │ + if (bounds != null) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerOptions │ │ │ │ │ - * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ - */ │ │ │ │ │ - layerOptions: null, │ │ │ │ │ + // if grid is empty or zoom has changed, we *must* re-tile │ │ │ │ │ + var forceReTile = !this.grid.length || zoomChanged; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Leave the feature rendered until clear is called. Default │ │ │ │ │ - * is false. If set to true, the feature remains rendered until │ │ │ │ │ - * clear is called, typically by deactivating the handler or starting │ │ │ │ │ - * another drawing. │ │ │ │ │ - */ │ │ │ │ │ - persist: false, │ │ │ │ │ + // total bounds of the tiles │ │ │ │ │ + var tilesBounds = this.getTilesBounds(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: irregular │ │ │ │ │ - * {Boolean} Draw an irregular polygon instead of a regular polygon. │ │ │ │ │ - * Default is false. If true, the initial mouse down will represent │ │ │ │ │ - * one corner of the polygon bounds and with each mouse movement, the │ │ │ │ │ - * polygon will be stretched so the opposite corner of its bounds │ │ │ │ │ - * follows the mouse position. This property takes precedence over │ │ │ │ │ - * the radius property. If set to true, the radius property will │ │ │ │ │ - * be ignored. │ │ │ │ │ - */ │ │ │ │ │ - irregular: false, │ │ │ │ │ + // the new map resolution │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: citeCompliant │ │ │ │ │ - * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ - * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - citeCompliant: false, │ │ │ │ │ + // the server-supported resolution for the new map resolution │ │ │ │ │ + var serverResolution = this.getServerResolution(resolution); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: angle │ │ │ │ │ - * {Float} The angle from the origin (mouse down) to the current mouse │ │ │ │ │ - * position, in radians. This is measured counterclockwise from the │ │ │ │ │ - * positive x-axis. │ │ │ │ │ - */ │ │ │ │ │ - angle: null, │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: fixedRadius │ │ │ │ │ - * {Boolean} The polygon has a fixed radius. True if a radius is set before │ │ │ │ │ - * drawing begins. False otherwise. │ │ │ │ │ - */ │ │ │ │ │ - fixedRadius: false, │ │ │ │ │ + // We want to redraw whenever even the slightest part of the │ │ │ │ │ + // current bounds is not contained by our tile. │ │ │ │ │ + // (thus, we do not specify partial -- its default is false) │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The currently drawn polygon feature │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ + if (forceReTile || │ │ │ │ │ + (!dragging && !tilesBounds.containsBounds(bounds))) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The temporary drawing layer │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ + // In single tile mode with no transition effect, we insert │ │ │ │ │ + // a non-scaled backbuffer when the layer is moved. But if │ │ │ │ │ + // a zoom occurs right after a move, i.e. before the new │ │ │ │ │ + // image is received, we need to remove the backbuffer, or │ │ │ │ │ + // an ill-positioned image will be visible during the zoom │ │ │ │ │ + // transition. │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: origin │ │ │ │ │ - * {} Location of the first mouse down │ │ │ │ │ - */ │ │ │ │ │ - origin: null, │ │ │ │ │ + if (zoomChanged && this.transitionEffect !== 'resize') { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.RegularPolygon │ │ │ │ │ - * Create a new regular polygon handler. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An object with properties to be set on the handler. │ │ │ │ │ - * If the options.sides property is not specified, the number of sides │ │ │ │ │ - * will default to 4. │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * done - Called when the sketch drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the sketch geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - if (!(options && options.layerOptions && options.layerOptions.styleMap)) { │ │ │ │ │ - this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); │ │ │ │ │ - } │ │ │ │ │ + if (!zoomChanged || this.transitionEffect === 'resize') { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - OpenLayers.Handler.Drag.prototype.initialize.apply(this, │ │ │ │ │ - [control, callbacks, options]); │ │ │ │ │ - this.options = (options) ? options : {}; │ │ │ │ │ - }, │ │ │ │ │ + this.initSingleTile(bounds); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setOptions │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newOptions - {Object} │ │ │ │ │ - */ │ │ │ │ │ - setOptions: function(newOptions) { │ │ │ │ │ - OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ - OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ - }, │ │ │ │ │ + // if the bounds have changed such that they are not even │ │ │ │ │ + // *partially* contained by our tiles (e.g. when user has │ │ │ │ │ + // programmatically panned to the other side of the earth on │ │ │ │ │ + // zoom level 18), then moveGriddedTiles could potentially have │ │ │ │ │ + // to run through thousands of cycles, so we want to reTile │ │ │ │ │ + // instead (thus, partial true). │ │ │ │ │ + forceReTile = forceReTile || │ │ │ │ │ + !tilesBounds.intersectsBounds(bounds, { │ │ │ │ │ + worldBounds: this.map.baseLayer.wrapDateLine && │ │ │ │ │ + this.map.getMaxExtent() │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Turn on the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.Drag.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - // create temporary vector layer for rendering geometry sketch │ │ │ │ │ - var options = OpenLayers.Util.extend({ │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - // indicate that the temp vector layer will never be out of range │ │ │ │ │ - // without this, resolution properties must be specified at the │ │ │ │ │ - // map-level for this temporary layer to init its resolutions │ │ │ │ │ - // correctly │ │ │ │ │ - calculateInRange: OpenLayers.Function.True, │ │ │ │ │ - wrapDateLine: this.citeCompliant │ │ │ │ │ - }, this.layerOptions); │ │ │ │ │ - this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ - this.map.addLayer(this.layer); │ │ │ │ │ - activated = true; │ │ │ │ │ + if (forceReTile) { │ │ │ │ │ + if (zoomChanged && (this.transitionEffect === 'resize' || │ │ │ │ │ + this.gridResolution === resolution)) { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ + } │ │ │ │ │ + this.initGriddedTiles(bounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Turn off the handler. │ │ │ │ │ + * Method: getTileData │ │ │ │ │ + * Given a map location, retrieve a tile and the pixel offset within that │ │ │ │ │ + * tile corresponding to the location. If there is not an existing │ │ │ │ │ + * tile in the grid that covers the given location, null will be │ │ │ │ │ + * returned. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * loc - {} map location │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated │ │ │ │ │ + * {Object} Object with the following properties: tile ({}), │ │ │ │ │ + * i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel │ │ │ │ │ + * offset from top left). │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - // call the cancel callback if mid-drawing │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.cancel(); │ │ │ │ │ + getTileData: function(loc) { │ │ │ │ │ + var data = null, │ │ │ │ │ + x = loc.lon, │ │ │ │ │ + y = loc.lat, │ │ │ │ │ + numRows = this.grid.length; │ │ │ │ │ + │ │ │ │ │ + if (this.map && numRows) { │ │ │ │ │ + var res = this.map.getResolution(), │ │ │ │ │ + tileWidth = this.tileSize.w, │ │ │ │ │ + tileHeight = this.tileSize.h, │ │ │ │ │ + bounds = this.grid[0][0].bounds, │ │ │ │ │ + left = bounds.left, │ │ │ │ │ + top = bounds.top; │ │ │ │ │ + │ │ │ │ │ + if (x < left) { │ │ │ │ │ + // deal with multiple worlds │ │ │ │ │ + if (this.map.baseLayer.wrapDateLine) { │ │ │ │ │ + var worldWidth = this.map.getMaxExtent().getWidth(); │ │ │ │ │ + var worldsAway = Math.ceil((left - x) / worldWidth); │ │ │ │ │ + x += worldWidth * worldsAway; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - // If a layer's map property is set to null, it means that that │ │ │ │ │ - // layer isn't added to the map. Since we ourself added the layer │ │ │ │ │ - // to the map in activate(), we can assume that if this.layer.map │ │ │ │ │ - // is null it means that the layer has been destroyed (as a result │ │ │ │ │ - // of map.destroy() for example. │ │ │ │ │ - if (this.layer.map != null) { │ │ │ │ │ - this.layer.destroy(false); │ │ │ │ │ - if (this.feature) { │ │ │ │ │ - this.feature.destroy(); │ │ │ │ │ + // tile distance to location (fractional number of tiles); │ │ │ │ │ + var dtx = (x - left) / (res * tileWidth); │ │ │ │ │ + var dty = (top - y) / (res * tileHeight); │ │ │ │ │ + // index of tile in grid │ │ │ │ │ + var col = Math.floor(dtx); │ │ │ │ │ + var row = Math.floor(dty); │ │ │ │ │ + if (row >= 0 && row < numRows) { │ │ │ │ │ + var tile = this.grid[row][col]; │ │ │ │ │ + if (tile) { │ │ │ │ │ + data = { │ │ │ │ │ + tile: tile, │ │ │ │ │ + // pixel index within tile │ │ │ │ │ + i: Math.floor((dtx - col) * tileWidth), │ │ │ │ │ + j: Math.floor((dty - row) * tileHeight) │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.feature = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + return data; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Start drawing a new feature │ │ │ │ │ + * Method: destroyTile │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The drag start event │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - this.fixedRadius = !!(this.radius); │ │ │ │ │ - var maploc = this.layer.getLonLatFromViewPortPx(evt.xy); │ │ │ │ │ - this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); │ │ │ │ │ - // create the new polygon │ │ │ │ │ - if (!this.fixedRadius || this.irregular) { │ │ │ │ │ - // smallest radius should not be less one pixel in map units │ │ │ │ │ - // VML doesn't behave well with smaller │ │ │ │ │ - this.radius = this.map.getResolution(); │ │ │ │ │ - } │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.clear(); │ │ │ │ │ - } │ │ │ │ │ - this.feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - this.createGeometry(); │ │ │ │ │ - this.callback("create", [this.origin, this.feature]); │ │ │ │ │ - this.layer.addFeatures([this.feature], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ + destroyTile: function(tile) { │ │ │ │ │ + this.removeTileMonitoringHooks(tile); │ │ │ │ │ + tile.destroy(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Respond to drag move events │ │ │ │ │ + * Method: getServerResolution │ │ │ │ │ + * Return the closest server-supported resolution. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Evt} The move event │ │ │ │ │ + * resolution - {Number} The base resolution. If undefined the │ │ │ │ │ + * map resolution is used. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The closest server resolution value. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - var maploc = this.layer.getLonLatFromViewPortPx(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; │ │ │ │ │ + getServerResolution: function(resolution) { │ │ │ │ │ + var distance = Number.POSITIVE_INFINITY; │ │ │ │ │ + resolution = resolution || this.map.getResolution(); │ │ │ │ │ + if (this.serverResolutions && │ │ │ │ │ + OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) { │ │ │ │ │ + var i, newDistance, newResolution, serverResolution; │ │ │ │ │ + for (i = this.serverResolutions.length - 1; i >= 0; i--) { │ │ │ │ │ + newResolution = this.serverResolutions[i]; │ │ │ │ │ + newDistance = Math.abs(newResolution - resolution); │ │ │ │ │ + if (newDistance > distance) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + distance = newDistance; │ │ │ │ │ + serverResolution = newResolution; │ │ │ │ │ } │ │ │ │ │ - this.feature.geometry.resize(1, this.origin, ratio); │ │ │ │ │ - this.feature.geometry.move(dx / 2, dy / 2); │ │ │ │ │ + resolution = serverResolution; │ │ │ │ │ } │ │ │ │ │ - this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Finish drawing the feature │ │ │ │ │ + * Method: getServerZoom │ │ │ │ │ + * Return the zoom value corresponding to the best matching server │ │ │ │ │ + * resolution, taking into account and . │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse up event │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The closest server supported zoom. This is not the map zoom │ │ │ │ │ + * level, but an index of the server's resolutions array. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - this.finalize(); │ │ │ │ │ - // the mouseup method of superclass doesn't call the │ │ │ │ │ - // "done" callback if there's been no move between │ │ │ │ │ - // down and up │ │ │ │ │ - if (this.start == this.last) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ - } │ │ │ │ │ + getServerZoom: function() { │ │ │ │ │ + var resolution = this.getServerResolution(); │ │ │ │ │ + return this.serverResolutions ? │ │ │ │ │ + OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ + this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: out │ │ │ │ │ - * Finish drawing the feature. │ │ │ │ │ + * Method: applyBackBuffer │ │ │ │ │ + * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse out event │ │ │ │ │ - */ │ │ │ │ │ - out: function(evt) { │ │ │ │ │ - this.finalize(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createGeometry │ │ │ │ │ - * Create the new polygon geometry. This is called at the start of the │ │ │ │ │ - * drag and at any point during the drag if the number of sides │ │ │ │ │ - * changes. │ │ │ │ │ + * resolution - {Number} The resolution to transition to. │ │ │ │ │ */ │ │ │ │ │ - createGeometry: function() { │ │ │ │ │ - this.angle = Math.PI * ((1 / this.sides) - (1 / 2)); │ │ │ │ │ - if (this.snapAngle) { │ │ │ │ │ - this.angle += this.snapAngle * (Math.PI / 180); │ │ │ │ │ + applyBackBuffer: function(resolution) { │ │ │ │ │ + if (this.backBufferTimerId !== null) { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ } │ │ │ │ │ - this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon( │ │ │ │ │ - this.origin, this.radius, this.sides, this.snapAngle │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + var backBuffer = this.backBuffer; │ │ │ │ │ + if (!backBuffer) { │ │ │ │ │ + backBuffer = this.createBackBuffer(); │ │ │ │ │ + if (!backBuffer) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (resolution === this.gridResolution) { │ │ │ │ │ + this.div.insertBefore(backBuffer, this.div.firstChild); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.baseLayer.div.parentNode.insertBefore(backBuffer, this.map.baseLayer.div); │ │ │ │ │ + } │ │ │ │ │ + this.backBuffer = backBuffer; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: modifyGeometry │ │ │ │ │ - * Modify the polygon geometry in place. │ │ │ │ │ - */ │ │ │ │ │ - modifyGeometry: function() { │ │ │ │ │ - var angle, point; │ │ │ │ │ - var ring = this.feature.geometry.components[0]; │ │ │ │ │ - // if the number of sides ever changes, create a new geometry │ │ │ │ │ - if (ring.components.length != (this.sides + 1)) { │ │ │ │ │ - this.createGeometry(); │ │ │ │ │ - ring = this.feature.geometry.components[0]; │ │ │ │ │ + // set some information in the instance for subsequent │ │ │ │ │ + // calls to applyBackBuffer where the same back buffer │ │ │ │ │ + // is reused │ │ │ │ │ + var topLeftTileBounds = this.grid[0][0].bounds; │ │ │ │ │ + this.backBufferLonLat = { │ │ │ │ │ + lon: topLeftTileBounds.left, │ │ │ │ │ + lat: topLeftTileBounds.top │ │ │ │ │ + }; │ │ │ │ │ + this.backBufferResolution = this.gridResolution; │ │ │ │ │ } │ │ │ │ │ - for (var i = 0; i < this.sides; ++i) { │ │ │ │ │ - point = ring.components[i]; │ │ │ │ │ - angle = this.angle + (i * 2 * Math.PI / this.sides); │ │ │ │ │ - point.x = this.origin.x + (this.radius * Math.cos(angle)); │ │ │ │ │ - point.y = this.origin.y + (this.radius * Math.sin(angle)); │ │ │ │ │ - point.clearBounds(); │ │ │ │ │ + │ │ │ │ │ + var ratio = this.backBufferResolution / resolution; │ │ │ │ │ + │ │ │ │ │ + // scale the tiles inside the back buffer │ │ │ │ │ + var tiles = backBuffer.childNodes, │ │ │ │ │ + tile; │ │ │ │ │ + for (var i = tiles.length - 1; i >= 0; --i) { │ │ │ │ │ + tile = tiles[i]; │ │ │ │ │ + tile.style.top = ((ratio * tile._i * tile._h) | 0) + 'px'; │ │ │ │ │ + tile.style.left = ((ratio * tile._j * tile._w) | 0) + 'px'; │ │ │ │ │ + tile.style.width = Math.round(ratio * tile._w) + 'px'; │ │ │ │ │ + tile.style.height = Math.round(ratio * tile._h) + 'px'; │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + // and position it (based on the grid's top-left corner) │ │ │ │ │ + var position = this.getViewPortPxFromLonLat( │ │ │ │ │ + this.backBufferLonLat, resolution); │ │ │ │ │ + var leftOffset = this.map.layerContainerOriginPx.x; │ │ │ │ │ + var topOffset = this.map.layerContainerOriginPx.y; │ │ │ │ │ + backBuffer.style.left = Math.round(position.x - leftOffset) + 'px'; │ │ │ │ │ + backBuffer.style.top = Math.round(position.y - topOffset) + 'px'; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: calculateAngle │ │ │ │ │ - * Calculate the angle based on settings. │ │ │ │ │ + * Method: createBackBuffer │ │ │ │ │ + * Create a back buffer. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ + * grid isn't initialized yet. │ │ │ │ │ */ │ │ │ │ │ - calculateAngle: function(point, evt) { │ │ │ │ │ - var alpha = Math.atan2(point.y - this.origin.y, │ │ │ │ │ - point.x - this.origin.x); │ │ │ │ │ - if (this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) { │ │ │ │ │ - var snapAngleRad = (Math.PI / 180) * this.snapAngle; │ │ │ │ │ - this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad; │ │ │ │ │ - } else { │ │ │ │ │ - this.angle = alpha; │ │ │ │ │ + createBackBuffer: function() { │ │ │ │ │ + var backBuffer; │ │ │ │ │ + if (this.grid.length > 0) { │ │ │ │ │ + backBuffer = document.createElement('div'); │ │ │ │ │ + backBuffer.id = this.div.id + '_bb'; │ │ │ │ │ + backBuffer.className = 'olBackBuffer'; │ │ │ │ │ + backBuffer.style.position = 'absolute'; │ │ │ │ │ + var map = this.map; │ │ │ │ │ + backBuffer.style.zIndex = this.transitionEffect === 'resize' ? │ │ │ │ │ + this.getZIndex() - 1 : │ │ │ │ │ + // 'map-resize': │ │ │ │ │ + map.Z_INDEX_BASE.BaseLayer - │ │ │ │ │ + (map.getNumLayers() - map.getLayerIndex(this)); │ │ │ │ │ + for (var i = 0, lenI = this.grid.length; i < lenI; i++) { │ │ │ │ │ + for (var j = 0, lenJ = this.grid[i].length; j < lenJ; j++) { │ │ │ │ │ + var tile = this.grid[i][j], │ │ │ │ │ + markup = this.grid[i][j].createBackBuffer(); │ │ │ │ │ + if (markup) { │ │ │ │ │ + markup._i = i; │ │ │ │ │ + markup._j = j; │ │ │ │ │ + markup._w = tile.size.w; │ │ │ │ │ + markup._h = tile.size.h; │ │ │ │ │ + markup.id = tile.id + '_bb'; │ │ │ │ │ + backBuffer.appendChild(markup); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return backBuffer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * Method: removeBackBuffer │ │ │ │ │ + * Remove back buffer from DOM. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - // the polygon geometry gets cloned in the callback method │ │ │ │ │ - this.callback("cancel", null); │ │ │ │ │ - this.finalize(); │ │ │ │ │ + removeBackBuffer: function() { │ │ │ │ │ + if (this._transitionElement) { │ │ │ │ │ + for (var i = this.transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ + OpenLayers.Event.stopObserving(this._transitionElement, │ │ │ │ │ + this.transitionendEvents[i], this._removeBackBuffer); │ │ │ │ │ + } │ │ │ │ │ + delete this._transitionElement; │ │ │ │ │ + } │ │ │ │ │ + if (this.backBuffer) { │ │ │ │ │ + if (this.backBuffer.parentNode) { │ │ │ │ │ + this.backBuffer.parentNode.removeChild(this.backBuffer); │ │ │ │ │ + } │ │ │ │ │ + this.backBuffer = null; │ │ │ │ │ + this.backBufferResolution = null; │ │ │ │ │ + if (this.backBufferTimerId !== null) { │ │ │ │ │ + window.clearTimeout(this.backBufferTimerId); │ │ │ │ │ + this.backBufferTimerId = null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finalize │ │ │ │ │ - * Finish the geometry and call the "done" callback. │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Move the layer based on pixel vector. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * dx - {Number} │ │ │ │ │ + * dy - {Number} │ │ │ │ │ */ │ │ │ │ │ - finalize: function() { │ │ │ │ │ - this.origin = null; │ │ │ │ │ - this.radius = this.options.radius; │ │ │ │ │ + moveByPx: function(dx, dy) { │ │ │ │ │ + if (!this.singleTile) { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clear │ │ │ │ │ - * Clear any rendered features on the temporary layer. This is called │ │ │ │ │ - * when the handler is deactivated, canceled, or done (unless persist │ │ │ │ │ - * is true). │ │ │ │ │ + * APIMethod: setTileSize │ │ │ │ │ + * Check if we are in singleTile mode and if so, set the size as a ratio │ │ │ │ │ + * of the map size (as specified by the layer's 'ratio' property). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - if (this.layer) { │ │ │ │ │ - this.layer.renderer.clear(); │ │ │ │ │ - this.layer.destroyFeatures(); │ │ │ │ │ + setTileSize: function(size) { │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + size.h = parseInt(size.h * this.ratio, 10); │ │ │ │ │ + size.w = parseInt(size.w * this.ratio, 10); │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: callback │ │ │ │ │ - * Trigger the control's named callback with the given arguments │ │ │ │ │ + * APIMethod: getTilesBounds │ │ │ │ │ + * Return the bounds of the tile grid. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The key for the callback that is one of the properties │ │ │ │ │ - * of the handler's callbacks object. │ │ │ │ │ - * args - {Array} An array of arguments with which to call the callback │ │ │ │ │ - * (defined by the control). │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object representing the bounds of all the │ │ │ │ │ + * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ + * onscreen). │ │ │ │ │ */ │ │ │ │ │ - callback: function(name, args) { │ │ │ │ │ - // override the callback method to always send the polygon geometry │ │ │ │ │ - if (this.callbacks[name]) { │ │ │ │ │ - this.callbacks[name].apply(this.control, │ │ │ │ │ - [this.feature.geometry.clone()]); │ │ │ │ │ - } │ │ │ │ │ - // since sketch features are added to the temporary layer │ │ │ │ │ - // they must be cleared here if done or cancel │ │ │ │ │ - if (!this.persist && (name == "done" || name == "cancel")) { │ │ │ │ │ - this.clear(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.RegularPolygon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Pinch.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + getTilesBounds: function() { │ │ │ │ │ + var bounds = null; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ + var length = this.grid.length; │ │ │ │ │ + if (length) { │ │ │ │ │ + var bottomLeftTileBounds = this.grid[length - 1][0].bounds, │ │ │ │ │ + width = this.grid[0].length * bottomLeftTileBounds.getWidth(), │ │ │ │ │ + height = this.grid.length * bottomLeftTileBounds.getHeight(); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Pinch │ │ │ │ │ - * The pinch handler is used to deal with sequences of browser events related │ │ │ │ │ - * to pinch gestures. The handler is used by controls that want to know │ │ │ │ │ - * when a pinch sequence begins, when a pinch is happening, and when it has │ │ │ │ │ - * finished. │ │ │ │ │ - * │ │ │ │ │ - * Controls that use the pinch handler typically construct it with callbacks │ │ │ │ │ - * for 'start', 'move', and 'done'. Callbacks for these keys are │ │ │ │ │ - * called when the pinch begins, with each change, and when the pinch is │ │ │ │ │ - * done. │ │ │ │ │ - * │ │ │ │ │ - * Create a new pinch handler with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ + bottomLeftTileBounds.bottom, │ │ │ │ │ + bottomLeftTileBounds.left + width, │ │ │ │ │ + bottomLeftTileBounds.bottom + height); │ │ │ │ │ + } │ │ │ │ │ + return bounds; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: started │ │ │ │ │ - * {Boolean} When a touchstart event is received, we want to record it, │ │ │ │ │ - * but not set 'pinching' until the touchmove get started after │ │ │ │ │ - * starting. │ │ │ │ │ + * Method: initSingleTile │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - started: false, │ │ │ │ │ + initSingleTile: function(bounds) { │ │ │ │ │ + this.events.triggerEvent("retile"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of touchstart events from getting to │ │ │ │ │ - * listeners on the same element. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: false, │ │ │ │ │ + //determine new tile bounds │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ + var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: pinching │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - pinching: false, │ │ │ │ │ + var tileBounds = │ │ │ │ │ + new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ + center.lat - (tileHeight / 2), │ │ │ │ │ + center.lon + (tileWidth / 2), │ │ │ │ │ + center.lat + (tileHeight / 2)); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Object} Object that store informations related to pinch last touch. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ + var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ + lon: tileBounds.left, │ │ │ │ │ + lat: tileBounds.top │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {Object} Object that store informations related to pinch touchstart. │ │ │ │ │ - */ │ │ │ │ │ - start: null, │ │ │ │ │ + if (!this.grid.length) { │ │ │ │ │ + this.grid[0] = []; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Pinch │ │ │ │ │ - * Returns OpenLayers.Handler.Pinch │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handlers setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object containing functions to be called when │ │ │ │ │ - * the pinch operation start, change, or is finished. The callbacks │ │ │ │ │ - * should expect to receive an object argument, which contains │ │ │ │ │ - * information about scale, distance, and position of touch points. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ + var tile = this.grid[0][0]; │ │ │ │ │ + if (!tile) { │ │ │ │ │ + tile = this.addTile(tileBounds, px); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - if (OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.started = true; │ │ │ │ │ - this.last = this.start = { │ │ │ │ │ - distance: this.getDistance(evt.touches), │ │ │ │ │ - delta: 0, │ │ │ │ │ - scale: 1 │ │ │ │ │ - }; │ │ │ │ │ - this.callback("start", [evt, this.start]); │ │ │ │ │ - propagate = !this.stopDown; │ │ │ │ │ - } else if (this.started) { │ │ │ │ │ - // Some webkit versions send fake single-touch events during │ │ │ │ │ - // multitouch, which cause the drag handler to trigger │ │ │ │ │ - return false; │ │ │ │ │ + this.addTileMonitoringHooks(tile); │ │ │ │ │ + tile.draw(); │ │ │ │ │ + this.grid[0][0] = tile; │ │ │ │ │ } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ + tile.moveTo(tileBounds, px); │ │ │ │ │ } │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - return propagate; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - if (this.started && OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.pinching = true; │ │ │ │ │ - var current = this.getPinchData(evt); │ │ │ │ │ - this.callback("move", [evt, current]); │ │ │ │ │ - this.last = current; │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } else if (this.started) { │ │ │ │ │ - // Some webkit versions send fake single-touch events during │ │ │ │ │ - // multitouch, which cause the drag handler to trigger │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + //remove all but our single tile │ │ │ │ │ + this.removeExcessTiles(1, 1); │ │ │ │ │ + │ │ │ │ │ + // store the resolution of the grid │ │ │ │ │ + this.gridResolution = this.getServerResolution(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateGridLayout │ │ │ │ │ + * Generate parameters for the grid layout. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * bounds - {|Object} OpenLayers.Bounds or an │ │ │ │ │ + * object with a 'left' and 'top' properties. │ │ │ │ │ + * origin - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * resolution - {Number} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ + * startrow │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - if (this.started && !OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - this.callback("done", [evt, this.start, this.last]); │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + calculateGridLayout: function(bounds, origin, resolution) { │ │ │ │ │ + var tilelon = resolution * this.tileSize.w; │ │ │ │ │ + var tilelat = resolution * this.tileSize.h; │ │ │ │ │ + │ │ │ │ │ + var offsetlon = bounds.left - origin.lon; │ │ │ │ │ + var tilecol = Math.floor(offsetlon / tilelon) - this.buffer; │ │ │ │ │ + │ │ │ │ │ + var rowSign = this.rowSign; │ │ │ │ │ + │ │ │ │ │ + var offsetlat = rowSign * (origin.lat - bounds.top + tilelat); │ │ │ │ │ + var tilerow = Math[~rowSign ? 'floor' : 'ceil'](offsetlat / tilelat) - this.buffer * rowSign; │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + tilelon: tilelon, │ │ │ │ │ + tilelat: tilelat, │ │ │ │ │ + startcol: tilecol, │ │ │ │ │ + startrow: tilerow │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + * Method: getTileOrigin │ │ │ │ │ + * Determine the origin for aligning the grid of tiles. If a │ │ │ │ │ + * property is supplied, that will be returned. Otherwise, the origin │ │ │ │ │ + * will be derived from the layer's property. In this case, │ │ │ │ │ + * the tile origin will be the corner of the given by the │ │ │ │ │ + * property. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {} The tile origin. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ + getTileOrigin: function() { │ │ │ │ │ + var origin = this.tileOrigin; │ │ │ │ │ + if (!origin) { │ │ │ │ │ + var extent = this.getMaxExtent(); │ │ │ │ │ + var edges = ({ │ │ │ │ │ + "tl": ["left", "top"], │ │ │ │ │ + "tr": ["right", "top"], │ │ │ │ │ + "bl": ["left", "bottom"], │ │ │ │ │ + "br": ["right", "bottom"] │ │ │ │ │ + })[this.tileOriginCorner]; │ │ │ │ │ + origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + return origin; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getDistance │ │ │ │ │ - * Get the distance in pixels between two touches. │ │ │ │ │ + * Method: getTileBoundsForGridIndex │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * touches - {Array(Object)} │ │ │ │ │ + * row - {Number} The row of the grid │ │ │ │ │ + * col - {Number} The column of the grid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Number} The distance in pixels. │ │ │ │ │ + * {} The bounds for the tile at (row, col) │ │ │ │ │ */ │ │ │ │ │ - getDistance: function(touches) { │ │ │ │ │ - var t0 = touches[0]; │ │ │ │ │ - var t1 = touches[1]; │ │ │ │ │ - return Math.sqrt( │ │ │ │ │ - Math.pow(t0.olClientX - t1.olClientX, 2) + │ │ │ │ │ - Math.pow(t0.olClientY - t1.olClientY, 2) │ │ │ │ │ + getTileBoundsForGridIndex: function(row, col) { │ │ │ │ │ + var origin = this.getTileOrigin(); │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + 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 │ │ │ │ │ ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getPinchData │ │ │ │ │ - * Get informations about the pinch event. │ │ │ │ │ - * │ │ │ │ │ + * Method: initGriddedTiles │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Object that contains data about the current pinch. │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - getPinchData: function(evt) { │ │ │ │ │ - var distance = this.getDistance(evt.touches); │ │ │ │ │ - var scale = distance / this.start.distance; │ │ │ │ │ - return { │ │ │ │ │ - distance: distance, │ │ │ │ │ - delta: this.last.distance - distance, │ │ │ │ │ - scale: scale │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ + initGriddedTiles: function(bounds) { │ │ │ │ │ + this.events.triggerEvent("retile"); │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Pinch" │ │ │ │ │ -}); │ │ │ │ │ + // work out mininum number of rows and columns; this is the number of │ │ │ │ │ + // tiles required to cover the viewport plus at least one for panning │ │ │ │ │ │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/MouseWheel.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + var viewSize = this.map.getSize(); │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + var origin = this.getTileOrigin(); │ │ │ │ │ + var resolution = this.map.getResolution(), │ │ │ │ │ + serverResolution = this.getServerResolution(), │ │ │ │ │ + ratio = resolution / serverResolution, │ │ │ │ │ + tileSize = { │ │ │ │ │ + w: this.tileSize.w / ratio, │ │ │ │ │ + h: this.tileSize.h / ratio │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ + var minRows = Math.ceil(viewSize.h / tileSize.h) + │ │ │ │ │ + 2 * this.buffer + 1; │ │ │ │ │ + var minCols = Math.ceil(viewSize.w / tileSize.w) + │ │ │ │ │ + 2 * this.buffer + 1; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.MouseWheel │ │ │ │ │ - * Handler for wheel up/down events. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: wheelListener │ │ │ │ │ - * {function} │ │ │ │ │ - */ │ │ │ │ │ - wheelListener: null, │ │ │ │ │ + var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ + this.gridLayout = tileLayout; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} In order to increase server performance, an interval (in │ │ │ │ │ - * milliseconds) can be set to reduce the number of up/down events │ │ │ │ │ - * called. If set, a new up/down event will not be set until the │ │ │ │ │ - * interval has passed. │ │ │ │ │ - * Defaults to 0, meaning no interval. │ │ │ │ │ - */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + var tilelon = tileLayout.tilelon; │ │ │ │ │ + var tilelat = tileLayout.tilelat; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: maxDelta │ │ │ │ │ - * {Integer} Maximum delta to collect before breaking from the current │ │ │ │ │ - * interval. In cumulative mode, this also limits the maximum delta │ │ │ │ │ - * returned from the handler. Default is Number.POSITIVE_INFINITY. │ │ │ │ │ - */ │ │ │ │ │ - maxDelta: Number.POSITIVE_INFINITY, │ │ │ │ │ + var layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ + var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: delta │ │ │ │ │ - * {Integer} When interval is set, delta collects the mousewheel z-deltas │ │ │ │ │ - * of the events that occur within the interval. │ │ │ │ │ - * See also the cumulative option │ │ │ │ │ - */ │ │ │ │ │ - delta: 0, │ │ │ │ │ + var tileBounds = this.getTileBoundsForGridIndex(0, 0); │ │ │ │ │ + var startPx = this.map.getViewPortPxFromLonLat( │ │ │ │ │ + new OpenLayers.LonLat(tileBounds.left, tileBounds.top) │ │ │ │ │ + ); │ │ │ │ │ + startPx.x = Math.round(startPx.x) - layerContainerDivLeft; │ │ │ │ │ + startPx.y = Math.round(startPx.y) - layerContainerDivTop; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: cumulative │ │ │ │ │ - * {Boolean} When interval is set: true to collect all the mousewheel │ │ │ │ │ - * z-deltas, false to only record the delta direction (positive or │ │ │ │ │ - * negative) │ │ │ │ │ - */ │ │ │ │ │ - cumulative: true, │ │ │ │ │ + var tileData = [], │ │ │ │ │ + center = this.map.getCenter(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.MouseWheel │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * callbacks - {Object} An object containing a single function to be │ │ │ │ │ - * called when the drag operation is finished. │ │ │ │ │ - * The callback should expect to recieve a single │ │ │ │ │ - * argument, the point geometry. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.wheelListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ - this.onWheelEvent, this │ │ │ │ │ - ); │ │ │ │ │ + var rowidx = 0; │ │ │ │ │ + do { │ │ │ │ │ + var row = this.grid[rowidx]; │ │ │ │ │ + if (!row) { │ │ │ │ │ + row = []; │ │ │ │ │ + this.grid.push(row); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var colidx = 0; │ │ │ │ │ + do { │ │ │ │ │ + tileBounds = this.getTileBoundsForGridIndex(rowidx, colidx); │ │ │ │ │ + var px = startPx.clone(); │ │ │ │ │ + px.x = px.x + colidx * Math.round(tileSize.w); │ │ │ │ │ + px.y = px.y + rowidx * Math.round(tileSize.h); │ │ │ │ │ + var tile = row[colidx]; │ │ │ │ │ + if (!tile) { │ │ │ │ │ + tile = this.addTile(tileBounds, px); │ │ │ │ │ + this.addTileMonitoringHooks(tile); │ │ │ │ │ + row.push(tile); │ │ │ │ │ + } else { │ │ │ │ │ + tile.moveTo(tileBounds, px, false); │ │ │ │ │ + } │ │ │ │ │ + var tileCenter = tileBounds.getCenterLonLat(); │ │ │ │ │ + tileData.push({ │ │ │ │ │ + tile: tile, │ │ │ │ │ + distance: Math.pow(tileCenter.lon - center.lon, 2) + │ │ │ │ │ + Math.pow(tileCenter.lat - center.lat, 2) │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + colidx += 1; │ │ │ │ │ + } while ((tileBounds.right <= bounds.right + tilelon * this.buffer) || │ │ │ │ │ + colidx < minCols); │ │ │ │ │ + │ │ │ │ │ + rowidx += 1; │ │ │ │ │ + } while ((tileBounds.bottom >= bounds.bottom - tilelat * this.buffer) || │ │ │ │ │ + rowidx < minRows); │ │ │ │ │ + │ │ │ │ │ + //shave off exceess rows and colums │ │ │ │ │ + this.removeExcessTiles(rowidx, colidx); │ │ │ │ │ + │ │ │ │ │ + var resolution = this.getServerResolution(); │ │ │ │ │ + // store the resolution of the grid │ │ │ │ │ + this.gridResolution = resolution; │ │ │ │ │ + │ │ │ │ │ + //now actually draw the tiles │ │ │ │ │ + tileData.sort(function(a, b) { │ │ │ │ │ + return a.distance - b.distance; │ │ │ │ │ + }); │ │ │ │ │ + for (var i = 0, ii = tileData.length; i < ii; ++i) { │ │ │ │ │ + tileData[i].tile.draw(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: getMaxExtent │ │ │ │ │ + * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ + * potential specific implementations in sub-classes.) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - this.wheelListener = null; │ │ │ │ │ + getMaxExtent: function() { │ │ │ │ │ + return this.maxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ │ │ │ │ │ + * APIMethod: addTile │ │ │ │ │ + * Create a tile, initialize it, and add it to the layer div. │ │ │ │ │ + * │ │ │ │ │ + * Parameters │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * position - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The added OpenLayers.Tile │ │ │ │ │ */ │ │ │ │ │ + addTile: function(bounds, position) { │ │ │ │ │ + var tile = new this.tileClass( │ │ │ │ │ + this, position, bounds, null, this.tileSize, this.tileOptions │ │ │ │ │ + ); │ │ │ │ │ + this.events.triggerEvent("addtile", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + return tile; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onWheelEvent │ │ │ │ │ - * Catch the wheel event and handle it xbrowserly │ │ │ │ │ + * Method: addTileMonitoringHooks │ │ │ │ │ + * This function takes a tile as input and adds the appropriate hooks to │ │ │ │ │ + * the tile so that the layer can keep track of the loading tiles. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - onWheelEvent: function(e) { │ │ │ │ │ - │ │ │ │ │ - // make sure we have a map and check keyboard modifiers │ │ │ │ │ - if (!this.map || !this.checkModifiers(e)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + addTileMonitoringHooks: function(tile) { │ │ │ │ │ │ │ │ │ │ - // Ride up the element's DOM hierarchy to determine if it or any of │ │ │ │ │ - // its ancestors was: │ │ │ │ │ - // * specifically marked as scrollable (CSS overflow property) │ │ │ │ │ - // * one of our layer divs or a div marked as scrollable │ │ │ │ │ - // ('olScrollable' CSS class) │ │ │ │ │ - // * the map div │ │ │ │ │ - // │ │ │ │ │ - var overScrollableDiv = false; │ │ │ │ │ - var allowScroll = false; │ │ │ │ │ - var overMapDiv = false; │ │ │ │ │ + var replacingCls = 'olTileReplacing'; │ │ │ │ │ │ │ │ │ │ - var elem = OpenLayers.Event.element(e); │ │ │ │ │ - while ((elem != null) && !overMapDiv && !overScrollableDiv) { │ │ │ │ │ + tile.onLoadStart = function() { │ │ │ │ │ + //if that was first tile then trigger a 'loadstart' on the layer │ │ │ │ │ + if (this.loading === false) { │ │ │ │ │ + this.loading = true; │ │ │ │ │ + this.events.triggerEvent("loadstart"); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("tileloadstart", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + this.numLoadingTiles++; │ │ │ │ │ + if (!this.singleTile && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ + OpenLayers.Element.addClass(tile.getTile(), replacingCls); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - if (!overScrollableDiv) { │ │ │ │ │ - try { │ │ │ │ │ - var overflow; │ │ │ │ │ - if (elem.currentStyle) { │ │ │ │ │ - overflow = elem.currentStyle["overflow"]; │ │ │ │ │ - } else { │ │ │ │ │ - var style = │ │ │ │ │ - document.defaultView.getComputedStyle(elem, null); │ │ │ │ │ - overflow = style.getPropertyValue("overflow"); │ │ │ │ │ + tile.onLoadEnd = function(evt) { │ │ │ │ │ + this.numLoadingTiles--; │ │ │ │ │ + var aborted = evt.type === 'unload'; │ │ │ │ │ + this.events.triggerEvent("tileloaded", { │ │ │ │ │ + tile: tile, │ │ │ │ │ + aborted: aborted │ │ │ │ │ + }); │ │ │ │ │ + if (!this.singleTile && !aborted && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ + var tileDiv = tile.getTile(); │ │ │ │ │ + if (OpenLayers.Element.getStyle(tileDiv, 'display') === 'none') { │ │ │ │ │ + var bufferTile = document.getElementById(tile.id + '_bb'); │ │ │ │ │ + if (bufferTile) { │ │ │ │ │ + bufferTile.parentNode.removeChild(bufferTile); │ │ │ │ │ } │ │ │ │ │ - overScrollableDiv = (overflow && │ │ │ │ │ - (overflow == "auto") || (overflow == "scroll")); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - //sometimes when scrolling in a popup, this causes │ │ │ │ │ - // obscure browser error │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Element.removeClass(tileDiv, replacingCls); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (!allowScroll) { │ │ │ │ │ - allowScroll = OpenLayers.Element.hasClass(elem, 'olScrollable'); │ │ │ │ │ - if (!allowScroll) { │ │ │ │ │ - for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ - // Are we in the layer div? Note that we have two cases │ │ │ │ │ - // here: one is to catch EventPane layers, which have a │ │ │ │ │ - // pane above the layer (layer.pane) │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if (elem == layer.div || elem == layer.pane) { │ │ │ │ │ - allowScroll = true; │ │ │ │ │ - break; │ │ │ │ │ + //if that was the last tile, then trigger a 'loadend' on the layer │ │ │ │ │ + if (this.numLoadingTiles === 0) { │ │ │ │ │ + if (this.backBuffer) { │ │ │ │ │ + if (this.backBuffer.childNodes.length === 0) { │ │ │ │ │ + // no tiles transitioning, remove immediately │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } else { │ │ │ │ │ + // wait until transition has ended or delay has passed │ │ │ │ │ + this._transitionElement = aborted ? │ │ │ │ │ + this.div.lastChild : tile.imgDiv; │ │ │ │ │ + var transitionendEvents = this.transitionendEvents; │ │ │ │ │ + for (var i = transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ + OpenLayers.Event.observe(this._transitionElement, │ │ │ │ │ + transitionendEvents[i], │ │ │ │ │ + this._removeBackBuffer); │ │ │ │ │ } │ │ │ │ │ + // the removal of the back buffer is delayed to prevent │ │ │ │ │ + // flash effects due to the animation of tile displaying │ │ │ │ │ + this.backBufferTimerId = window.setTimeout( │ │ │ │ │ + this._removeBackBuffer, this.removeBackBufferDelay │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + this.loading = false; │ │ │ │ │ + this.events.triggerEvent("loadend"); │ │ │ │ │ } │ │ │ │ │ - overMapDiv = (elem == this.map.div); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - elem = elem.parentNode; │ │ │ │ │ - } │ │ │ │ │ + tile.onLoadError = function() { │ │ │ │ │ + this.events.triggerEvent("tileerror", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - // Logic below is the following: │ │ │ │ │ - // │ │ │ │ │ - // If we are over a scrollable div or not over the map div: │ │ │ │ │ - // * do nothing (let the browser handle scrolling) │ │ │ │ │ - // │ │ │ │ │ - // otherwise │ │ │ │ │ - // │ │ │ │ │ - // If we are over the layer div or a 'olScrollable' div: │ │ │ │ │ - // * zoom/in out │ │ │ │ │ - // then │ │ │ │ │ - // * kill event (so as not to also scroll the page after zooming) │ │ │ │ │ - // │ │ │ │ │ - // otherwise │ │ │ │ │ - // │ │ │ │ │ - // Kill the event (dont scroll the page if we wheel over the │ │ │ │ │ - // layerswitcher or the pan/zoom control) │ │ │ │ │ - // │ │ │ │ │ - if (!overScrollableDiv && overMapDiv) { │ │ │ │ │ - if (allowScroll) { │ │ │ │ │ - var delta = 0; │ │ │ │ │ + tile.events.on({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (e.wheelDelta) { │ │ │ │ │ - delta = e.wheelDelta; │ │ │ │ │ - if (delta % 160 === 0) { │ │ │ │ │ - // opera have steps of 160 instead of 120 │ │ │ │ │ - delta = delta * 0.75; │ │ │ │ │ - } │ │ │ │ │ - delta = delta / 120; │ │ │ │ │ - } else if (e.detail) { │ │ │ │ │ - // detail in Firefox on OS X is 1/3 of Windows │ │ │ │ │ - // so force delta 1 / -1 │ │ │ │ │ - delta = -(e.detail / Math.abs(e.detail)); │ │ │ │ │ - } │ │ │ │ │ - this.delta += delta; │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeTileMonitoringHooks │ │ │ │ │ + * This function takes a tile as input and removes the tile hooks │ │ │ │ │ + * that were added in addTileMonitoringHooks() │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * tile - {} │ │ │ │ │ + */ │ │ │ │ │ + removeTileMonitoringHooks: function(tile) { │ │ │ │ │ + tile.unload(); │ │ │ │ │ + tile.events.un({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - window.clearTimeout(this._timeoutId); │ │ │ │ │ - if (this.interval && Math.abs(this.delta) < this.maxDelta) { │ │ │ │ │ - // store e because window.event might change during delay │ │ │ │ │ - var evt = OpenLayers.Util.extend({}, e); │ │ │ │ │ - this._timeoutId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.wheelZoom(evt); │ │ │ │ │ - }, this), │ │ │ │ │ - this.interval │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.wheelZoom(e); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveGriddedTiles │ │ │ │ │ + */ │ │ │ │ │ + moveGriddedTiles: function() { │ │ │ │ │ + var buffer = this.buffer + 1; │ │ │ │ │ + while (true) { │ │ │ │ │ + var tlTile = this.grid[0][0]; │ │ │ │ │ + var tlViewPort = { │ │ │ │ │ + x: tlTile.position.x + │ │ │ │ │ + this.map.layerContainerOriginPx.x, │ │ │ │ │ + y: tlTile.position.y + │ │ │ │ │ + this.map.layerContainerOriginPx.y │ │ │ │ │ + }; │ │ │ │ │ + var ratio = this.getServerResolution() / this.map.getResolution(); │ │ │ │ │ + var tileSize = { │ │ │ │ │ + w: Math.round(this.tileSize.w * ratio), │ │ │ │ │ + h: Math.round(this.tileSize.h * ratio) │ │ │ │ │ + }; │ │ │ │ │ + if (tlViewPort.x > -tileSize.w * (buffer - 1)) { │ │ │ │ │ + this.shiftColumn(true, tileSize); │ │ │ │ │ + } else if (tlViewPort.x < -tileSize.w * buffer) { │ │ │ │ │ + this.shiftColumn(false, tileSize); │ │ │ │ │ + } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) { │ │ │ │ │ + this.shiftRow(true, tileSize); │ │ │ │ │ + } else if (tlViewPort.y < -tileSize.h * buffer) { │ │ │ │ │ + this.shiftRow(false, tileSize); │ │ │ │ │ + } else { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: wheelZoom │ │ │ │ │ - * Given the wheel event, we carry out the appropriate zooming in or out, │ │ │ │ │ - * based on the 'wheelDelta' or 'detail' property of the event. │ │ │ │ │ + * Method: shiftRow │ │ │ │ │ + * Shifty grid work │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ + * if false, then append to end │ │ │ │ │ + * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ + */ │ │ │ │ │ + shiftRow: function(prepend, tileSize) { │ │ │ │ │ + var grid = this.grid; │ │ │ │ │ + var rowIndex = prepend ? 0 : (grid.length - 1); │ │ │ │ │ + var sign = prepend ? -1 : 1; │ │ │ │ │ + var rowSign = this.rowSign; │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + tileLayout.startrow += sign * rowSign; │ │ │ │ │ + │ │ │ │ │ + var modelRow = grid[rowIndex]; │ │ │ │ │ + var row = grid[prepend ? 'pop' : 'shift'](); │ │ │ │ │ + for (var i = 0, len = row.length; i < len; i++) { │ │ │ │ │ + var tile = row[i]; │ │ │ │ │ + var position = modelRow[i].position.clone(); │ │ │ │ │ + position.y += tileSize.h * sign; │ │ │ │ │ + tile.moveTo(this.getTileBoundsForGridIndex(rowIndex, i), position); │ │ │ │ │ + } │ │ │ │ │ + grid[prepend ? 'unshift' : 'push'](row); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: shiftColumn │ │ │ │ │ + * Shift grid work in the other dimension │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ + * if false, then append to end │ │ │ │ │ + * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ + */ │ │ │ │ │ + shiftColumn: function(prepend, tileSize) { │ │ │ │ │ + var grid = this.grid; │ │ │ │ │ + var colIndex = prepend ? 0 : (grid[0].length - 1); │ │ │ │ │ + var sign = prepend ? -1 : 1; │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + tileLayout.startcol += sign; │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = grid.length; i < len; i++) { │ │ │ │ │ + var row = grid[i]; │ │ │ │ │ + var position = row[colIndex].position.clone(); │ │ │ │ │ + var tile = row[prepend ? 'pop' : 'shift'](); │ │ │ │ │ + position.x += tileSize.w * sign; │ │ │ │ │ + tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position); │ │ │ │ │ + row[prepend ? 'unshift' : 'push'](tile); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeExcessTiles │ │ │ │ │ + * When the size of the map or the buffer changes, we may need to │ │ │ │ │ + * remove some excess rows and columns. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * rows - {Integer} Maximum number of rows we want our grid to have. │ │ │ │ │ + * columns - {Integer} Maximum number of columns we want our grid to have. │ │ │ │ │ */ │ │ │ │ │ - wheelZoom: function(e) { │ │ │ │ │ - var delta = this.delta; │ │ │ │ │ - this.delta = 0; │ │ │ │ │ + removeExcessTiles: function(rows, columns) { │ │ │ │ │ + var i, l; │ │ │ │ │ │ │ │ │ │ - if (delta) { │ │ │ │ │ - e.xy = this.map.events.getMousePosition(e); │ │ │ │ │ - if (delta < 0) { │ │ │ │ │ - this.callback("down", │ │ │ │ │ - [e, this.cumulative ? Math.max(-this.maxDelta, delta) : -1]); │ │ │ │ │ - } else { │ │ │ │ │ - this.callback("up", │ │ │ │ │ - [e, this.cumulative ? Math.min(this.maxDelta, delta) : 1]); │ │ │ │ │ + // remove extra rows │ │ │ │ │ + while (this.grid.length > rows) { │ │ │ │ │ + var row = this.grid.pop(); │ │ │ │ │ + for (i = 0, l = row.length; i < l; i++) { │ │ │ │ │ + var tile = row[i]; │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // remove extra columns │ │ │ │ │ + for (i = 0, l = this.grid.length; i < l; i++) { │ │ │ │ │ + while (this.grid[i].length > columns) { │ │ │ │ │ + var row = this.grid[i]; │ │ │ │ │ + var tile = row.pop(); │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: onMapResize │ │ │ │ │ + * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ + * dimensions of the map pane. │ │ │ │ │ */ │ │ │ │ │ - activate: function(evt) { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - //register mousewheel events specifically on the window and document │ │ │ │ │ - var wheelListener = this.wheelListener; │ │ │ │ │ - OpenLayers.Event.observe(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ - OpenLayers.Event.observe(window, "mousewheel", wheelListener); │ │ │ │ │ - OpenLayers.Event.observe(document, "mousewheel", wheelListener); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * APIMethod: getTileBounds │ │ │ │ │ + * Returns The tile bounds for a layer given a pixel location. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {} The location in the viewport. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Bounds of the tile at the given pixel location. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function(evt) { │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - // unregister mousewheel events specifically on the window and document │ │ │ │ │ - var wheelListener = this.wheelListener; │ │ │ │ │ - OpenLayers.Event.stopObserving(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ - OpenLayers.Event.stopObserving(window, "mousewheel", wheelListener); │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mousewheel", wheelListener); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ + getTileBounds: function(viewPortPx) { │ │ │ │ │ + var maxExtent = this.maxExtent; │ │ │ │ │ + var resolution = this.getResolution(); │ │ │ │ │ + var tileMapWidth = resolution * this.tileSize.w; │ │ │ │ │ + var tileMapHeight = resolution * this.tileSize.h; │ │ │ │ │ + var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ + var tileLeft = maxExtent.left + (tileMapWidth * │ │ │ │ │ + Math.floor((mapPoint.lon - │ │ │ │ │ + maxExtent.left) / │ │ │ │ │ + tileMapWidth)); │ │ │ │ │ + var tileBottom = maxExtent.bottom + (tileMapHeight * │ │ │ │ │ + Math.floor((mapPoint.lat - │ │ │ │ │ + maxExtent.bottom) / │ │ │ │ │ + tileMapHeight)); │ │ │ │ │ + return new OpenLayers.Bounds(tileLeft, tileBottom, │ │ │ │ │ + tileLeft + tileMapWidth, │ │ │ │ │ + tileBottom + tileMapHeight); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.MouseWheel" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Feature.js │ │ │ │ │ + OpenLayers/TileManager.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ + * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ + * @requires OpenLayers/Tile/Image.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Feature │ │ │ │ │ - * Handler to respond to mouse events related to a drawn feature. Callbacks │ │ │ │ │ - * with the following keys will be notified of the following events │ │ │ │ │ - * associated with features: click, clickout, over, out, and dblclick. │ │ │ │ │ + * Class: OpenLayers.TileManager │ │ │ │ │ + * Provides queueing of image requests and caching of image elements. │ │ │ │ │ * │ │ │ │ │ - * This handler stops event propagation for mousedown and mouseup if those │ │ │ │ │ - * browser events target features that can be selected. │ │ │ │ │ + * Queueing avoids unnecessary image requests while changing zoom levels │ │ │ │ │ + * quickly, and helps improve dragging performance on mobile devices that show │ │ │ │ │ + * a lag in dragging when loading of new images starts. and │ │ │ │ │ + * are the configuration options to control this behavior. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Caching avoids setting the src on image elements for images that have already │ │ │ │ │ + * been used. Several maps can share a TileManager instance, in which case each │ │ │ │ │ + * map gets its own tile queue, but all maps share the same tile cache. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.TileManager = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: EVENTMAP │ │ │ │ │ - * {Object} A object mapping the browser events to objects with callback │ │ │ │ │ - * keys for in and out. │ │ │ │ │ + * APIProperty: cacheSize │ │ │ │ │ + * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ + * cache for fast reuse. Default is 256. │ │ │ │ │ */ │ │ │ │ │ - EVENTMAP: { │ │ │ │ │ - 'click': { │ │ │ │ │ - 'in': 'click', │ │ │ │ │ - 'out': 'clickout' │ │ │ │ │ - }, │ │ │ │ │ - 'mousemove': { │ │ │ │ │ - 'in': 'over', │ │ │ │ │ - 'out': 'out' │ │ │ │ │ - }, │ │ │ │ │ - 'dblclick': { │ │ │ │ │ - 'in': 'dblclick', │ │ │ │ │ - 'out': null │ │ │ │ │ - }, │ │ │ │ │ - 'mousedown': { │ │ │ │ │ - 'in': null, │ │ │ │ │ - 'out': null │ │ │ │ │ - }, │ │ │ │ │ - 'mouseup': { │ │ │ │ │ - 'in': null, │ │ │ │ │ - 'out': null │ │ │ │ │ - }, │ │ │ │ │ - 'touchstart': { │ │ │ │ │ - 'in': 'click', │ │ │ │ │ - 'out': 'clickout' │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + cacheSize: 256, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The last feature that was hovered. │ │ │ │ │ + * APIProperty: tilesPerFrame │ │ │ │ │ + * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ + * Default is 2. │ │ │ │ │ */ │ │ │ │ │ - feature: null, │ │ │ │ │ + tilesPerFrame: 2, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastFeature │ │ │ │ │ - * {} The last feature that was handled. │ │ │ │ │ + * APIProperty: frameDelay │ │ │ │ │ + * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ + * milliseconds. Default is 16. │ │ │ │ │ */ │ │ │ │ │ - lastFeature: null, │ │ │ │ │ + frameDelay: 16, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: down │ │ │ │ │ - * {} The location of the last mousedown. │ │ │ │ │ + * APIProperty: moveDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ + * tiles. Default is 100. │ │ │ │ │ */ │ │ │ │ │ - down: null, │ │ │ │ │ + moveDelay: 100, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: up │ │ │ │ │ - * {} The location of the last mouseup. │ │ │ │ │ + * APIProperty: zoomDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ + * tiles. Default is 200. │ │ │ │ │ */ │ │ │ │ │ - up: null, │ │ │ │ │ + zoomDelay: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: clickTolerance │ │ │ │ │ - * {Number} The number of pixels the mouse can move between mousedown │ │ │ │ │ - * and mouseup for the event to still be considered a click. │ │ │ │ │ - * Dragging the map should not trigger the click and clickout callbacks │ │ │ │ │ - * unless the map is moved by less than this tolerance. Defaults to 4. │ │ │ │ │ + * Property: maps │ │ │ │ │ + * {Array()} The maps to manage tiles on. │ │ │ │ │ */ │ │ │ │ │ - clickTolerance: 4, │ │ │ │ │ + maps: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: geometryTypes │ │ │ │ │ - * To restrict dragging to a limited set of geometry types, send a list │ │ │ │ │ - * of strings corresponding to the geometry class names. │ │ │ │ │ - * │ │ │ │ │ - * @type Array(String) │ │ │ │ │ + * Property: tileQueueId │ │ │ │ │ + * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ + tileQueueId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stopClick │ │ │ │ │ - * {Boolean} If stopClick is set to true, handled clicks do not │ │ │ │ │ - * propagate to other click listeners. Otherwise, handled clicks │ │ │ │ │ - * do propagate. Unhandled clicks always propagate, whatever the │ │ │ │ │ - * value of stopClick. Defaults to true. │ │ │ │ │ + * Property: tileQueue │ │ │ │ │ + * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ + * map id. │ │ │ │ │ */ │ │ │ │ │ - stopClick: true, │ │ │ │ │ + tileQueue: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} If stopDown is set to true, handled mousedowns do not │ │ │ │ │ - * propagate to other mousedown listeners. Otherwise, handled │ │ │ │ │ - * mousedowns do propagate. Unhandled mousedowns always propagate, │ │ │ │ │ - * whatever the value of stopDown. Defaults to true. │ │ │ │ │ + * Property: tileCache │ │ │ │ │ + * {Object} Cached image elements, keyed by URL. │ │ │ │ │ */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ + tileCache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stopUp │ │ │ │ │ - * {Boolean} If stopUp is set to true, handled mouseups do not │ │ │ │ │ - * propagate to other mouseup listeners. Otherwise, handled mouseups │ │ │ │ │ - * do propagate. Unhandled mouseups always propagate, whatever the │ │ │ │ │ - * value of stopUp. Defaults to false. │ │ │ │ │ + * Property: tileCacheIndex │ │ │ │ │ + * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ + * used. │ │ │ │ │ */ │ │ │ │ │ - stopUp: false, │ │ │ │ │ + tileCacheIndex: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.TileManager │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Configuration for this instance. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.maps = []; │ │ │ │ │ + this.tileQueueId = {}; │ │ │ │ │ + this.tileQueue = {}; │ │ │ │ │ + this.tileCache = {}; │ │ │ │ │ + this.tileCacheIndex = []; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Feature │ │ │ │ │ + * Method: addMap │ │ │ │ │ + * Binds this instance to a map │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * layer - {} │ │ │ │ │ - * callbacks - {Object} An object with a 'over' property whos value is │ │ │ │ │ - * a function to be called when the mouse is over a feature. The │ │ │ │ │ - * callback should expect to recieve a single argument, the feature. │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, layer, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, [control, callbacks, options]); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ + addMap: function(map) { │ │ │ │ │ + if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.maps.push(map); │ │ │ │ │ + this.tileQueue[map.id] = []; │ │ │ │ │ + for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: map.layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + map.events.on({ │ │ │ │ │ + move: this.move, │ │ │ │ │ + zoomend: this.zoomEnd, │ │ │ │ │ + changelayer: this.changeLayer, │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + preremovelayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Unbinds this instance from a map │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return OpenLayers.Event.isMultiTouch(evt) ? │ │ │ │ │ - true : this.mousedown(evt); │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ + if (map.layers) { │ │ │ │ │ + for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: map.layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (map.events) { │ │ │ │ │ + map.events.un({ │ │ │ │ │ + move: this.move, │ │ │ │ │ + zoomend: this.zoomEnd, │ │ │ │ │ + changelayer: this.changeLayer, │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + preremovelayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + delete this.tileQueue[map.id]; │ │ │ │ │ + delete this.tileQueueId[map.id]; │ │ │ │ │ + OpenLayers.Util.removeItem(this.maps, map); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events. We just prevent the browser default behavior, │ │ │ │ │ - * for Android Webkit not to select text when moving the finger after │ │ │ │ │ - * selecting a feature. │ │ │ │ │ + * Method: move │ │ │ │ │ + * Handles the map's move event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mouse down. Stop propagation if a feature is targeted by this │ │ │ │ │ - * event (stops map dragging during feature selection). │ │ │ │ │ - * │ │ │ │ │ + * Method: zoomEnd │ │ │ │ │ + * Handles the map's zoomEnd event │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - // Feature selection is only done with a left click. Other handlers may stop the │ │ │ │ │ - // propagation of left-click mousedown events but not right-click mousedown events. │ │ │ │ │ - // This mismatch causes problems when comparing the location of the down and up │ │ │ │ │ - // events in the click function so it is important ignore right-clicks. │ │ │ │ │ - if (OpenLayers.Event.isLeftClick(evt) || OpenLayers.Event.isSingleTouch(evt)) { │ │ │ │ │ - this.down = evt.xy; │ │ │ │ │ - } │ │ │ │ │ - return this.handle(evt) ? !this.stopDown : true; │ │ │ │ │ + zoomEnd: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouse up. Stop propagation if a feature is targeted by this │ │ │ │ │ - * event. │ │ │ │ │ - * │ │ │ │ │ + * Method: changeLayer │ │ │ │ │ + * Handles the map's changeLayer event │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - this.up = evt.xy; │ │ │ │ │ - return this.handle(evt) ? !this.stopUp : true; │ │ │ │ │ + changeLayer: function(evt) { │ │ │ │ │ + if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ + this.updateTimeout(evt.object, 0); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * Handle click. Call the "click" callback if click on a feature, │ │ │ │ │ - * or the "clickout" callback if click outside any feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Handles the map's addlayer event │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - return this.handle(evt) ? !this.stopClick : true; │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + var layer = evt.layer; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + layer.events.on({ │ │ │ │ │ + addtile: this.addTile, │ │ │ │ │ + retile: this.clearTileQueue, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + var i, j, tile; │ │ │ │ │ + for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ + for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ + tile = layer.grid[i][j]; │ │ │ │ │ + this.addTile({ │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + if (tile.url && !tile.imgDiv) { │ │ │ │ │ + this.manageTileCache({ │ │ │ │ │ + object: tile │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mouse moves. Call the "over" callback if moving in to a feature, │ │ │ │ │ - * or the "out" callback if moving out of a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Handles the map's preremovelayer event │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - if (!this.callbacks['over'] && !this.callbacks['out']) { │ │ │ │ │ - return true; │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + var layer = evt.layer; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + this.clearTileQueue({ │ │ │ │ │ + object: layer │ │ │ │ │ + }); │ │ │ │ │ + if (layer.events) { │ │ │ │ │ + layer.events.un({ │ │ │ │ │ + addtile: this.addTile, │ │ │ │ │ + retile: this.clearTileQueue, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (layer.grid) { │ │ │ │ │ + var i, j, tile; │ │ │ │ │ + for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ + for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ + tile = layer.grid[i][j]; │ │ │ │ │ + this.unloadTile({ │ │ │ │ │ + object: tile │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.handle(evt); │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle dblclick. Call the "dblclick" callback if dblclick on a feature. │ │ │ │ │ + * Method: updateTimeout │ │ │ │ │ + * Applies the or to the loop, │ │ │ │ │ + * and schedules more queue processing after if there are still │ │ │ │ │ + * tiles in the queue. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * map - {} The map to update the timeout for │ │ │ │ │ + * delay - {Number} The delay to apply │ │ │ │ │ + * nice - {Boolean} If true, the timeout function will only be created if │ │ │ │ │ + * the tilequeue is not empty. This is used by the move handler to │ │ │ │ │ + * avoid impacts on dragging performance. For other events, the tile │ │ │ │ │ + * queue may not be populated yet, so we need to set the timer │ │ │ │ │ + * regardless of the queue size. │ │ │ │ │ */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - return !this.handle(evt); │ │ │ │ │ + updateTimeout: function(map, delay, nice) { │ │ │ │ │ + window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ + var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ + if (!nice || tileQueue.length) { │ │ │ │ │ + this.tileQueueId[map.id] = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.drawTilesFromQueue(map); │ │ │ │ │ + if (tileQueue.length) { │ │ │ │ │ + this.updateTimeout(map, this.frameDelay); │ │ │ │ │ + } │ │ │ │ │ + }, this), delay │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: geometryTypeMatches │ │ │ │ │ - * Return true if the geometry type of the passed feature matches │ │ │ │ │ - * one of the geometry types in the geometryTypes array. │ │ │ │ │ + * Method: addTile │ │ │ │ │ + * Listener for the layer's addtile event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - geometryTypeMatches: function(feature) { │ │ │ │ │ - return this.geometryTypes == null || │ │ │ │ │ - OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ - feature.geometry.CLASS_NAME) > -1; │ │ │ │ │ + addTile: function(evt) { │ │ │ │ │ + if (evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ + evt.tile.events.on({ │ │ │ │ │ + beforedraw: this.queueTileDraw, │ │ │ │ │ + beforeload: this.manageTileCache, │ │ │ │ │ + loadend: this.addToCache, │ │ │ │ │ + unload: this.unloadTile, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + // Layer has the wrong tile type, so don't handle it any longer │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: evt.tile.layer │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handle │ │ │ │ │ + * Method: unloadTile │ │ │ │ │ + * Listener for the tile's unload event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The event occurred over a relevant feature. │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - handle: function(evt) { │ │ │ │ │ - if (this.feature && !this.feature.layer) { │ │ │ │ │ - // feature has been destroyed │ │ │ │ │ - this.feature = null; │ │ │ │ │ - } │ │ │ │ │ - var type = evt.type; │ │ │ │ │ - var handled = false; │ │ │ │ │ - var previouslyIn = !!(this.feature); // previously in a feature │ │ │ │ │ - var click = (type == "click" || type == "dblclick" || type == "touchstart"); │ │ │ │ │ - this.feature = this.layer.getFeatureFromEvent(evt); │ │ │ │ │ - if (this.feature && !this.feature.layer) { │ │ │ │ │ - // feature has been destroyed │ │ │ │ │ - this.feature = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.lastFeature && !this.lastFeature.layer) { │ │ │ │ │ - // last feature has been destroyed │ │ │ │ │ - this.lastFeature = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.feature) { │ │ │ │ │ - if (type === "touchstart") { │ │ │ │ │ - // stop the event to prevent Android Webkit from │ │ │ │ │ - // "flashing" the map div │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - } │ │ │ │ │ - var inNew = (this.feature != this.lastFeature); │ │ │ │ │ - if (this.geometryTypeMatches(this.feature)) { │ │ │ │ │ - // in to a feature │ │ │ │ │ - if (previouslyIn && inNew) { │ │ │ │ │ - // out of last feature and in to another │ │ │ │ │ - if (this.lastFeature) { │ │ │ │ │ - this.triggerCallback(type, 'out', [this.lastFeature]); │ │ │ │ │ - } │ │ │ │ │ - this.triggerCallback(type, 'in', [this.feature]); │ │ │ │ │ - } else if (!previouslyIn || click) { │ │ │ │ │ - // in feature for the first time │ │ │ │ │ - this.triggerCallback(type, 'in', [this.feature]); │ │ │ │ │ - } │ │ │ │ │ - this.lastFeature = this.feature; │ │ │ │ │ - handled = true; │ │ │ │ │ - } else { │ │ │ │ │ - // not in to a feature │ │ │ │ │ - if (this.lastFeature && (previouslyIn && inNew || click)) { │ │ │ │ │ - // out of last feature for the first time │ │ │ │ │ - this.triggerCallback(type, 'out', [this.lastFeature]); │ │ │ │ │ - } │ │ │ │ │ - // next time the mouse goes in a feature whose geometry type │ │ │ │ │ - // doesn't match we don't want to call the 'out' callback │ │ │ │ │ - // again, so let's set this.feature to null so that │ │ │ │ │ - // previouslyIn will evaluate to false the next time │ │ │ │ │ - // we enter handle. Yes, a bit hackish... │ │ │ │ │ - this.feature = null; │ │ │ │ │ - } │ │ │ │ │ - } else if (this.lastFeature && (previouslyIn || click)) { │ │ │ │ │ - this.triggerCallback(type, 'out', [this.lastFeature]); │ │ │ │ │ - } │ │ │ │ │ - return handled; │ │ │ │ │ + unloadTile: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + tile.events.un({ │ │ │ │ │ + beforedraw: this.queueTileDraw, │ │ │ │ │ + beforeload: this.manageTileCache, │ │ │ │ │ + loadend: this.addToCache, │ │ │ │ │ + unload: this.unloadTile, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileQueue[tile.layer.map.id], tile); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: triggerCallback │ │ │ │ │ - * Call the callback keyed in the event map with the supplied arguments. │ │ │ │ │ - * For click and clickout, the is checked first. │ │ │ │ │ + * Method: queueTileDraw │ │ │ │ │ + * Adds a tile to the queue that will draw it. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ */ │ │ │ │ │ - triggerCallback: function(type, mode, args) { │ │ │ │ │ - var key = this.EVENTMAP[type][mode]; │ │ │ │ │ - if (key) { │ │ │ │ │ - if (type == 'click' && this.up && this.down) { │ │ │ │ │ - // for click/clickout, only trigger callback if tolerance is met │ │ │ │ │ - var dpx = Math.sqrt( │ │ │ │ │ - Math.pow(this.up.x - this.down.x, 2) + │ │ │ │ │ - Math.pow(this.up.y - this.down.y, 2) │ │ │ │ │ - ); │ │ │ │ │ - if (dpx <= this.clickTolerance) { │ │ │ │ │ - this.callback(key, args); │ │ │ │ │ - } │ │ │ │ │ - // we're done with this set of events now: clear the cached │ │ │ │ │ - // positions so we can't trip over them later (this can occur │ │ │ │ │ - // if one of the up/down events gets eaten before it gets to us │ │ │ │ │ - // but we still get the click) │ │ │ │ │ - this.up = this.down = null; │ │ │ │ │ - } else { │ │ │ │ │ - this.callback(key, args); │ │ │ │ │ + queueTileDraw: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + var queued = false; │ │ │ │ │ + var layer = tile.layer; │ │ │ │ │ + var url = layer.getURL(tile.bounds); │ │ │ │ │ + var img = this.tileCache[url]; │ │ │ │ │ + if (img && img.className !== 'olTileImage') { │ │ │ │ │ + // cached image no longer valid, e.g. because we're olTileReplacing │ │ │ │ │ + delete this.tileCache[url]; │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileCacheIndex, url); │ │ │ │ │ + img = null; │ │ │ │ │ + } │ │ │ │ │ + // queue only if image with same url not cached already │ │ │ │ │ + if (layer.url && (layer.async || !img)) { │ │ │ │ │ + // add to queue only if not in queue already │ │ │ │ │ + var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ + if (!~OpenLayers.Util.indexOf(tileQueue, tile)) { │ │ │ │ │ + tileQueue.push(tile); │ │ │ │ │ } │ │ │ │ │ + queued = true; │ │ │ │ │ } │ │ │ │ │ + return !queued; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Method: drawTilesFromQueue │ │ │ │ │ + * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - activated = true; │ │ │ │ │ + drawTilesFromQueue: function(map) { │ │ │ │ │ + var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ + var limit = this.tilesPerFrame; │ │ │ │ │ + var animating = map.zoomTween && map.zoomTween.playing; │ │ │ │ │ + while (!animating && tileQueue.length && limit) { │ │ │ │ │ + tileQueue.shift().draw(true); │ │ │ │ │ + --limit; │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Turn off the handler. Returns false if the handler was already active. │ │ │ │ │ + * Method: manageTileCache │ │ │ │ │ + * Adds, updates, removes and fetches cache entries. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.moveLayerBack(); │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.lastFeature = null; │ │ │ │ │ - this.down = null; │ │ │ │ │ - this.up = null; │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - deactivated = true; │ │ │ │ │ + manageTileCache: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + var img = this.tileCache[tile.url]; │ │ │ │ │ + if (img) { │ │ │ │ │ + // if image is on its layer's backbuffer, remove it from backbuffer │ │ │ │ │ + if (img.parentNode && │ │ │ │ │ + OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer')) { │ │ │ │ │ + img.parentNode.removeChild(img); │ │ │ │ │ + img.id = null; │ │ │ │ │ + } │ │ │ │ │ + // only use image from cache if it is not on a layer already │ │ │ │ │ + if (!img.parentNode) { │ │ │ │ │ + img.style.visibility = 'hidden'; │ │ │ │ │ + img.style.opacity = 0; │ │ │ │ │ + tile.setImage(img); │ │ │ │ │ + // LRU - move tile to the end of the array to mark it as the most │ │ │ │ │ + // recently used │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url); │ │ │ │ │ + this.tileCacheIndex.push(tile.url); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleMapEvents │ │ │ │ │ - * │ │ │ │ │ + * Method: addToCache │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ */ │ │ │ │ │ - handleMapEvents: function(evt) { │ │ │ │ │ - if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ + addToCache: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + if (!this.tileCache[tile.url]) { │ │ │ │ │ + if (!OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError')) { │ │ │ │ │ + if (this.tileCacheIndex.length >= this.cacheSize) { │ │ │ │ │ + delete this.tileCache[this.tileCacheIndex[0]]; │ │ │ │ │ + this.tileCacheIndex.shift(); │ │ │ │ │ + } │ │ │ │ │ + this.tileCache[tile.url] = tile.imgDiv; │ │ │ │ │ + this.tileCacheIndex.push(tile.url); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveLayerToTop │ │ │ │ │ - * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ - * it. │ │ │ │ │ + * Method: clearTileQueue │ │ │ │ │ + * Clears the tile queue from tiles of a specific layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the layer's retile event │ │ │ │ │ */ │ │ │ │ │ - moveLayerToTop: function() { │ │ │ │ │ - var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ - this.layer.getZIndex()) + 1; │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ - │ │ │ │ │ + clearTileQueue: function(evt) { │ │ │ │ │ + var layer = evt.object; │ │ │ │ │ + var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ + for (var i = tileQueue.length - 1; i >= 0; --i) { │ │ │ │ │ + if (tileQueue[i].layer === layer) { │ │ │ │ │ + tileQueue.splice(i, 1); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveLayerBack │ │ │ │ │ - * Moves the layer back to the position determined by the map's layers │ │ │ │ │ - * array. │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - moveLayerBack: function() { │ │ │ │ │ - var index = this.layer.getZIndex() - 1; │ │ │ │ │ - if (index >= this.map.Z_INDEX_BASE['Feature']) { │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.setLayerZIndex(this.layer, │ │ │ │ │ - this.map.getLayerIndex(this.layer)); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = this.maps.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeMap(this.maps[i]); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + this.maps = null; │ │ │ │ │ + this.tileQueue = null; │ │ │ │ │ + this.tileQueueId = null; │ │ │ │ │ + this.tileCache = null; │ │ │ │ │ + this.tileCacheIndex = null; │ │ │ │ │ + this._destroyed = true; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Feature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Click.js │ │ │ │ │ + OpenLayers/Handler.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Click │ │ │ │ │ - * A handler for mouse clicks. The intention of this handler is to give │ │ │ │ │ - * controls more flexibility with handling clicks. Browsers trigger │ │ │ │ │ - * click events twice for a double-click. In addition, the mousedown, │ │ │ │ │ - * mousemove, mouseup sequence fires a click event. With this handler, │ │ │ │ │ - * controls can decide whether to ignore clicks associated with a double │ │ │ │ │ - * click. By setting a , controls can also ignore clicks │ │ │ │ │ - * that include a drag. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Handler │ │ │ │ │ + * Base class to construct a higher-level handler for event sequences. All │ │ │ │ │ + * handlers have activate and deactivate methods. In addition, they have │ │ │ │ │ + * methods named like browser events. When a handler is activated, any │ │ │ │ │ + * additional methods named like a browser event is registered as a │ │ │ │ │ + * listener for the corresponding event. When a handler is deactivated, │ │ │ │ │ + * those same methods are unregistered as event listeners. │ │ │ │ │ + * │ │ │ │ │ + * Handlers also typically have a callbacks object with keys named like │ │ │ │ │ + * the abstracted events or event sequences that they are in charge of │ │ │ │ │ + * handling. The controls that wrap handlers define the methods that │ │ │ │ │ + * correspond to these abstract events - so instead of listening for │ │ │ │ │ + * individual browser events, they only listen for the abstract events │ │ │ │ │ + * defined by the handler. │ │ │ │ │ + * │ │ │ │ │ + * Handlers are created by controls, which ultimately have the responsibility │ │ │ │ │ + * of making changes to the the state of the application. Handlers │ │ │ │ │ + * themselves may make temporary changes, but in general are expected to │ │ │ │ │ + * return the application in the same state that they found it. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: delay │ │ │ │ │ - * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ - * considered a double-click. │ │ │ │ │ - */ │ │ │ │ │ - delay: 300, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: single │ │ │ │ │ - * {Boolean} Handle single clicks. Default is true. If false, clicks │ │ │ │ │ - * will not be reported. If true, single-clicks will be reported. │ │ │ │ │ - */ │ │ │ │ │ - single: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: double │ │ │ │ │ - * {Boolean} Handle double-clicks. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - 'double': false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Number} Maximum number of pixels between mouseup and mousedown for an │ │ │ │ │ - * event to be considered a click. Default is 0. If set to an │ │ │ │ │ - * integer value, clicks with a drag greater than the value will be │ │ │ │ │ - * ignored. This property can only be set when the handler is │ │ │ │ │ - * constructed. │ │ │ │ │ - */ │ │ │ │ │ - pixelTolerance: 0, │ │ │ │ │ +OpenLayers.Handler = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dblclickTolerance │ │ │ │ │ - * {Number} Maximum distance in pixels between clicks for a sequence of │ │ │ │ │ - * events to be considered a double click. Default is 13. If the │ │ │ │ │ - * distance between two clicks is greater than this value, a double- │ │ │ │ │ - * click will not be fired. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - dblclickTolerance: 13, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopSingle │ │ │ │ │ - * {Boolean} Stop other listeners from being notified of clicks. Default │ │ │ │ │ - * is false. If true, any listeners registered before this one for │ │ │ │ │ - * click or rightclick events will not be notified. │ │ │ │ │ + * APIProperty: control │ │ │ │ │ + * {}. The control that initialized this handler. The │ │ │ │ │ + * control is assumed to have a valid map property - that map is used │ │ │ │ │ + * in the handler's own setMap method. │ │ │ │ │ */ │ │ │ │ │ - stopSingle: false, │ │ │ │ │ + control: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopDouble │ │ │ │ │ - * {Boolean} Stop other listeners from being notified of double-clicks. │ │ │ │ │ - * Default is false. If true, any click listeners registered before │ │ │ │ │ - * this one will not be notified of *any* double-click events. │ │ │ │ │ - * │ │ │ │ │ - * The one caveat with stopDouble is that given a map with two click │ │ │ │ │ - * handlers, one with stopDouble true and the other with stopSingle │ │ │ │ │ - * true, the stopSingle handler should be activated last to get │ │ │ │ │ - * uniform cross-browser performance. Since IE triggers one click │ │ │ │ │ - * with a dblclick and FF triggers two, if a stopSingle handler is │ │ │ │ │ - * activated first, all it gets in IE is a single click when the │ │ │ │ │ - * second handler stops propagation on the dblclick. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - stopDouble: false, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ + * APIProperty: keyMask │ │ │ │ │ + * {Integer} Use bitwise operators and one or more of the OpenLayers.Handler │ │ │ │ │ + * constants to construct a keyMask. The keyMask is used by │ │ │ │ │ + * . If the keyMask matches the combination of keys │ │ │ │ │ + * down on an event, checkModifiers returns true. │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * // handler only responds if the Shift key is down │ │ │ │ │ + * handler.keyMask = OpenLayers.Handler.MOD_SHIFT; │ │ │ │ │ + * │ │ │ │ │ + * // handler only responds if Ctrl-Shift is down │ │ │ │ │ + * handler.keyMask = OpenLayers.Handler.MOD_SHIFT | │ │ │ │ │ + * OpenLayers.Handler.MOD_CTRL; │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + keyMask: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: down │ │ │ │ │ - * {Object} Object that store relevant information about the last │ │ │ │ │ - * mousedown or touchstart. Its 'xy' OpenLayers.Pixel property gives │ │ │ │ │ - * the average location of the mouse/touch event. Its 'touches' │ │ │ │ │ - * property records clientX/clientY of each touches. │ │ │ │ │ + * Property: active │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - down: null, │ │ │ │ │ + active: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Object} Object that store relevant information about the last │ │ │ │ │ - * mousemove or touchmove. Its 'xy' OpenLayers.Pixel property gives │ │ │ │ │ - * the average location of the mouse/touch event. Its 'touches' │ │ │ │ │ - * property records clientX/clientY of each touches. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: first │ │ │ │ │ - * {Object} When waiting for double clicks, this object will store │ │ │ │ │ - * information about the first click in a two click sequence. │ │ │ │ │ + * Property: evt │ │ │ │ │ + * {Event} This property references the last event handled by the handler. │ │ │ │ │ + * Note that this property is not part of the stable API. Use of the │ │ │ │ │ + * evt property should be restricted to controls in the library │ │ │ │ │ + * or other applications that are willing to update with changes to │ │ │ │ │ + * the OpenLayers code. │ │ │ │ │ */ │ │ │ │ │ - first: null, │ │ │ │ │ + evt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: rightclickTimerId │ │ │ │ │ - * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ - * . │ │ │ │ │ + * Property: touch │ │ │ │ │ + * {Boolean} Indicates the support of touch events. When touch events are │ │ │ │ │ + * started touch will be true and all mouse related listeners will do │ │ │ │ │ + * nothing. │ │ │ │ │ */ │ │ │ │ │ - rightclickTimerId: null, │ │ │ │ │ + touch: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Click │ │ │ │ │ - * Create a new click handler. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Handler │ │ │ │ │ + * Construct a handler. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handler's setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object with keys corresponding to callbacks │ │ │ │ │ - * that will be called by the handler. The callbacks should │ │ │ │ │ - * expect to recieve a single argument, the click event. │ │ │ │ │ - * Callbacks for 'click' and 'dblclick' are supported. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * handler. │ │ │ │ │ + * control - {} The control that initialized this │ │ │ │ │ + * handler. The control is assumed to have a valid map property; that │ │ │ │ │ + * map is used in the handler's own setMap method. If a map property │ │ │ │ │ + * is present in the options argument it will be used instead. │ │ │ │ │ + * callbacks - {Object} An object whose properties correspond to abstracted │ │ │ │ │ + * events or sequences of browser events. The values for these │ │ │ │ │ + * properties are functions defined by the control that get called by │ │ │ │ │ + * the handler. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * the handler. │ │ │ │ │ */ │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.control = control; │ │ │ │ │ + this.callbacks = callbacks; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + var map = this.map || control.map; │ │ │ │ │ + if (map) { │ │ │ │ │ + this.setMap(map); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Store position of last move, because touchend event can have │ │ │ │ │ - * an empty "touches" property. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Method: setMap │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ - * touches property from last touchstart or touchmove │ │ │ │ │ + * Method: checkModifiers │ │ │ │ │ + * Check the keyMask on the handler. If no is set, this always │ │ │ │ │ + * returns true. If a is set and it matches the combination │ │ │ │ │ + * of keys down on an event, this returns true. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Boolean} The keyMask matches the keys down on an event. │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - // touchstart may not have been allowed to propagate │ │ │ │ │ - if (this.down) { │ │ │ │ │ - evt.xy = this.last.xy; │ │ │ │ │ - evt.lastTouches = this.last.touches; │ │ │ │ │ - this.handleSingle(evt); │ │ │ │ │ - this.down = null; │ │ │ │ │ + checkModifiers: function(evt) { │ │ │ │ │ + if (this.keyMask == null) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + /* calculate the keyboard modifier mask for this event */ │ │ │ │ │ + var keyModifiers = │ │ │ │ │ + (evt.shiftKey ? OpenLayers.Handler.MOD_SHIFT : 0) | │ │ │ │ │ + (evt.ctrlKey ? OpenLayers.Handler.MOD_CTRL : 0) | │ │ │ │ │ + (evt.altKey ? OpenLayers.Handler.MOD_ALT : 0) | │ │ │ │ │ + (evt.metaKey ? OpenLayers.Handler.MOD_META : 0); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + /* if it differs from the handler object's key mask, │ │ │ │ │ + bail out of the event handler */ │ │ │ │ │ + return (keyModifiers == this.keyMask); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was activated. │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - │ │ │ │ │ - // Collect right mouse clicks from the mouseup │ │ │ │ │ - // IE - ignores the second right click in mousedown so using │ │ │ │ │ - // mouseup instead │ │ │ │ │ - if (this.checkModifiers(evt) && this.control.handleRightClicks && │ │ │ │ │ - OpenLayers.Event.isRightClick(evt)) { │ │ │ │ │ - propagate = this.rightclick(evt); │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return propagate; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: rightclick │ │ │ │ │ - * Handle rightclick. For a dblrightclick, we get two clicks so we need │ │ │ │ │ - * to always register for dblrightclick to properly handle single │ │ │ │ │ - * clicks. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - rightclick: function(evt) { │ │ │ │ │ - if (this.passesTolerance(evt)) { │ │ │ │ │ - if (this.rightclickTimerId != null) { │ │ │ │ │ - //Second click received before timeout this must be │ │ │ │ │ - // a double click │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('dblrightclick', [evt]); │ │ │ │ │ - return !this.stopDouble; │ │ │ │ │ - } else { │ │ │ │ │ - //Set the rightclickTimerId, send evt only if double is │ │ │ │ │ - // true else trigger single │ │ │ │ │ - var clickEvent = this['double'] ? │ │ │ │ │ - OpenLayers.Util.extend({}, evt) : │ │ │ │ │ - this.callback('rightclick', [evt]); │ │ │ │ │ - │ │ │ │ │ - var delayedRightCall = OpenLayers.Function.bind( │ │ │ │ │ - this.delayedRightCall, │ │ │ │ │ - this, │ │ │ │ │ - clickEvent │ │ │ │ │ - ); │ │ │ │ │ - this.rightclickTimerId = window.setTimeout( │ │ │ │ │ - delayedRightCall, this.delay │ │ │ │ │ - ); │ │ │ │ │ + // register for event handlers defined on this class. │ │ │ │ │ + var events = OpenLayers.Events.prototype.BROWSER_EVENTS; │ │ │ │ │ + for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ + if (this[events[i]]) { │ │ │ │ │ + this.register(events[i], this[events[i]]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: delayedRightCall │ │ │ │ │ - * Sets to null. And optionally triggers the │ │ │ │ │ - * rightclick callback if evt is set. │ │ │ │ │ - */ │ │ │ │ │ - delayedRightCall: function(evt) { │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback('rightclick', [evt]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * Handle click events from the browser. This is registered as a listener │ │ │ │ │ - * for click events and should not be called from other events in this │ │ │ │ │ - * handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - if (!this.last) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - } │ │ │ │ │ - this.handleSingle(evt); │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ + this.active = true; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle dblclick. For a dblclick, we get two clicks in some browsers │ │ │ │ │ - * (FF) and one in others (IE). So we need to always register for │ │ │ │ │ - * dblclick to properly handle single clicks. This method is registered │ │ │ │ │ - * as a listener for the dblclick browser event. It should *not* be │ │ │ │ │ - * called by other methods in this handler. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Turn off the handler. Returns false if the handler was already inactive. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - this.handleDouble(evt); │ │ │ │ │ - return !this.stopDouble; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleDouble │ │ │ │ │ - * Handle double-click sequence. │ │ │ │ │ + * {Boolean} The handler was deactivated. │ │ │ │ │ */ │ │ │ │ │ - handleDouble: function(evt) { │ │ │ │ │ - if (this.passesDblclickTolerance(evt)) { │ │ │ │ │ - if (this["double"]) { │ │ │ │ │ - this.callback("dblclick", [evt]); │ │ │ │ │ - } │ │ │ │ │ - // to prevent a dblclick from firing the click callback in IE │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleSingle │ │ │ │ │ - * Handle single click sequence. │ │ │ │ │ - */ │ │ │ │ │ - handleSingle: function(evt) { │ │ │ │ │ - if (this.passesTolerance(evt)) { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - // already received a click │ │ │ │ │ - if (this.last.touches && this.last.touches.length === 1) { │ │ │ │ │ - // touch device, no dblclick event - this may be a double │ │ │ │ │ - if (this["double"]) { │ │ │ │ │ - // on Android don't let the browser zoom on the page │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - } │ │ │ │ │ - this.handleDouble(evt); │ │ │ │ │ - } │ │ │ │ │ - // if we're not in a touch environment we clear the click timer │ │ │ │ │ - // if we've got a second touch, we'll get two touchend events │ │ │ │ │ - if (!this.last.touches || this.last.touches.length !== 2) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // remember the first click info so we can compare to the second │ │ │ │ │ - this.first = this.getEventInfo(evt); │ │ │ │ │ - // set the timer, send evt only if single is true │ │ │ │ │ - //use a clone of the event object because it will no longer │ │ │ │ │ - //be a valid event object in IE in the timer callback │ │ │ │ │ - var clickEvent = this.single ? │ │ │ │ │ - OpenLayers.Util.extend({}, evt) : null; │ │ │ │ │ - this.queuePotentialClick(clickEvent); │ │ │ │ │ + // unregister event handlers defined on this class. │ │ │ │ │ + var events = OpenLayers.Events.prototype.BROWSER_EVENTS; │ │ │ │ │ + for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ + if (this[events[i]]) { │ │ │ │ │ + this.unregister(events[i], this[events[i]]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: queuePotentialClick │ │ │ │ │ - * This method is separated out largely to make testing easier (so we │ │ │ │ │ - * don't have to override window.setTimeout) │ │ │ │ │ - */ │ │ │ │ │ - queuePotentialClick: function(evt) { │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ - this.delay │ │ │ │ │ - ); │ │ │ │ │ + this.touch = false; │ │ │ │ │ + this.active = false; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the event is within the optional pixel tolerance. Note │ │ │ │ │ - * that the pixel tolerance check only works if mousedown events get to │ │ │ │ │ - * the listeners registered here. If they are stopped by other elements, │ │ │ │ │ - * the will have no effect here (this method will always │ │ │ │ │ - * return true). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The click is within the pixel tolerance (if specified). │ │ │ │ │ + * Method: startTouch │ │ │ │ │ + * Start touch events, this method must be called by subclasses in │ │ │ │ │ + * "touchstart" method. When touch events are started will be │ │ │ │ │ + * true and all mouse related listeners will do nothing. │ │ │ │ │ */ │ │ │ │ │ - passesTolerance: function(evt) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.pixelTolerance != null && this.down && this.down.xy) { │ │ │ │ │ - passes = this.pixelTolerance >= this.down.xy.distanceTo(evt.xy); │ │ │ │ │ - // for touch environments, we also enforce that all touches │ │ │ │ │ - // start and end within the given tolerance to be considered a click │ │ │ │ │ - if (passes && this.touch && │ │ │ │ │ - this.down.touches.length === this.last.touches.length) { │ │ │ │ │ - // the touchend event doesn't come with touches, so we check │ │ │ │ │ - // down and last │ │ │ │ │ - for (var i = 0, ii = this.down.touches.length; i < ii; ++i) { │ │ │ │ │ - if (this.getTouchDistance( │ │ │ │ │ - this.down.touches[i], │ │ │ │ │ - this.last.touches[i] │ │ │ │ │ - ) > this.pixelTolerance) { │ │ │ │ │ - passes = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + startTouch: function() { │ │ │ │ │ + if (!this.touch) { │ │ │ │ │ + this.touch = true; │ │ │ │ │ + var events = [ │ │ │ │ │ + "mousedown", "mouseup", "mousemove", "click", "dblclick", │ │ │ │ │ + "mouseout" │ │ │ │ │ + ]; │ │ │ │ │ + for (var i = 0, len = events.length; i < len; i++) { │ │ │ │ │ + if (this[events[i]]) { │ │ │ │ │ + this.unregister(events[i], this[events[i]]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getTouchDistance │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The pixel displacement between two touches. │ │ │ │ │ - */ │ │ │ │ │ - getTouchDistance: function(from, to) { │ │ │ │ │ - return Math.sqrt( │ │ │ │ │ - Math.pow(from.clientX - to.clientX, 2) + │ │ │ │ │ - Math.pow(from.clientY - to.clientY, 2) │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesDblclickTolerance │ │ │ │ │ - * Determine whether the event is within the optional double-cick pixel │ │ │ │ │ - * tolerance. │ │ │ │ │ + * Method: callback │ │ │ │ │ + * Trigger the control's named callback with the given arguments │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The click is within the double-click pixel tolerance. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} The key for the callback that is one of the properties │ │ │ │ │ + * of the handler's callbacks object. │ │ │ │ │ + * args - {Array(*)} An array of arguments (any type) with which to call │ │ │ │ │ + * the callback (defined by the control). │ │ │ │ │ */ │ │ │ │ │ - passesDblclickTolerance: function(evt) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.down && this.first) { │ │ │ │ │ - passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ + callback: function(name, args) { │ │ │ │ │ + if (name && this.callbacks[name]) { │ │ │ │ │ + this.callbacks[name].apply(this.control, args); │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: register │ │ │ │ │ + * register an event on the map │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.rightclickTimerId != null) { │ │ │ │ │ - window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - } │ │ │ │ │ + register: function(name, method) { │ │ │ │ │ + // TODO: deal with registerPriority in 3.0 │ │ │ │ │ + this.map.events.registerPriority(name, this, method); │ │ │ │ │ + this.map.events.registerPriority(name, this, this.setEvent); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Sets to null. And optionally triggers the click callback if │ │ │ │ │ - * evt is set. │ │ │ │ │ + * Method: unregister │ │ │ │ │ + * unregister an event from the map │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback("click", [evt]); │ │ │ │ │ - } │ │ │ │ │ + unregister: function(name, method) { │ │ │ │ │ + this.map.events.unregister(name, this, method); │ │ │ │ │ + this.map.events.unregister(name, this, this.setEvent); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getEventInfo │ │ │ │ │ - * This method allows us to store event information without storing the │ │ │ │ │ - * actual event. In touch devices (at least), the same event is │ │ │ │ │ - * modified between touchstart, touchmove, and touchend. │ │ │ │ │ + * Method: setEvent │ │ │ │ │ + * With each registered browser event, the handler sets its own evt │ │ │ │ │ + * property. This property can be accessed by controls if needed │ │ │ │ │ + * to get more information about the event that the handler is │ │ │ │ │ + * processing. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with event related info. │ │ │ │ │ + * This allows modifier keys on the event to be checked (alt, shift, ctrl, │ │ │ │ │ + * and meta cannot be checked with the keyboard handler). For a │ │ │ │ │ + * control to determine which modifier keys are associated with the │ │ │ │ │ + * event that a handler is currently processing, it should access │ │ │ │ │ + * (code)handler.evt.altKey || handler.evt.shiftKey || │ │ │ │ │ + * handler.evt.ctrlKey || handler.evt.metaKey(end). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event. │ │ │ │ │ */ │ │ │ │ │ - getEventInfo: function(evt) { │ │ │ │ │ - var touches; │ │ │ │ │ - if (evt.touches) { │ │ │ │ │ - var len = evt.touches.length; │ │ │ │ │ - touches = new Array(len); │ │ │ │ │ - var touch; │ │ │ │ │ - for (var i = 0; i < len; i++) { │ │ │ │ │ - touch = evt.touches[i]; │ │ │ │ │ - touches[i] = { │ │ │ │ │ - clientX: touch.olClientX, │ │ │ │ │ - clientY: touch.olClientY │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return { │ │ │ │ │ - xy: evt.xy, │ │ │ │ │ - touches: touches │ │ │ │ │ - }; │ │ │ │ │ + setEvent: function(evt) { │ │ │ │ │ + this.evt = evt; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Deconstruct the handler. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.down = null; │ │ │ │ │ - this.first = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // unregister event listeners │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + // eliminate circular references │ │ │ │ │ + this.control = this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_NONE │ │ │ │ │ + * If set as the , returns false if any key is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_NONE = 0; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_SHIFT │ │ │ │ │ + * If set as the , returns false if Shift is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_SHIFT = 1; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_CTRL │ │ │ │ │ + * If set as the , returns false if Ctrl is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_CTRL = 2; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_ALT │ │ │ │ │ + * If set as the , returns false if Alt is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_ALT = 4; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_META │ │ │ │ │ + * If set as the , returns false if Cmd is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_META = 8; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Events/buttonclick.js │ │ │ │ │ + OpenLayers/StyleMap.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.buttonclick │ │ │ │ │ - * Extension event type for handling buttons on top of a dom element. This │ │ │ │ │ - * event type fires "buttonclick" on its when a button was │ │ │ │ │ - * clicked. Buttons are detected by the "olButton" class. │ │ │ │ │ - * │ │ │ │ │ - * This event type makes sure that button clicks do not interfere with other │ │ │ │ │ - * events that are registered on the same . │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - *buttonclick* Triggered when a button is clicked. Listeners receive an │ │ │ │ │ - * object with a *buttonElement* property referencing the dom element of │ │ │ │ │ - * the clicked button, and an *buttonXY* property with the click position │ │ │ │ │ - * relative to the button. │ │ │ │ │ + * Class: OpenLayers.StyleMap │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.buttonclick = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: target │ │ │ │ │ - * {} The events instance that the buttonclick event will │ │ │ │ │ - * be triggered on. │ │ │ │ │ - */ │ │ │ │ │ - target: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {Array} Events to observe and conditionally stop from propagating when │ │ │ │ │ - * an element with the olButton class (or its olAlphaImg child) is │ │ │ │ │ - * clicked. │ │ │ │ │ - */ │ │ │ │ │ - events: [ │ │ │ │ │ - 'mousedown', 'mouseup', 'click', 'dblclick', │ │ │ │ │ - 'touchstart', 'touchmove', 'touchend', 'keydown' │ │ │ │ │ - ], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: startRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that start │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ - */ │ │ │ │ │ - startRegEx: /^mousedown|touchstart$/, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: cancelRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that cancel │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ - */ │ │ │ │ │ - cancelRegEx: /^touchmove$/, │ │ │ │ │ +OpenLayers.StyleMap = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: completeRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that complete │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * Property: styles │ │ │ │ │ + * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ + * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ */ │ │ │ │ │ - completeRegEx: /^mouseup|touchend$/, │ │ │ │ │ + styles: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startEvt │ │ │ │ │ - * {Event} The event that started the click sequence │ │ │ │ │ + * Property: extendDefault │ │ │ │ │ + * {Boolean} if true, every render intent will extend the symbolizers │ │ │ │ │ + * specified for the "default" intent at rendering time. Otherwise, every │ │ │ │ │ + * rendering intent will be treated as a completely independent style. │ │ │ │ │ */ │ │ │ │ │ + extendDefault: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Events.buttonclick │ │ │ │ │ - * Construct a buttonclick event type. Applications are not supposed to │ │ │ │ │ - * create instances of this class - they are created on demand by │ │ │ │ │ - * instances. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.StyleMap │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * target - {} The events instance that the buttonclick │ │ │ │ │ - * event will be triggered on. │ │ │ │ │ + * style - {Object} Optional. Either a style hash, or a style object, or │ │ │ │ │ + * a hash of style objects (style hashes) keyed by rendering │ │ │ │ │ + * intent. If just one style hash or style object is passed, │ │ │ │ │ + * this will be used for all known render intents (default, │ │ │ │ │ + * select, temporary) │ │ │ │ │ + * options - {Object} optional hash of additional options for this │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - initialize: function(target) { │ │ │ │ │ - this.target = target; │ │ │ │ │ - for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ - this.target.register(this.events[i], this, this.buttonClick, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(style, options) { │ │ │ │ │ + this.styles = { │ │ │ │ │ + "default": new OpenLayers.Style( │ │ │ │ │ + OpenLayers.Feature.Vector.style["default"]), │ │ │ │ │ + "select": new OpenLayers.Style( │ │ │ │ │ + OpenLayers.Feature.Vector.style["select"]), │ │ │ │ │ + "temporary": new OpenLayers.Style( │ │ │ │ │ + OpenLayers.Feature.Vector.style["temporary"]), │ │ │ │ │ + "delete": new OpenLayers.Style( │ │ │ │ │ + OpenLayers.Feature.Vector.style["delete"]) │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // take whatever the user passed as style parameter and convert it │ │ │ │ │ + // into parts of stylemap. │ │ │ │ │ + if (style instanceof OpenLayers.Style) { │ │ │ │ │ + // user passed a style object │ │ │ │ │ + this.styles["default"] = style; │ │ │ │ │ + this.styles["select"] = style; │ │ │ │ │ + this.styles["temporary"] = style; │ │ │ │ │ + this.styles["delete"] = style; │ │ │ │ │ + } else if (typeof style == "object") { │ │ │ │ │ + for (var key in style) { │ │ │ │ │ + if (style[key] instanceof OpenLayers.Style) { │ │ │ │ │ + // user passed a hash of style objects │ │ │ │ │ + this.styles[key] = style[key]; │ │ │ │ │ + } else if (typeof style[key] == "object") { │ │ │ │ │ + // user passsed a hash of style hashes │ │ │ │ │ + this.styles[key] = new OpenLayers.Style(style[key]); │ │ │ │ │ + } else { │ │ │ │ │ + // user passed a style hash (i.e. symbolizer) │ │ │ │ │ + this.styles["default"] = new OpenLayers.Style(style); │ │ │ │ │ + this.styles["select"] = new OpenLayers.Style(style); │ │ │ │ │ + this.styles["temporary"] = new OpenLayers.Style(style); │ │ │ │ │ + this.styles["delete"] = new OpenLayers.Style(style); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ - this.target.unregister(this.events[i], this, this.buttonClick); │ │ │ │ │ + for (var key in this.styles) { │ │ │ │ │ + this.styles[key].destroy(); │ │ │ │ │ } │ │ │ │ │ - delete this.target; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getPressedButton │ │ │ │ │ - * Get the pressed button, if any. Returns undefined if no button │ │ │ │ │ - * was pressed. │ │ │ │ │ - * │ │ │ │ │ - * Arguments: │ │ │ │ │ - * element - {DOMElement} The event target. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The button element, or undefined. │ │ │ │ │ - */ │ │ │ │ │ - getPressedButton: function(element) { │ │ │ │ │ - var depth = 3, // limit the search depth │ │ │ │ │ - button; │ │ │ │ │ - do { │ │ │ │ │ - if (OpenLayers.Element.hasClass(element, "olButton")) { │ │ │ │ │ - // hit! │ │ │ │ │ - button = element; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - element = element.parentNode; │ │ │ │ │ - } while (--depth > 0 && element); │ │ │ │ │ - return button; │ │ │ │ │ + this.styles = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: ignore │ │ │ │ │ - * Check for event target elements that should be ignored by OpenLayers. │ │ │ │ │ - * │ │ │ │ │ + * Method: createSymbolizer │ │ │ │ │ + * Creates the symbolizer for a feature for a render intent. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} The event target. │ │ │ │ │ + * feature - {} The feature to evaluate the rules │ │ │ │ │ + * of the intended style against. │ │ │ │ │ + * intent - {String} The intent determines the symbolizer that will be │ │ │ │ │ + * used to draw the feature. Well known intents are "default" │ │ │ │ │ + * (for just drawing the features), "select" (for selected │ │ │ │ │ + * features) and "temporary" (for drawing features). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} symbolizer hash │ │ │ │ │ */ │ │ │ │ │ - ignore: function(element) { │ │ │ │ │ - var depth = 3, │ │ │ │ │ - ignore = false; │ │ │ │ │ - do { │ │ │ │ │ - if (element.nodeName.toLowerCase() === 'a') { │ │ │ │ │ - ignore = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - element = element.parentNode; │ │ │ │ │ - } while (--depth > 0 && element); │ │ │ │ │ - return ignore; │ │ │ │ │ + createSymbolizer: function(feature, intent) { │ │ │ │ │ + if (!feature) { │ │ │ │ │ + feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ + } │ │ │ │ │ + if (!this.styles[intent]) { │ │ │ │ │ + intent = "default"; │ │ │ │ │ + } │ │ │ │ │ + feature.renderIntent = intent; │ │ │ │ │ + var defaultSymbolizer = {}; │ │ │ │ │ + if (this.extendDefault && intent != "default") { │ │ │ │ │ + defaultSymbolizer = this.styles["default"].createSymbolizer(feature); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Util.extend(defaultSymbolizer, │ │ │ │ │ + this.styles[intent].createSymbolizer(feature)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buttonClick │ │ │ │ │ - * Check if a button was clicked, and fire the buttonclick event │ │ │ │ │ - * │ │ │ │ │ + * Method: addUniqueValueRules │ │ │ │ │ + * Convenience method to create comparison rules for unique values of a │ │ │ │ │ + * property. The rules will be added to the style object for a specified │ │ │ │ │ + * rendering intent. This method is a shortcut for creating something like │ │ │ │ │ + * the "unique value legends" familiar from well known desktop GIS systems │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * renderIntent - {String} rendering intent to add the rules to │ │ │ │ │ + * property - {String} values of feature attributes to create the │ │ │ │ │ + * rules for │ │ │ │ │ + * symbolizers - {Object} Hash of symbolizers, keyed by the desired │ │ │ │ │ + * property values │ │ │ │ │ + * context - {Object} An optional object with properties that │ │ │ │ │ + * symbolizers' property values should be evaluated │ │ │ │ │ + * against. If no context is specified, feature.attributes │ │ │ │ │ + * will be used │ │ │ │ │ */ │ │ │ │ │ - buttonClick: function(evt) { │ │ │ │ │ - var propagate = true, │ │ │ │ │ - element = OpenLayers.Event.element(evt); │ │ │ │ │ - if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) { │ │ │ │ │ - // was a button pressed? │ │ │ │ │ - var button = this.getPressedButton(element); │ │ │ │ │ - if (button) { │ │ │ │ │ - if (evt.type === "keydown") { │ │ │ │ │ - switch (evt.keyCode) { │ │ │ │ │ - case OpenLayers.Event.KEY_RETURN: │ │ │ │ │ - case OpenLayers.Event.KEY_SPACE: │ │ │ │ │ - this.target.triggerEvent("buttonclick", { │ │ │ │ │ - buttonElement: button │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (this.startEvt) { │ │ │ │ │ - if (this.completeRegEx.test(evt.type)) { │ │ │ │ │ - var pos = OpenLayers.Util.pagePosition(button); │ │ │ │ │ - var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ - var scrollTop = window.pageYOffset || viewportElement.scrollTop; │ │ │ │ │ - var scrollLeft = window.pageXOffset || viewportElement.scrollLeft; │ │ │ │ │ - pos[0] = pos[0] - scrollLeft; │ │ │ │ │ - pos[1] = pos[1] - scrollTop; │ │ │ │ │ - │ │ │ │ │ - this.target.triggerEvent("buttonclick", { │ │ │ │ │ - buttonElement: button, │ │ │ │ │ - buttonXY: { │ │ │ │ │ - x: this.startEvt.clientX - pos[0], │ │ │ │ │ - y: this.startEvt.clientY - pos[1] │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (this.cancelRegEx.test(evt.type)) { │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ - } │ │ │ │ │ - if (this.startRegEx.test(evt.type)) { │ │ │ │ │ - this.startEvt = evt; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - propagate = !this.ignore(OpenLayers.Event.element(evt)); │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - } │ │ │ │ │ + addUniqueValueRules: function(renderIntent, property, symbolizers, context) { │ │ │ │ │ + var rules = []; │ │ │ │ │ + for (var value in symbolizers) { │ │ │ │ │ + rules.push(new OpenLayers.Rule({ │ │ │ │ │ + symbolizer: symbolizers[value], │ │ │ │ │ + context: context, │ │ │ │ │ + filter: new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.EQUAL_TO, │ │ │ │ │ + property: property, │ │ │ │ │ + value: value │ │ │ │ │ + }) │ │ │ │ │ + })); │ │ │ │ │ } │ │ │ │ │ - return propagate; │ │ │ │ │ - } │ │ │ │ │ + this.styles[renderIntent].addRules(rules); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Events/featureclick.js │ │ │ │ │ + OpenLayers/Control.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.featureclick │ │ │ │ │ + * Class: OpenLayers.Control │ │ │ │ │ + * Controls affect the display or behavior of the map. They allow everything │ │ │ │ │ + * from panning and zooming to displaying a scale indicator. Controls by │ │ │ │ │ + * default are added to the map they are contained within however it is │ │ │ │ │ + * possible to add a control to an external div by passing the div in the │ │ │ │ │ + * options parameter. │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * The following example shows how to add many of the common controls │ │ │ │ │ + * to a map. │ │ │ │ │ + * │ │ │ │ │ + * > var map = new OpenLayers.Map('map', { controls: [] }); │ │ │ │ │ + * > │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.PanZoomBar()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.Permalink()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.Permalink('permalink')); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.MousePosition()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.OverviewMap()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.KeyboardDefaults()); │ │ │ │ │ * │ │ │ │ │ - * Extension event type for handling feature click events, including overlapping │ │ │ │ │ - * features. │ │ │ │ │ + * The next code fragment is a quick example of how to intercept │ │ │ │ │ + * shift-mouse click to display the extent of the bounding box │ │ │ │ │ + * dragged out by the user. Usually controls are not created │ │ │ │ │ + * in exactly this manner. See the source for a more complete │ │ │ │ │ + * example: │ │ │ │ │ + * │ │ │ │ │ + * > var control = new OpenLayers.Control(); │ │ │ │ │ + * > OpenLayers.Util.extend(control, { │ │ │ │ │ + * > draw: function () { │ │ │ │ │ + * > // this Handler.Box will intercept the shift-mousedown │ │ │ │ │ + * > // before Control.MouseDefault gets to see it │ │ │ │ │ + * > this.box = new OpenLayers.Handler.Box( control, │ │ │ │ │ + * > {"done": this.notice}, │ │ │ │ │ + * > {keyMask: OpenLayers.Handler.MOD_SHIFT}); │ │ │ │ │ + * > this.box.activate(); │ │ │ │ │ + * > }, │ │ │ │ │ + * > │ │ │ │ │ + * > notice: function (bounds) { │ │ │ │ │ + * > OpenLayers.Console.userError(bounds); │ │ │ │ │ + * > } │ │ │ │ │ + * > }); │ │ │ │ │ + * > map.addControl(control); │ │ │ │ │ * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - featureclick │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.featureclick = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Control = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: cache │ │ │ │ │ - * {Object} A cache of features under the mouse. │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - cache: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} The map to register browser events on. │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} this gets set in the addControl() function in │ │ │ │ │ + * OpenLayers.Map │ │ │ │ │ */ │ │ │ │ │ map: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: provides │ │ │ │ │ - * {Array(String)} The event types provided by this extension. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} The element that contains the control, if not present the │ │ │ │ │ + * control is placed inside the map. │ │ │ │ │ */ │ │ │ │ │ - provides: ["featureclick", "nofeatureclick", "featureover", "featureout"], │ │ │ │ │ + div: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: type │ │ │ │ │ + * {Number} Controls can have a 'type'. The type determines the type of │ │ │ │ │ + * interactions which are possible with them when they are placed in an │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + type: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: allowSelection │ │ │ │ │ + * {Boolean} By default, controls do not allow selection, because │ │ │ │ │ + * it may interfere with map dragging. If this is true, OpenLayers │ │ │ │ │ + * will not prevent selection of the control. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + allowSelection: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: displayClass │ │ │ │ │ + * {string} This property is used for CSS related to the drawing of the │ │ │ │ │ + * Control. │ │ │ │ │ + */ │ │ │ │ │ + displayClass: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Events.featureclick │ │ │ │ │ - * Create a new featureclick event type. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {} The events instance to create the events │ │ │ │ │ - * for. │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {string} This property is used for showing a tooltip over the │ │ │ │ │ + * Control. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(target) { │ │ │ │ │ - this.target = target; │ │ │ │ │ - if (target.object instanceof OpenLayers.Map) { │ │ │ │ │ - this.setMap(target.object); │ │ │ │ │ - } else if (target.object instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ - if (target.object.map) { │ │ │ │ │ - this.setMap(target.object.map); │ │ │ │ │ - } else { │ │ │ │ │ - target.object.events.register("added", this, function(evt) { │ │ │ │ │ - this.setMap(target.object.map); │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - throw ("Listeners for '" + this.provides.join("', '") + │ │ │ │ │ - "' events can only be registered for OpenLayers.Layer.Vector " + │ │ │ │ │ - "or OpenLayers.Map instances"); │ │ │ │ │ - } │ │ │ │ │ - for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ - target.extensions[this.provides[i]] = true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + title: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map to register browser events on. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - this.cache = {}; │ │ │ │ │ - map.events.register("mousedown", this, this.start, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - map.events.register("mouseup", this, this.onClick, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - map.events.register("touchstart", this, this.start, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - map.events.register("touchmove", this, this.cancel, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - map.events.register("touchend", this, this.onClick, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - map.events.register("mousemove", this, this.onMousemove, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + autoActivate: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: active │ │ │ │ │ + * {Boolean} The control is active (read-only). Use and │ │ │ │ │ + * to change control state. │ │ │ │ │ + */ │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: start │ │ │ │ │ - * Sets startEvt = evt. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Property: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - start: function(evt) { │ │ │ │ │ - this.startEvt = evt; │ │ │ │ │ - }, │ │ │ │ │ + handlerOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancel │ │ │ │ │ - * Deletes the start event. │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ + */ │ │ │ │ │ + eventListeners: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to control.events.object (a reference │ │ │ │ │ + * to the control). │ │ │ │ │ + * element - {DOMElement} A reference to control.events.element (which │ │ │ │ │ + * will be null unless documented otherwise). │ │ │ │ │ + * │ │ │ │ │ + * Supported map event types: │ │ │ │ │ + * activate - Triggered when activated. │ │ │ │ │ + * deactivate - Triggered when deactivated. │ │ │ │ │ */ │ │ │ │ │ - cancel: function(evt) { │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - }, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onClick │ │ │ │ │ - * Listener for the click event. │ │ │ │ │ + * Constructor: OpenLayers.Control │ │ │ │ │ + * Create an OpenLayers Control. The options passed as a parameter │ │ │ │ │ + * directly extend the control. For example passing the following: │ │ │ │ │ + * │ │ │ │ │ + * > var control = new OpenLayers.Control({div: myDiv}); │ │ │ │ │ * │ │ │ │ │ + * Overrides the default div attribute value of null. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - onClick: function(evt) { │ │ │ │ │ - if (!this.startEvt || evt.type !== "touchend" && │ │ │ │ │ - !OpenLayers.Event.isLeftClick(evt)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var features = this.getFeatures(this.startEvt); │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - // fire featureclick events │ │ │ │ │ - var feature, layer, more, clicked = {}; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - layer = feature.layer; │ │ │ │ │ - clicked[layer.id] = true; │ │ │ │ │ - more = this.triggerEvent("featureclick", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (more === false) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + // We do this before the extend so that instances can override │ │ │ │ │ + // className in options. │ │ │ │ │ + this.displayClass = │ │ │ │ │ + this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, ""); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ - // fire nofeatureclick events on all vector layers with no targets │ │ │ │ │ - for (i = 0, len = this.map.layers.length; i < len; ++i) { │ │ │ │ │ - layer = this.map.layers[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Vector && !clicked[layer.id]) { │ │ │ │ │ - this.triggerEvent("nofeatureclick", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMousemove │ │ │ │ │ - * Listener for the mousemove event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * The destroy method is used to perform any clean up before the control │ │ │ │ │ + * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ + * to prevent memory leaks. │ │ │ │ │ */ │ │ │ │ │ - onMousemove: function(evt) { │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - var features = this.getFeatures(evt); │ │ │ │ │ - var over = {}, │ │ │ │ │ - newly = [], │ │ │ │ │ - feature; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - over[feature.id] = feature; │ │ │ │ │ - if (!this.cache[feature.id]) { │ │ │ │ │ - newly.push(feature); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ } │ │ │ │ │ - // check if already over features │ │ │ │ │ - var out = []; │ │ │ │ │ - for (var id in this.cache) { │ │ │ │ │ - feature = this.cache[id]; │ │ │ │ │ - if (feature.layer && feature.layer.map) { │ │ │ │ │ - if (!over[feature.id]) { │ │ │ │ │ - out.push(feature); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + │ │ │ │ │ + // eliminate circular references │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.destroy(); │ │ │ │ │ + this.handler = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.handlers) { │ │ │ │ │ + for (var key in this.handlers) { │ │ │ │ │ + if (this.handlers.hasOwnProperty(key) && │ │ │ │ │ + typeof this.handlers[key].destroy == "function") { │ │ │ │ │ + this.handlers[key].destroy(); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - // removed │ │ │ │ │ - delete this.cache[id]; │ │ │ │ │ } │ │ │ │ │ + this.handlers = null; │ │ │ │ │ } │ │ │ │ │ - // fire featureover events │ │ │ │ │ - var more; │ │ │ │ │ - for (i = 0, len = newly.length; i < len; ++i) { │ │ │ │ │ - feature = newly[i]; │ │ │ │ │ - this.cache[feature.id] = feature; │ │ │ │ │ - more = this.triggerEvent("featureover", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (more === false) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.removeControl(this); │ │ │ │ │ + this.map = null; │ │ │ │ │ } │ │ │ │ │ - // fire featureout events │ │ │ │ │ - for (i = 0, len = out.length; i < len; ++i) { │ │ │ │ │ - feature = out[i]; │ │ │ │ │ - delete this.cache[feature.id]; │ │ │ │ │ - more = this.triggerEvent("featureout", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (more === false) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + this.div = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. This is done through an accessor │ │ │ │ │ + * so that subclasses can override this and take special action once │ │ │ │ │ + * they have their map variable set. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.setMap(map); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: triggerEvent │ │ │ │ │ - * Determines where to trigger the event and triggers it. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * The draw method is called when the control is ready to be displayed │ │ │ │ │ + * on the page. If a div has not been created one is created. Controls │ │ │ │ │ + * with a visual component will almost always want to override this method │ │ │ │ │ + * to customize the look of control. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} The event type to trigger │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * px - {} The top-left pixel position of the control │ │ │ │ │ + * or null. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The last listener return. │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ */ │ │ │ │ │ - triggerEvent: function(type, evt) { │ │ │ │ │ - var layer = evt.feature ? evt.feature.layer : evt.layer, │ │ │ │ │ - object = this.target.object; │ │ │ │ │ - if (object instanceof OpenLayers.Map || object === layer) { │ │ │ │ │ - return this.target.triggerEvent(type, evt); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + if (this.div == null) { │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.className = this.displayClass; │ │ │ │ │ + if (!this.allowSelection) { │ │ │ │ │ + this.div.className += " olControlNoSelect"; │ │ │ │ │ + this.div.setAttribute("unselectable", "on", 0); │ │ │ │ │ + this.div.onselectstart = OpenLayers.Function.False; │ │ │ │ │ + } │ │ │ │ │ + if (this.title != "") { │ │ │ │ │ + this.div.title = this.title; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.position = px.clone(); │ │ │ │ │ } │ │ │ │ │ + this.moveTo(this.position); │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatures │ │ │ │ │ - * Get all features at the given screen location. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ + * coordinates. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Event object. │ │ │ │ │ - * │ │ │ │ │ + * px - {} │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.div != null)) { │ │ │ │ │ + this.div.style.left = px.x + "px"; │ │ │ │ │ + this.div.style.top = px.y + "px"; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Explicitly activates a control and it's associated │ │ │ │ │ + * handler if one has been set. Controls can be │ │ │ │ │ + * deactivated by calling the deactivate() method. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} List of features at the given point. │ │ │ │ │ + * {Boolean} True if the control was successfully activated or │ │ │ │ │ + * false if the control was already active. │ │ │ │ │ */ │ │ │ │ │ - getFeatures: function(evt) { │ │ │ │ │ - var x = evt.clientX, │ │ │ │ │ - y = evt.clientY, │ │ │ │ │ - features = [], │ │ │ │ │ - targets = [], │ │ │ │ │ - layers = [], │ │ │ │ │ - layer, target, feature, i, len; │ │ │ │ │ - // go through all layers looking for targets │ │ │ │ │ - for (i = this.map.layers.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = this.map.layers[i]; │ │ │ │ │ - if (layer.div.style.display !== "none") { │ │ │ │ │ - if (layer.renderer instanceof OpenLayers.Renderer.Elements) { │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ - target = document.elementFromPoint(x, y); │ │ │ │ │ - while (target && target._featureId) { │ │ │ │ │ - feature = layer.getFeatureById(target._featureId); │ │ │ │ │ - if (feature) { │ │ │ │ │ - features.push(feature); │ │ │ │ │ - target.style.display = "none"; │ │ │ │ │ - targets.push(target); │ │ │ │ │ - target = document.elementFromPoint(x, y); │ │ │ │ │ - } else { │ │ │ │ │ - // sketch, all bets off │ │ │ │ │ - target = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - layer.div.style.display = "none"; │ │ │ │ │ - } else if (layer.renderer instanceof OpenLayers.Renderer.Canvas) { │ │ │ │ │ - feature = layer.renderer.getFeatureIdFromEvent(evt); │ │ │ │ │ - if (feature) { │ │ │ │ │ - features.push(feature); │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - // restore feature visibility │ │ │ │ │ - for (i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ - targets[i].style.display = ""; │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.activate(); │ │ │ │ │ } │ │ │ │ │ - // restore layer visibility │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - layers[i].div.style.display = "block"; │ │ │ │ │ + this.active = true; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + OpenLayers.Element.addClass( │ │ │ │ │ + this.map.viewPortDiv, │ │ │ │ │ + this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return features; │ │ │ │ │ + this.events.triggerEvent("activate"); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivates a control and it's associated handler if any. The exact │ │ │ │ │ + * effect of this depends on the control itself. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the control was effectively deactivated or false │ │ │ │ │ + * if the control was already inactive. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ - delete this.target.extensions[this.provides[i]]; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + this.active = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, │ │ │ │ │ + this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("deactivate"); │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - mousemove: this.onMousemove, │ │ │ │ │ - mousedown: this.start, │ │ │ │ │ - mouseup: this.onClick, │ │ │ │ │ - touchstart: this.start, │ │ │ │ │ - touchmove: this.cancel, │ │ │ │ │ - touchend: this.onClick, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - delete this.cache; │ │ │ │ │ - delete this.map; │ │ │ │ │ - delete this.target; │ │ │ │ │ - } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.nofeatureclick │ │ │ │ │ - * │ │ │ │ │ - * Extension event type for handling click events that do not hit a feature. │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - nofeatureclick │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_BUTTON │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.nofeatureclick = OpenLayers.Events.featureclick; │ │ │ │ │ +OpenLayers.Control.TYPE_BUTTON = 1; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.featureover │ │ │ │ │ - * │ │ │ │ │ - * Extension event type for handling hovering over a feature. │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - featureover │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_TOGGLE │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.featureover = OpenLayers.Events.featureclick; │ │ │ │ │ +OpenLayers.Control.TYPE_TOGGLE = 2; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.featureout │ │ │ │ │ - * │ │ │ │ │ - * Extension event type for handling leaving a feature. │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - featureout │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_TOOL │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.featureout = OpenLayers.Events.featureclick; │ │ │ │ │ +OpenLayers.Control.TYPE_TOOL = 3; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/WMTS.js │ │ │ │ │ + OpenLayers/Popup.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.WMTS │ │ │ │ │ - * Instances of the WMTS class allow viewing of tiles from a service that │ │ │ │ │ - * implements the OGC WMTS specification version 1.0.0. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Popup │ │ │ │ │ + * A popup is a small div that can opened and closed on the map. │ │ │ │ │ + * Typically opened in response to clicking on a marker. │ │ │ │ │ + * See . Popup's don't require their own │ │ │ │ │ + * layer and are added the the map using the │ │ │ │ │ + * method. │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * popup = new OpenLayers.Popup("chicken", │ │ │ │ │ + * new OpenLayers.LonLat(5,40), │ │ │ │ │ + * new OpenLayers.Size(200,200), │ │ │ │ │ + * "example popup", │ │ │ │ │ + * true); │ │ │ │ │ + * │ │ │ │ │ + * map.addPopup(popup); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Popup = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer will be considered a base layer. Default is true. │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} custom event manager │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} WMTS version. Default is "1.0.0". │ │ │ │ │ + /** Property: id │ │ │ │ │ + * {String} the unique identifier assigned to this popup. │ │ │ │ │ */ │ │ │ │ │ - version: "1.0.0", │ │ │ │ │ + id: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: requestEncoding │ │ │ │ │ - * {String} Request encoding. Can be "REST" or "KVP". Default is "KVP". │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} the position of this popup on the map │ │ │ │ │ */ │ │ │ │ │ - requestEncoding: "KVP", │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String|Array(String)} The base URL or request URL template for the WMTS │ │ │ │ │ - * service. Must be provided. Array is only supported for base URLs, not │ │ │ │ │ - * for request URL templates. URL templates are only supported for │ │ │ │ │ - * REST . │ │ │ │ │ + /** │ │ │ │ │ + * Property: div │ │ │ │ │ + * {DOMElement} the div that contains this popup. │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layer │ │ │ │ │ - * {String} The layer identifier advertised by the WMTS service. Must be │ │ │ │ │ - * provided. │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentSize │ │ │ │ │ + * {} the width and height of the content. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + contentSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: matrixSet │ │ │ │ │ - * {String} One of the advertised matrix set identifiers. Must be provided. │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} the width and height of the popup. │ │ │ │ │ */ │ │ │ │ │ - matrixSet: null, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {String} One of the advertised layer styles. Must be provided. │ │ │ │ │ + * Property: contentHTML │ │ │ │ │ + * {String} An HTML string for this popup to display. │ │ │ │ │ */ │ │ │ │ │ - style: null, │ │ │ │ │ + contentHTML: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {String} The image MIME type. Default is "image/jpeg". │ │ │ │ │ + * Property: backgroundColor │ │ │ │ │ + * {String} the background color used by the popup. │ │ │ │ │ */ │ │ │ │ │ - format: "image/jpeg", │ │ │ │ │ + backgroundColor: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileOrigin │ │ │ │ │ - * {} The top-left corner of the tile matrix in map │ │ │ │ │ - * units. If the tile origin for each matrix in a set is different, │ │ │ │ │ - * the should include a topLeftCorner property. If │ │ │ │ │ - * not provided, the tile origin will default to the top left corner │ │ │ │ │ - * of the layer . │ │ │ │ │ + /** │ │ │ │ │ + * Property: opacity │ │ │ │ │ + * {float} the opacity of this popup (between 0.0 and 1.0) │ │ │ │ │ */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ + opacity: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileFullExtent │ │ │ │ │ - * {} The full extent of the tile set. If not supplied, │ │ │ │ │ - * the layer's property will be used. │ │ │ │ │ + /** │ │ │ │ │ + * Property: border │ │ │ │ │ + * {String} the border size of the popup. (eg 2px) │ │ │ │ │ */ │ │ │ │ │ - tileFullExtent: null, │ │ │ │ │ + border: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: formatSuffix │ │ │ │ │ - * {String} For REST request encoding, an image format suffix must be │ │ │ │ │ - * included in the request. If not provided, the suffix will be derived │ │ │ │ │ - * from the property. │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentDiv │ │ │ │ │ + * {DOMElement} a reference to the element that holds the content of │ │ │ │ │ + * the div. │ │ │ │ │ */ │ │ │ │ │ - formatSuffix: null, │ │ │ │ │ + contentDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: matrixIds │ │ │ │ │ - * {Array} A list of tile matrix identifiers. If not provided, the matrix │ │ │ │ │ - * identifiers will be assumed to be integers corresponding to the │ │ │ │ │ - * map zoom level. If a list of strings is provided, each item should │ │ │ │ │ - * be the matrix identifier that corresponds to the map zoom level. │ │ │ │ │ - * Additionally, a list of objects can be provided. Each object should │ │ │ │ │ - * describe the matrix as presented in the WMTS capabilities. These │ │ │ │ │ - * objects should have the propertes shown below. │ │ │ │ │ - * │ │ │ │ │ - * Matrix properties: │ │ │ │ │ - * identifier - {String} The matrix identifier (required). │ │ │ │ │ - * scaleDenominator - {Number} The matrix scale denominator. │ │ │ │ │ - * topLeftCorner - {} The top left corner of the │ │ │ │ │ - * matrix. Must be provided if different than the layer . │ │ │ │ │ - * tileWidth - {Number} The tile width for the matrix. Must be provided │ │ │ │ │ - * if different than the width given in the layer . │ │ │ │ │ - * tileHeight - {Number} The tile height for the matrix. Must be provided │ │ │ │ │ - * if different than the height given in the layer . │ │ │ │ │ + /** │ │ │ │ │ + * Property: groupDiv │ │ │ │ │ + * {DOMElement} First and only child of 'div'. The group Div contains the │ │ │ │ │ + * 'contentDiv' and the 'closeDiv'. │ │ │ │ │ */ │ │ │ │ │ - matrixIds: null, │ │ │ │ │ + groupDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: dimensions │ │ │ │ │ - * {Array} For RESTful request encoding, extra dimensions may be specified. │ │ │ │ │ - * Items in this list should be property names in the object. │ │ │ │ │ - * Values of extra dimensions will be determined from the corresponding │ │ │ │ │ - * values in the object. │ │ │ │ │ + /** │ │ │ │ │ + * Property: closeDiv │ │ │ │ │ + * {DOMElement} the optional closer image │ │ │ │ │ */ │ │ │ │ │ - dimensions: null, │ │ │ │ │ + closeDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: params │ │ │ │ │ - * {Object} Extra parameters to include in tile requests. For KVP │ │ │ │ │ - * , these properties will be encoded in the request │ │ │ │ │ - * query string. For REST , these properties will │ │ │ │ │ - * become part of the request path, with order determined by the │ │ │ │ │ - * list. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: autoSize │ │ │ │ │ + * {Boolean} Resize the popup to auto-fit the contents. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + autoSize: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOffset │ │ │ │ │ - * {Number} If your cache has more levels than you want to provide │ │ │ │ │ - * access to with this layer, supply a zoomOffset. This zoom offset │ │ │ │ │ - * is added to the current map zoom level to determine the level │ │ │ │ │ - * for a requested tile. For example, if you supply a zoomOffset │ │ │ │ │ - * of 3, when the map is at the zoom 0, tiles will be requested from │ │ │ │ │ - * level 3 of your cache. Default is 0 (assumes cache level and map │ │ │ │ │ - * zoom are equivalent). Additionally, if this layer is to be used │ │ │ │ │ - * as an overlay and the cache has fewer zoom levels than the base │ │ │ │ │ - * layer, you can supply a negative zoomOffset. For example, if a │ │ │ │ │ - * map zoom level of 1 corresponds to your cache level zero, you would │ │ │ │ │ - * supply a -1 zoomOffset (and set the maxResolution of the layer │ │ │ │ │ - * appropriately). The zoomOffset value has no effect if complete │ │ │ │ │ - * matrix definitions (including scaleDenominator) are supplied in │ │ │ │ │ - * the property. Defaults to 0 (no zoom offset). │ │ │ │ │ + * APIProperty: minSize │ │ │ │ │ + * {} Minimum size allowed for the popup's contents. │ │ │ │ │ */ │ │ │ │ │ - zoomOffset: 0, │ │ │ │ │ + minSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: serverResolutions │ │ │ │ │ - * {Array} A list of all resolutions available on the server. Only set this │ │ │ │ │ - * property if the map resolutions differ from the server. This │ │ │ │ │ - * property serves two purposes. (a) can include │ │ │ │ │ - * resolutions that the server supports and that you don't want to │ │ │ │ │ - * provide with this layer; you can also look at , which is │ │ │ │ │ - * an alternative to for that specific purpose. │ │ │ │ │ - * (b) The map can work with resolutions that aren't supported by │ │ │ │ │ - * the server, i.e. that aren't in . When the │ │ │ │ │ - * map is displayed in such a resolution data for the closest │ │ │ │ │ - * server-supported resolution is loaded and the layer div is │ │ │ │ │ - * stretched as necessary. │ │ │ │ │ + * APIProperty: maxSize │ │ │ │ │ + * {} Maximum size allowed for the popup's contents. │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + maxSize: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: formatSuffixMap │ │ │ │ │ - * {Object} a map between WMTS 'format' request parameter and tile image file suffix │ │ │ │ │ + /** │ │ │ │ │ + * Property: displayClass │ │ │ │ │ + * {String} The CSS class of the popup. │ │ │ │ │ */ │ │ │ │ │ - formatSuffixMap: { │ │ │ │ │ - "image/png": "png", │ │ │ │ │ - "image/png8": "png", │ │ │ │ │ - "image/png24": "png", │ │ │ │ │ - "image/png32": "png", │ │ │ │ │ - "png": "png", │ │ │ │ │ - "image/jpeg": "jpg", │ │ │ │ │ - "image/jpg": "jpg", │ │ │ │ │ - "jpeg": "jpg", │ │ │ │ │ - "jpg": "jpg" │ │ │ │ │ - }, │ │ │ │ │ + displayClass: "olPopup", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: matrix │ │ │ │ │ - * {Object} Matrix definition for the current map resolution. Updated by │ │ │ │ │ - * the method. │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentDisplayClass │ │ │ │ │ + * {String} The CSS class of the popup content div. │ │ │ │ │ */ │ │ │ │ │ - matrix: null, │ │ │ │ │ + contentDisplayClass: "olPopupContent", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.WMTS │ │ │ │ │ - * Create a new WMTS layer. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var wmts = new OpenLayers.Layer.WMTS({ │ │ │ │ │ - * name: "My WMTS Layer", │ │ │ │ │ - * url: "http://example.com/wmts", │ │ │ │ │ - * layer: "layer_id", │ │ │ │ │ - * style: "default", │ │ │ │ │ - * matrixSet: "matrix_id" │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Configuration properties for the layer. │ │ │ │ │ - * │ │ │ │ │ - * Required configuration properties: │ │ │ │ │ - * url - {String} The base url for the service. See the property. │ │ │ │ │ - * layer - {String} The layer identifier. See the property. │ │ │ │ │ - * style - {String} The layer style identifier. See the