--- /srv/reproducible-results/rbuild-debian/r-b-build.WFi1oveG/b1/openlayers_2.13.1+ds2-11_armhf.changes +++ /srv/reproducible-results/rbuild-debian/r-b-build.WFi1oveG/b2/openlayers_2.13.1+ds2-11_armhf.changes ├── Files │ @@ -1,2 +1,2 @@ │ │ - 89c9f630ac374cee7a597165edaad466 730180 javascript optional libjs-openlayers_2.13.1+ds2-11_all.deb │ + 900775a3f4c9cba8e59249a737338a58 717832 javascript optional libjs-openlayers_2.13.1+ds2-11_all.deb ├── libjs-openlayers_2.13.1+ds2-11_all.deb │ ├── file list │ │ @@ -1,3 +1,3 @@ │ │ -rw-r--r-- 0 0 0 4 2025-03-06 18:35:30.000000 debian-binary │ │ --rw-r--r-- 0 0 0 3684 2025-03-06 18:35:30.000000 control.tar.xz │ │ --rw-r--r-- 0 0 0 726304 2025-03-06 18:35:30.000000 data.tar.xz │ │ +-rw-r--r-- 0 0 0 3680 2025-03-06 18:35:30.000000 control.tar.xz │ │ +-rw-r--r-- 0 0 0 713960 2025-03-06 18:35:30.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 {} │ │ │ │ │ @@ -52,37 +52,14 @@ │ │ │ │ │ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS │ │ │ │ │ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN │ │ │ │ │ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) │ │ │ │ │ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE │ │ │ │ │ * POSSIBILITY OF SUCH DAMAGE. │ │ │ │ │ */ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - Rico/license.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @license Apache 2 │ │ │ │ │ - * │ │ │ │ │ - * Contains portions of Rico │ │ │ │ │ - * │ │ │ │ │ - * Copyright 2005 Sabre Airline Solutions │ │ │ │ │ - * │ │ │ │ │ - * Licensed under the Apache License, Version 2.0 (the "License"); you │ │ │ │ │ - * may not use this file except in compliance with the License. You │ │ │ │ │ - * may obtain a copy of the License at │ │ │ │ │ - * │ │ │ │ │ - * http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ │ - * │ │ │ │ │ - * Unless required by applicable law or agreed to in writing, software │ │ │ │ │ - * distributed under the License is distributed on an "AS IS" BASIS, │ │ │ │ │ - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or │ │ │ │ │ - * implied. See the License for the specific language governing │ │ │ │ │ - * permissions and limitations under the License. │ │ │ │ │ - */ │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/SingleFile.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. */ │ │ │ │ │ @@ -159,395 +136,14 @@ │ │ │ │ │ * (code) │ │ │ │ │ * │ │ │ │ │ * (end code) │ │ │ │ │ */ │ │ │ │ │ ImgPath: '' │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/BaseTypes/Class.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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constructor: OpenLayers.Class │ │ │ │ │ - * Base class used to construct all other classes. Includes support for │ │ │ │ │ - * multiple inheritance. │ │ │ │ │ - * │ │ │ │ │ - * This constructor is new in OpenLayers 2.5. At OpenLayers 3.0, the old │ │ │ │ │ - * syntax for creating classes and dealing with inheritance │ │ │ │ │ - * will be removed. │ │ │ │ │ - * │ │ │ │ │ - * To create a new OpenLayers-style class, use the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * var MyClass = OpenLayers.Class(prototype); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * To create a new OpenLayers-style class with multiple inheritance, use the │ │ │ │ │ - * following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * var MyClass = OpenLayers.Class(Class1, Class2, prototype); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Note that instanceof reflection will only reveal Class1 as superclass. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Class = function() { │ │ │ │ │ - var len = arguments.length; │ │ │ │ │ - var P = arguments[0]; │ │ │ │ │ - var F = arguments[len - 1]; │ │ │ │ │ - │ │ │ │ │ - var C = typeof F.initialize == "function" ? │ │ │ │ │ - F.initialize : │ │ │ │ │ - function() { │ │ │ │ │ - P.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - if (len > 1) { │ │ │ │ │ - var newArgs = [C, P].concat( │ │ │ │ │ - Array.prototype.slice.call(arguments).slice(1, len - 1), F); │ │ │ │ │ - OpenLayers.inherit.apply(null, newArgs); │ │ │ │ │ - } else { │ │ │ │ │ - C.prototype = F; │ │ │ │ │ - } │ │ │ │ │ - return C; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.inherit │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * C - {Object} the class that inherits │ │ │ │ │ - * P - {Object} the superclass to inherit from │ │ │ │ │ - * │ │ │ │ │ - * In addition to the mandatory C and P parameters, an arbitrary number of │ │ │ │ │ - * objects can be passed, which will extend C. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.inherit = function(C, P) { │ │ │ │ │ - var F = function() {}; │ │ │ │ │ - F.prototype = P.prototype; │ │ │ │ │ - C.prototype = new F; │ │ │ │ │ - var i, l, o; │ │ │ │ │ - for (i = 2, l = arguments.length; i < l; i++) { │ │ │ │ │ - o = arguments[i]; │ │ │ │ │ - if (typeof o === "function") { │ │ │ │ │ - o = o.prototype; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.extend(C.prototype, o); │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: extend │ │ │ │ │ - * Copy all properties of a source object to a destination object. Modifies │ │ │ │ │ - * the passed in destination object. Any properties on the source object │ │ │ │ │ - * that are set to undefined will not be (re)set on the destination object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * destination - {Object} The object that will be modified │ │ │ │ │ - * source - {Object} The object with properties to be set on the destination │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} The destination object. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ -OpenLayers.Util.extend = function(destination, source) { │ │ │ │ │ - destination = destination || {}; │ │ │ │ │ - if (source) { │ │ │ │ │ - for (var property in source) { │ │ │ │ │ - var value = source[property]; │ │ │ │ │ - if (value !== undefined) { │ │ │ │ │ - destination[property] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * IE doesn't include the toString property when iterating over an object's │ │ │ │ │ - * properties with the for(property in object) syntax. Explicitly check if │ │ │ │ │ - * the source has its own toString property. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative │ │ │ │ │ - * prototype object" when calling hawOwnProperty if the source object │ │ │ │ │ - * is an instance of window.Event. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - var sourceIsEvt = typeof window.Event == "function" && │ │ │ │ │ - source instanceof window.Event; │ │ │ │ │ - │ │ │ │ │ - if (!sourceIsEvt && │ │ │ │ │ - source.hasOwnProperty && source.hasOwnProperty("toString")) { │ │ │ │ │ - destination.toString = source.toString; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return destination; │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Console.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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Console │ │ │ │ │ - * The OpenLayers.Console namespace is used for debugging and error logging. │ │ │ │ │ - * If the Firebug Lite (../Firebug/firebug.js) is included before this script, │ │ │ │ │ - * calls to OpenLayers.Console methods will get redirected to window.console. │ │ │ │ │ - * This makes use of the Firebug extension where available and allows for │ │ │ │ │ - * cross-browser debugging Firebug style. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * Note that behavior will differ with the Firebug extention and Firebug Lite. │ │ │ │ │ - * Most notably, the Firebug Lite console does not currently allow for │ │ │ │ │ - * hyperlinks to code or for clicking on object to explore their properties. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Console = { │ │ │ │ │ - /** │ │ │ │ │ - * Create empty functions for all console methods. The real value of these │ │ │ │ │ - * properties will be set if Firebug Lite (../Firebug/firebug.js script) is │ │ │ │ │ - * included. We explicitly require the Firebug Lite script to trigger │ │ │ │ │ - * functionality of the OpenLayers.Console methods. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: log │ │ │ │ │ - * Log an object in the console. The Firebug Lite console logs string │ │ │ │ │ - * representation of objects. Given multiple arguments, they will │ │ │ │ │ - * be cast to strings and logged with a space delimiter. If the first │ │ │ │ │ - * argument is a string with printf-like formatting, subsequent arguments │ │ │ │ │ - * will be used in string substitution. Any additional arguments (beyond │ │ │ │ │ - * the number substituted in a format string) will be appended in a space- │ │ │ │ │ - * delimited line. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - log: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: debug │ │ │ │ │ - * Writes a message to the console, including a hyperlink to the line │ │ │ │ │ - * where it was called. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - debug: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: info │ │ │ │ │ - * Writes a message to the console with the visual "info" icon and color │ │ │ │ │ - * coding and a hyperlink to the line where it was called. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - info: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: warn │ │ │ │ │ - * Writes a message to the console with the visual "warning" icon and │ │ │ │ │ - * color coding and a hyperlink to the line where it was called. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - warn: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: error │ │ │ │ │ - * Writes a message to the console with the visual "error" icon and color │ │ │ │ │ - * coding and a hyperlink to the line where it was called. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - error: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: userError │ │ │ │ │ - * A single interface for showing error messages to the user. The default │ │ │ │ │ - * behavior is a Javascript alert, though this can be overridden by │ │ │ │ │ - * reassigning OpenLayers.Console.userError to a different function. │ │ │ │ │ - * │ │ │ │ │ - * Expects a single error message │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * error - {Object} │ │ │ │ │ - */ │ │ │ │ │ - userError: function(error) { │ │ │ │ │ - alert(error); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: assert │ │ │ │ │ - * Tests that an expression is true. If not, it will write a message to │ │ │ │ │ - * the console and throw an exception. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - assert: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: dir │ │ │ │ │ - * Prints an interactive listing of all properties of the object. This │ │ │ │ │ - * looks identical to the view that you would see in the DOM tab. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - dir: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: dirxml │ │ │ │ │ - * Prints the XML source tree of an HTML or XML element. This looks │ │ │ │ │ - * identical to the view that you would see in the HTML tab. You can click │ │ │ │ │ - * on any node to inspect it in the HTML tab. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - dirxml: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: trace │ │ │ │ │ - * Prints an interactive stack trace of JavaScript execution at the point │ │ │ │ │ - * where it is called. The stack trace details the functions on the stack, │ │ │ │ │ - * as well as the values that were passed as arguments to each function. │ │ │ │ │ - * You can click each function to take you to its source in the Script tab, │ │ │ │ │ - * and click each argument value to inspect it in the DOM or HTML tabs. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - trace: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: group │ │ │ │ │ - * Writes a message to the console and opens a nested block to indent all │ │ │ │ │ - * future messages sent to the console. Call OpenLayers.Console.groupEnd() │ │ │ │ │ - * to close the block. │ │ │ │ │ - * │ │ │ │ │ - * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ - */ │ │ │ │ │ - group: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: groupEnd │ │ │ │ │ - * Closes the most recently opened block created by a call to │ │ │ │ │ - * OpenLayers.Console.group │ │ │ │ │ - */ │ │ │ │ │ - groupEnd: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: time │ │ │ │ │ - * Creates a new timer under the given name. Call │ │ │ │ │ - * OpenLayers.Console.timeEnd(name) │ │ │ │ │ - * with the same name to stop the timer and print the time elapsed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - */ │ │ │ │ │ - time: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: timeEnd │ │ │ │ │ - * Stops a timer created by a call to OpenLayers.Console.time(name) and │ │ │ │ │ - * writes the time elapsed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - */ │ │ │ │ │ - timeEnd: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: profile │ │ │ │ │ - * Turns on the JavaScript profiler. The optional argument title would │ │ │ │ │ - * contain the text to be printed in the header of the profile report. │ │ │ │ │ - * │ │ │ │ │ - * This function is not currently implemented in Firebug Lite. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * title - {String} Optional title for the profiler │ │ │ │ │ - */ │ │ │ │ │ - profile: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: profileEnd │ │ │ │ │ - * Turns off the JavaScript profiler and prints its report. │ │ │ │ │ - * │ │ │ │ │ - * This function is not currently implemented in Firebug Lite. │ │ │ │ │ - */ │ │ │ │ │ - profileEnd: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: count │ │ │ │ │ - * Writes the number of times that the line of code where count was called │ │ │ │ │ - * was executed. The optional argument title will print a message in │ │ │ │ │ - * addition to the number of the count. │ │ │ │ │ - * │ │ │ │ │ - * This function is not currently implemented in Firebug Lite. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * title - {String} Optional title to be printed with count │ │ │ │ │ - */ │ │ │ │ │ - count: function() {}, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Console" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Execute an anonymous function to extend the OpenLayers.Console namespace │ │ │ │ │ - * if the firebug.js script is included. This closure is used so that the │ │ │ │ │ - * "scripts" and "i" variables don't pollute the global namespace. │ │ │ │ │ - */ │ │ │ │ │ -(function() { │ │ │ │ │ - /** │ │ │ │ │ - * If Firebug Lite is included (before this script), re-route all │ │ │ │ │ - * OpenLayers.Console calls to the console object. │ │ │ │ │ - */ │ │ │ │ │ - var scripts = document.getElementsByTagName("script"); │ │ │ │ │ - for (var i = 0, len = scripts.length; i < len; ++i) { │ │ │ │ │ - if (scripts[i].src.indexOf("firebug.js") != -1) { │ │ │ │ │ - if (console) { │ │ │ │ │ - OpenLayers.Util.extend(OpenLayers.Console, console); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ -})(); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/BaseTypes.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. */ │ │ │ │ │ @@ -1007,14 +603,141 @@ │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ return selected; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/BaseTypes/Class.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 │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constructor: OpenLayers.Class │ │ │ │ │ + * Base class used to construct all other classes. Includes support for │ │ │ │ │ + * multiple inheritance. │ │ │ │ │ + * │ │ │ │ │ + * This constructor is new in OpenLayers 2.5. At OpenLayers 3.0, the old │ │ │ │ │ + * syntax for creating classes and dealing with inheritance │ │ │ │ │ + * will be removed. │ │ │ │ │ + * │ │ │ │ │ + * To create a new OpenLayers-style class, use the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * var MyClass = OpenLayers.Class(prototype); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * To create a new OpenLayers-style class with multiple inheritance, use the │ │ │ │ │ + * following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * var MyClass = OpenLayers.Class(Class1, Class2, prototype); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Note that instanceof reflection will only reveal Class1 as superclass. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Class = function() { │ │ │ │ │ + var len = arguments.length; │ │ │ │ │ + var P = arguments[0]; │ │ │ │ │ + var F = arguments[len - 1]; │ │ │ │ │ + │ │ │ │ │ + var C = typeof F.initialize == "function" ? │ │ │ │ │ + F.initialize : │ │ │ │ │ + function() { │ │ │ │ │ + P.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + if (len > 1) { │ │ │ │ │ + var newArgs = [C, P].concat( │ │ │ │ │ + Array.prototype.slice.call(arguments).slice(1, len - 1), F); │ │ │ │ │ + OpenLayers.inherit.apply(null, newArgs); │ │ │ │ │ + } else { │ │ │ │ │ + C.prototype = F; │ │ │ │ │ + } │ │ │ │ │ + return C; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Function: OpenLayers.inherit │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * C - {Object} the class that inherits │ │ │ │ │ + * P - {Object} the superclass to inherit from │ │ │ │ │ + * │ │ │ │ │ + * In addition to the mandatory C and P parameters, an arbitrary number of │ │ │ │ │ + * objects can be passed, which will extend C. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.inherit = function(C, P) { │ │ │ │ │ + var F = function() {}; │ │ │ │ │ + F.prototype = P.prototype; │ │ │ │ │ + C.prototype = new F; │ │ │ │ │ + var i, l, o; │ │ │ │ │ + for (i = 2, l = arguments.length; i < l; i++) { │ │ │ │ │ + o = arguments[i]; │ │ │ │ │ + if (typeof o === "function") { │ │ │ │ │ + o = o.prototype; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.extend(C.prototype, o); │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: extend │ │ │ │ │ + * Copy all properties of a source object to a destination object. Modifies │ │ │ │ │ + * the passed in destination object. Any properties on the source object │ │ │ │ │ + * that are set to undefined will not be (re)set on the destination object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * destination - {Object} The object that will be modified │ │ │ │ │ + * source - {Object} The object with properties to be set on the destination │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} The destination object. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ +OpenLayers.Util.extend = function(destination, source) { │ │ │ │ │ + destination = destination || {}; │ │ │ │ │ + if (source) { │ │ │ │ │ + for (var property in source) { │ │ │ │ │ + var value = source[property]; │ │ │ │ │ + if (value !== undefined) { │ │ │ │ │ + destination[property] = value; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * IE doesn't include the toString property when iterating over an object's │ │ │ │ │ + * properties with the for(property in object) syntax. Explicitly check if │ │ │ │ │ + * the source has its own toString property. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /* │ │ │ │ │ + * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative │ │ │ │ │ + * prototype object" when calling hawOwnProperty if the source object │ │ │ │ │ + * is an instance of window.Event. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + var sourceIsEvt = typeof window.Event == "function" && │ │ │ │ │ + source instanceof window.Event; │ │ │ │ │ + │ │ │ │ │ + if (!sourceIsEvt && │ │ │ │ │ + source.hasOwnProperty && source.hasOwnProperty("toString")) { │ │ │ │ │ + destination.toString = source.toString; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return destination; │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/BaseTypes/Bounds.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. */ │ │ │ │ │ @@ -1866,14 +1589,207 @@ │ │ │ │ │ │ │ │ │ │ opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; │ │ │ │ │ opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; │ │ │ │ │ │ │ │ │ │ return opp; │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/BaseTypes/Element.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/Util.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Element │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Element = { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: visible │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Is the element visible? │ │ │ │ │ + */ │ │ │ │ │ + visible: function(element) { │ │ │ │ │ + return OpenLayers.Util.getElement(element).style.display != 'none'; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: toggle │ │ │ │ │ + * Toggle the visibility of element(s) passed in │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} Actually user can pass any number of elements │ │ │ │ │ + */ │ │ │ │ │ + toggle: function() { │ │ │ │ │ + for (var i = 0, len = arguments.length; i < len; i++) { │ │ │ │ │ + var element = OpenLayers.Util.getElement(arguments[i]); │ │ │ │ │ + var display = OpenLayers.Element.visible(element) ? 'none' : │ │ │ │ │ + ''; │ │ │ │ │ + element.style.display = display; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: remove │ │ │ │ │ + * Remove the specified element from the DOM. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + remove: function(element) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + element.parentNode.removeChild(element); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: getHeight │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The offset height of the element passed in │ │ │ │ │ + */ │ │ │ │ │ + getHeight: function(element) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + return element.offsetHeight; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: hasClass │ │ │ │ │ + * Tests if an element has the given CSS class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to search for. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The element has the given class name. │ │ │ │ │ + */ │ │ │ │ │ + hasClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + return (!!names && new RegExp("(^|\\s)" + name + "(\\s|$)").test(names)); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: addClass │ │ │ │ │ + * Add a CSS class name to an element. Safe where element already has │ │ │ │ │ + * the class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to add. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + addClass: function(element, name) { │ │ │ │ │ + if (!OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + element.className += (element.className ? " " : "") + name; │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: removeClass │ │ │ │ │ + * Remove a CSS class name from an element. Safe where element does not │ │ │ │ │ + * have the class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to remove. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + removeClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + if (names) { │ │ │ │ │ + element.className = OpenLayers.String.trim( │ │ │ │ │ + names.replace( │ │ │ │ │ + new RegExp("(^|\\s+)" + name + "(\\s+|$)"), " " │ │ │ │ │ + ) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: toggleClass │ │ │ │ │ + * Remove a CSS class name from an element if it exists. Add the class name │ │ │ │ │ + * if it doesn't exist. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to toggle. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + toggleClass: function(element, name) { │ │ │ │ │ + if (OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + OpenLayers.Element.removeClass(element, name); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Element.addClass(element, name); │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: getStyle │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * style - {?} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {?} │ │ │ │ │ + */ │ │ │ │ │ + getStyle: function(element, style) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + │ │ │ │ │ + var value = null; │ │ │ │ │ + if (element && element.style) { │ │ │ │ │ + value = element.style[OpenLayers.String.camelize(style)]; │ │ │ │ │ + if (!value) { │ │ │ │ │ + if (document.defaultView && │ │ │ │ │ + document.defaultView.getComputedStyle) { │ │ │ │ │ + │ │ │ │ │ + var css = document.defaultView.getComputedStyle(element, null); │ │ │ │ │ + value = css ? css.getPropertyValue(style) : null; │ │ │ │ │ + } else if (element.currentStyle) { │ │ │ │ │ + value = element.currentStyle[OpenLayers.String.camelize(style)]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var positions = ['left', 'top', 'right', 'bottom']; │ │ │ │ │ + if (window.opera && │ │ │ │ │ + (OpenLayers.Util.indexOf(positions, style) != -1) && │ │ │ │ │ + (OpenLayers.Element.getStyle(element, 'position') == 'static')) { │ │ │ │ │ + value = 'auto'; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return value == 'auto' ? null : value; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/BaseTypes/LonLat.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. */ │ │ │ │ │ @@ -2327,14 +2243,268 @@ │ │ │ │ │ } │ │ │ │ │ return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Size" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Console.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 │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Console │ │ │ │ │ + * The OpenLayers.Console namespace is used for debugging and error logging. │ │ │ │ │ + * If the Firebug Lite (../Firebug/firebug.js) is included before this script, │ │ │ │ │ + * calls to OpenLayers.Console methods will get redirected to window.console. │ │ │ │ │ + * This makes use of the Firebug extension where available and allows for │ │ │ │ │ + * cross-browser debugging Firebug style. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * Note that behavior will differ with the Firebug extention and Firebug Lite. │ │ │ │ │ + * Most notably, the Firebug Lite console does not currently allow for │ │ │ │ │ + * hyperlinks to code or for clicking on object to explore their properties. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Console = { │ │ │ │ │ + /** │ │ │ │ │ + * Create empty functions for all console methods. The real value of these │ │ │ │ │ + * properties will be set if Firebug Lite (../Firebug/firebug.js script) is │ │ │ │ │ + * included. We explicitly require the Firebug Lite script to trigger │ │ │ │ │ + * functionality of the OpenLayers.Console methods. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: log │ │ │ │ │ + * Log an object in the console. The Firebug Lite console logs string │ │ │ │ │ + * representation of objects. Given multiple arguments, they will │ │ │ │ │ + * be cast to strings and logged with a space delimiter. If the first │ │ │ │ │ + * argument is a string with printf-like formatting, subsequent arguments │ │ │ │ │ + * will be used in string substitution. Any additional arguments (beyond │ │ │ │ │ + * the number substituted in a format string) will be appended in a space- │ │ │ │ │ + * delimited line. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + log: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: debug │ │ │ │ │ + * Writes a message to the console, including a hyperlink to the line │ │ │ │ │ + * where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + debug: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: info │ │ │ │ │ + * Writes a message to the console with the visual "info" icon and color │ │ │ │ │ + * coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + info: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: warn │ │ │ │ │ + * Writes a message to the console with the visual "warning" icon and │ │ │ │ │ + * color coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + warn: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: error │ │ │ │ │ + * Writes a message to the console with the visual "error" icon and color │ │ │ │ │ + * coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + error: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: userError │ │ │ │ │ + * A single interface for showing error messages to the user. The default │ │ │ │ │ + * behavior is a Javascript alert, though this can be overridden by │ │ │ │ │ + * reassigning OpenLayers.Console.userError to a different function. │ │ │ │ │ + * │ │ │ │ │ + * Expects a single error message │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * error - {Object} │ │ │ │ │ + */ │ │ │ │ │ + userError: function(error) { │ │ │ │ │ + alert(error); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: assert │ │ │ │ │ + * Tests that an expression is true. If not, it will write a message to │ │ │ │ │ + * the console and throw an exception. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + assert: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: dir │ │ │ │ │ + * Prints an interactive listing of all properties of the object. This │ │ │ │ │ + * looks identical to the view that you would see in the DOM tab. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + dir: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: dirxml │ │ │ │ │ + * Prints the XML source tree of an HTML or XML element. This looks │ │ │ │ │ + * identical to the view that you would see in the HTML tab. You can click │ │ │ │ │ + * on any node to inspect it in the HTML tab. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + dirxml: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: trace │ │ │ │ │ + * Prints an interactive stack trace of JavaScript execution at the point │ │ │ │ │ + * where it is called. The stack trace details the functions on the stack, │ │ │ │ │ + * as well as the values that were passed as arguments to each function. │ │ │ │ │ + * You can click each function to take you to its source in the Script tab, │ │ │ │ │ + * and click each argument value to inspect it in the DOM or HTML tabs. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + trace: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: group │ │ │ │ │ + * Writes a message to the console and opens a nested block to indent all │ │ │ │ │ + * future messages sent to the console. Call OpenLayers.Console.groupEnd() │ │ │ │ │ + * to close the block. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + group: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: groupEnd │ │ │ │ │ + * Closes the most recently opened block created by a call to │ │ │ │ │ + * OpenLayers.Console.group │ │ │ │ │ + */ │ │ │ │ │ + groupEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: time │ │ │ │ │ + * Creates a new timer under the given name. Call │ │ │ │ │ + * OpenLayers.Console.timeEnd(name) │ │ │ │ │ + * with the same name to stop the timer and print the time elapsed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} │ │ │ │ │ + */ │ │ │ │ │ + time: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: timeEnd │ │ │ │ │ + * Stops a timer created by a call to OpenLayers.Console.time(name) and │ │ │ │ │ + * writes the time elapsed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} │ │ │ │ │ + */ │ │ │ │ │ + timeEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: profile │ │ │ │ │ + * Turns on the JavaScript profiler. The optional argument title would │ │ │ │ │ + * contain the text to be printed in the header of the profile report. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * title - {String} Optional title for the profiler │ │ │ │ │ + */ │ │ │ │ │ + profile: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: profileEnd │ │ │ │ │ + * Turns off the JavaScript profiler and prints its report. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + */ │ │ │ │ │ + profileEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: count │ │ │ │ │ + * Writes the number of times that the line of code where count was called │ │ │ │ │ + * was executed. The optional argument title will print a message in │ │ │ │ │ + * addition to the number of the count. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * title - {String} Optional title to be printed with count │ │ │ │ │ + */ │ │ │ │ │ + count: function() {}, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Console" │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Execute an anonymous function to extend the OpenLayers.Console namespace │ │ │ │ │ + * if the firebug.js script is included. This closure is used so that the │ │ │ │ │ + * "scripts" and "i" variables don't pollute the global namespace. │ │ │ │ │ + */ │ │ │ │ │ +(function() { │ │ │ │ │ + /** │ │ │ │ │ + * If Firebug Lite is included (before this script), re-route all │ │ │ │ │ + * OpenLayers.Console calls to the console object. │ │ │ │ │ + */ │ │ │ │ │ + var scripts = document.getElementsByTagName("script"); │ │ │ │ │ + for (var i = 0, len = scripts.length; i < len; ++i) { │ │ │ │ │ + if (scripts[i].src.indexOf("firebug.js") != -1) { │ │ │ │ │ + if (console) { │ │ │ │ │ + OpenLayers.Util.extend(OpenLayers.Console, console); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ +})(); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/Lang.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. */ │ │ │ │ │ @@ -4256,840 +4426,579 @@ │ │ │ │ │ } else { │ │ │ │ │ str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N"); │ │ │ │ │ } │ │ │ │ │ return str; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/BaseTypes/Element.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/BaseTypes.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Namespace: OpenLayers.Element │ │ │ │ │ + * 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.Element = { │ │ │ │ │ +OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: visible │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Is the element visible? │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} A reference to options passed to the constructor. │ │ │ │ │ */ │ │ │ │ │ - visible: function(element) { │ │ │ │ │ - return OpenLayers.Util.getElement(element).style.display != 'none'; │ │ │ │ │ - }, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: toggle │ │ │ │ │ - * Toggle the visibility of element(s) passed in │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} Actually user can pass any number of elements │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - toggle: function() { │ │ │ │ │ - for (var i = 0, len = arguments.length; i < len; i++) { │ │ │ │ │ - var element = OpenLayers.Util.getElement(arguments[i]); │ │ │ │ │ - var display = OpenLayers.Element.visible(element) ? 'none' : │ │ │ │ │ - ''; │ │ │ │ │ - element.style.display = display; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + externalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: remove │ │ │ │ │ - * Remove the specified element from the DOM. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - remove: function(element) { │ │ │ │ │ - element = OpenLayers.Util.getElement(element); │ │ │ │ │ - element.parentNode.removeChild(element); │ │ │ │ │ - }, │ │ │ │ │ + internalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: getHeight │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The offset height of the element passed in │ │ │ │ │ + * APIProperty: data │ │ │ │ │ + * {Object} When is true, this is the parsed string sent to │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - getHeight: function(element) { │ │ │ │ │ - element = OpenLayers.Util.getElement(element); │ │ │ │ │ - return element.offsetHeight; │ │ │ │ │ - }, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: hasClass │ │ │ │ │ - * Tests if an element has the given CSS class name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to search for. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The element has the given class name. │ │ │ │ │ + * APIProperty: keepData │ │ │ │ │ + * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - hasClass: function(element, name) { │ │ │ │ │ - var names = element.className; │ │ │ │ │ - return (!!names && new RegExp("(^|\\s)" + name + "(\\s|$)").test(names)); │ │ │ │ │ - }, │ │ │ │ │ + keepData: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: addClass │ │ │ │ │ - * Add a CSS class name to an element. Safe where element already has │ │ │ │ │ - * the class name. │ │ │ │ │ + * Constructor: OpenLayers.Format │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to add. │ │ │ │ │ + * 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). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The element. │ │ │ │ │ + * An instance of OpenLayers.Format │ │ │ │ │ */ │ │ │ │ │ - addClass: function(element, name) { │ │ │ │ │ - if (!OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ - element.className += (element.className ? " " : "") + name; │ │ │ │ │ - } │ │ │ │ │ - return element; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: removeClass │ │ │ │ │ - * Remove a CSS class name from an element. Safe where element does not │ │ │ │ │ - * have the class name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to remove. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The element. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ */ │ │ │ │ │ - removeClass: function(element, name) { │ │ │ │ │ - var names = element.className; │ │ │ │ │ - if (names) { │ │ │ │ │ - element.className = OpenLayers.String.trim( │ │ │ │ │ - names.replace( │ │ │ │ │ - new RegExp("(^|\\s+)" + name + "(\\s+|$)"), " " │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return element; │ │ │ │ │ - }, │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: toggleClass │ │ │ │ │ - * Remove a CSS class name from an element if it exists. Add the class name │ │ │ │ │ - * if it doesn't exist. │ │ │ │ │ - * │ │ │ │ │ + * Method: read │ │ │ │ │ + * Read data from a string, and return an object whose type depends on the │ │ │ │ │ + * subclass. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to toggle. │ │ │ │ │ + * data - {string} Data to read/parse. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The element. │ │ │ │ │ + * Depends on the subclass │ │ │ │ │ */ │ │ │ │ │ - toggleClass: function(element, name) { │ │ │ │ │ - if (OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ - OpenLayers.Element.removeClass(element, name); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Element.addClass(element, name); │ │ │ │ │ - } │ │ │ │ │ - return element; │ │ │ │ │ + read: function(data) { │ │ │ │ │ + throw new Error('Read not implemented.'); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIFunction: getStyle │ │ │ │ │ - * │ │ │ │ │ + * Method: write │ │ │ │ │ + * Accept an object, and return a string. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * style - {?} │ │ │ │ │ - * │ │ │ │ │ + * object - {Object} Object to be serialized │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {?} │ │ │ │ │ + * {String} A string representation of the object. │ │ │ │ │ */ │ │ │ │ │ - getStyle: function(element, style) { │ │ │ │ │ - element = OpenLayers.Util.getElement(element); │ │ │ │ │ - │ │ │ │ │ - var value = null; │ │ │ │ │ - if (element && element.style) { │ │ │ │ │ - value = element.style[OpenLayers.String.camelize(style)]; │ │ │ │ │ - if (!value) { │ │ │ │ │ - if (document.defaultView && │ │ │ │ │ - document.defaultView.getComputedStyle) { │ │ │ │ │ - │ │ │ │ │ - var css = document.defaultView.getComputedStyle(element, null); │ │ │ │ │ - value = css ? css.getPropertyValue(style) : null; │ │ │ │ │ - } else if (element.currentStyle) { │ │ │ │ │ - value = element.currentStyle[OpenLayers.String.camelize(style)]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var positions = ['left', 'top', 'right', 'bottom']; │ │ │ │ │ - if (window.opera && │ │ │ │ │ - (OpenLayers.Util.indexOf(positions, style) != -1) && │ │ │ │ │ - (OpenLayers.Element.getStyle(element, 'position') == 'static')) { │ │ │ │ │ - value = 'auto'; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return value == 'auto' ? null : value; │ │ │ │ │ - } │ │ │ │ │ + write: function(object) { │ │ │ │ │ + throw new Error('Write not implemented.'); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -}; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - Rico/Color.js │ │ │ │ │ + OpenLayers/Tile.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires Rico/license.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Element.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 file has been edited substantially from the Rico-released version by │ │ │ │ │ - * the OpenLayers development team. │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Console.warn("OpenLayers.Rico is deprecated"); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Rico = OpenLayers.Rico || {}; │ │ │ │ │ -OpenLayers.Rico.Color = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - initialize: function(red, green, blue) { │ │ │ │ │ - this.rgb = { │ │ │ │ │ - r: red, │ │ │ │ │ - g: green, │ │ │ │ │ - b: blue │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setRed: function(r) { │ │ │ │ │ - this.rgb.r = r; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setGreen: function(g) { │ │ │ │ │ - this.rgb.g = g; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setBlue: function(b) { │ │ │ │ │ - this.rgb.b = b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setHue: function(h) { │ │ │ │ │ - │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.h = h; │ │ │ │ │ - │ │ │ │ │ - // convert back to RGB... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setSaturation: function(s) { │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.s = s; │ │ │ │ │ - │ │ │ │ │ - // convert back to RGB and set values... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setBrightness: function(b) { │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.b = b; │ │ │ │ │ - │ │ │ │ │ - // convert back to RGB and set values... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - darken: function(percent) { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent, 0)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - brighten: function(percent) { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent, 1)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - blend: function(other) { │ │ │ │ │ - this.rgb.r = Math.floor((this.rgb.r + other.rgb.r) / 2); │ │ │ │ │ - this.rgb.g = Math.floor((this.rgb.g + other.rgb.g) / 2); │ │ │ │ │ - this.rgb.b = Math.floor((this.rgb.b + other.rgb.b) / 2); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - isBright: function() { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - return this.asHSB().b > 0.5; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - isDark: function() { │ │ │ │ │ - return !this.isBright(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - asRGB: function() { │ │ │ │ │ - return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - asHex: function() { │ │ │ │ │ - return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - asHSB: function() { │ │ │ │ │ - return OpenLayers.Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - toString: function() { │ │ │ │ │ - return this.asHex(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Rico.Color.createFromHex = function(hexCode) { │ │ │ │ │ - if (hexCode.length == 4) { │ │ │ │ │ - var shortHexCode = hexCode; │ │ │ │ │ - var hexCode = '#'; │ │ │ │ │ - for (var i = 1; i < 4; i++) { │ │ │ │ │ - hexCode += (shortHexCode.charAt(i) + │ │ │ │ │ - shortHexCode.charAt(i)); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (hexCode.indexOf('#') == 0) { │ │ │ │ │ - hexCode = hexCode.substring(1); │ │ │ │ │ - } │ │ │ │ │ - var red = hexCode.substring(0, 2); │ │ │ │ │ - var green = hexCode.substring(2, 4); │ │ │ │ │ - var blue = hexCode.substring(4, 6); │ │ │ │ │ - return new OpenLayers.Rico.Color(parseInt(red, 16), parseInt(green, 16), parseInt(blue, 16)); │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Factory method for creating a color from the background of │ │ │ │ │ - * an HTML element. │ │ │ │ │ + * 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.Rico.Color.createColorFromBackground = function(elem) { │ │ │ │ │ - │ │ │ │ │ - var actualColor = │ │ │ │ │ - OpenLayers.Element.getStyle(OpenLayers.Util.getElement(elem), │ │ │ │ │ - "backgroundColor"); │ │ │ │ │ +OpenLayers.Tile = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - if (actualColor == "transparent" && elem.parentNode) { │ │ │ │ │ - return OpenLayers.Rico.Color.createColorFromBackground(elem.parentNode); │ │ │ │ │ - } │ │ │ │ │ - if (actualColor == null) { │ │ │ │ │ - return new OpenLayers.Rico.Color(255, 255, 255); │ │ │ │ │ - } │ │ │ │ │ - if (actualColor.indexOf("rgb(") == 0) { │ │ │ │ │ - var colors = actualColor.substring(4, actualColor.length - 1); │ │ │ │ │ - var colorArray = colors.split(","); │ │ │ │ │ - return new OpenLayers.Rico.Color(parseInt(colorArray[0]), │ │ │ │ │ - parseInt(colorArray[1]), │ │ │ │ │ - parseInt(colorArray[2])); │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - } else if (actualColor.indexOf("#") == 0) { │ │ │ │ │ - return OpenLayers.Rico.Color.createFromHex(actualColor); │ │ │ │ │ - } else { │ │ │ │ │ - return new OpenLayers.Rico.Color(255, 255, 255); │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + */ │ │ │ │ │ + eventListeners: null, │ │ │ │ │ │ │ │ │ │ -OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} null │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - var red = 0; │ │ │ │ │ - var green = 0; │ │ │ │ │ - var blue = 0; │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} layer the tile is attached to │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ - if (saturation == 0) { │ │ │ │ │ - red = parseInt(brightness * 255.0 + 0.5); │ │ │ │ │ - green = red; │ │ │ │ │ - blue = red; │ │ │ │ │ - } else { │ │ │ │ │ - var h = (hue - Math.floor(hue)) * 6.0; │ │ │ │ │ - var f = h - Math.floor(h); │ │ │ │ │ - var p = brightness * (1.0 - saturation); │ │ │ │ │ - var q = brightness * (1.0 - saturation * f); │ │ │ │ │ - var t = brightness * (1.0 - (saturation * (1.0 - f))); │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - switch (parseInt(h)) { │ │ │ │ │ - case 0: │ │ │ │ │ - red = (brightness * 255.0 + 0.5); │ │ │ │ │ - green = (t * 255.0 + 0.5); │ │ │ │ │ - blue = (p * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - case 1: │ │ │ │ │ - red = (q * 255.0 + 0.5); │ │ │ │ │ - green = (brightness * 255.0 + 0.5); │ │ │ │ │ - blue = (p * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - case 2: │ │ │ │ │ - red = (p * 255.0 + 0.5); │ │ │ │ │ - green = (brightness * 255.0 + 0.5); │ │ │ │ │ - blue = (t * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - case 3: │ │ │ │ │ - red = (p * 255.0 + 0.5); │ │ │ │ │ - green = (q * 255.0 + 0.5); │ │ │ │ │ - blue = (brightness * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - case 4: │ │ │ │ │ - red = (t * 255.0 + 0.5); │ │ │ │ │ - green = (p * 255.0 + 0.5); │ │ │ │ │ - blue = (brightness * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - case 5: │ │ │ │ │ - red = (brightness * 255.0 + 0.5); │ │ │ │ │ - green = (p * 255.0 + 0.5); │ │ │ │ │ - blue = (q * 255.0 + 0.5); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: bounds │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ - return { │ │ │ │ │ - r: parseInt(red), │ │ │ │ │ - g: parseInt(green), │ │ │ │ │ - b: parseInt(blue) │ │ │ │ │ - }; │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ -OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { │ │ │ │ │ + /** │ │ │ │ │ + * Property: position │ │ │ │ │ + * {} Top Left pixel of the tile │ │ │ │ │ + */ │ │ │ │ │ + position: null, │ │ │ │ │ │ │ │ │ │ - var hue; │ │ │ │ │ - var saturation; │ │ │ │ │ - var brightness; │ │ │ │ │ + /** │ │ │ │ │ + * Property: isLoading │ │ │ │ │ + * {Boolean} Is the tile loading? │ │ │ │ │ + */ │ │ │ │ │ + isLoading: false, │ │ │ │ │ │ │ │ │ │ - var cmax = (r > g) ? r : g; │ │ │ │ │ - if (b > cmax) { │ │ │ │ │ - cmax = b; │ │ │ │ │ - } │ │ │ │ │ - var cmin = (r < g) ? r : g; │ │ │ │ │ - if (b < cmin) { │ │ │ │ │ - cmin = b; │ │ │ │ │ - } │ │ │ │ │ - brightness = cmax / 255.0; │ │ │ │ │ - if (cmax != 0) { │ │ │ │ │ - saturation = (cmax - cmin) / cmax; │ │ │ │ │ - } else { │ │ │ │ │ - saturation = 0; │ │ │ │ │ - } │ │ │ │ │ - if (saturation == 0) { │ │ │ │ │ - hue = 0; │ │ │ │ │ - } else { │ │ │ │ │ - var redc = (cmax - r) / (cmax - cmin); │ │ │ │ │ - var greenc = (cmax - g) / (cmax - cmin); │ │ │ │ │ - var bluec = (cmax - b) / (cmax - cmin); │ │ │ │ │ + /** 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (r == cmax) { │ │ │ │ │ - hue = bluec - greenc; │ │ │ │ │ - } else if (g == cmax) { │ │ │ │ │ - hue = 2.0 + redc - bluec; │ │ │ │ │ - } else { │ │ │ │ │ - hue = 4.0 + greenc - redc; │ │ │ │ │ - } │ │ │ │ │ - hue = hue / 6.0; │ │ │ │ │ - if (hue < 0) { │ │ │ │ │ - hue = hue + 1.0; │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * 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(); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - h: hue, │ │ │ │ │ - s: saturation, │ │ │ │ │ - b: brightness │ │ │ │ │ - }; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - Rico/Corner.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ - * @requires Rico/Color.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* │ │ │ │ │ - * This file has been edited substantially from the Rico-released │ │ │ │ │ - * version by the OpenLayers development team. │ │ │ │ │ - * │ │ │ │ │ - * Copyright 2005 Sabre Airline Solutions │ │ │ │ │ - * │ │ │ │ │ - * Licensed under the Apache License, Version 2.0 (the "License"); │ │ │ │ │ - * you may not use this file except in compliance with the │ │ │ │ │ - * License. You may obtain a copy of the License at │ │ │ │ │ - * │ │ │ │ │ - * http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ │ - * │ │ │ │ │ - * Unless required by applicable law or agreed to in writing, software │ │ │ │ │ - * distributed under the * License is distributed on an "AS IS" BASIS, │ │ │ │ │ - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or │ │ │ │ │ - * implied. See the License for the specific language governing │ │ │ │ │ - * permissions * and limitations under the License. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Console.warn("OpenLayers.Rico is deprecated"); │ │ │ │ │ │ │ │ │ │ -OpenLayers.Rico = OpenLayers.Rico || {}; │ │ │ │ │ -OpenLayers.Rico.Corner = { │ │ │ │ │ + //give the tile a unique id based on its BBOX. │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID("Tile_"); │ │ │ │ │ │ │ │ │ │ - round: function(e, options) { │ │ │ │ │ - e = OpenLayers.Util.getElement(e); │ │ │ │ │ - this._setOptions(options); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ │ │ │ │ │ - var color = this.options.color; │ │ │ │ │ - if (this.options.color == "fromElement") { │ │ │ │ │ - color = this._background(e); │ │ │ │ │ - } │ │ │ │ │ - var bgColor = this.options.bgColor; │ │ │ │ │ - if (this.options.bgColor == "fromParent") { │ │ │ │ │ - bgColor = this._background(e.offsetParent); │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ - this._roundCornersImpl(e, color, bgColor); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** This is a helper function to change the background │ │ │ │ │ - * color of
that has had Rico rounded corners added. │ │ │ │ │ - * │ │ │ │ │ - * It seems we cannot just set the background color for the │ │ │ │ │ - * outer
so each element used to create the │ │ │ │ │ - * corners must have its background color set individually. │ │ │ │ │ - * │ │ │ │ │ - * @param {DOM} theDiv - A child of the outer
that was │ │ │ │ │ - * supplied to the `round` method. │ │ │ │ │ - * │ │ │ │ │ - * @param {String} newColor - The new background color to use. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - changeColor: function(theDiv, newColor) { │ │ │ │ │ - │ │ │ │ │ - theDiv.style.backgroundColor = newColor; │ │ │ │ │ - │ │ │ │ │ - var spanElements = theDiv.parentNode.getElementsByTagName("span"); │ │ │ │ │ - │ │ │ │ │ - for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { │ │ │ │ │ - spanElements[currIdx].style.backgroundColor = newColor; │ │ │ │ │ + unload: function() { │ │ │ │ │ + if (this.isLoading) { │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + this.events.triggerEvent("unload"); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /** This is a helper function to change the background │ │ │ │ │ - * opacity of
that has had Rico rounded corners added. │ │ │ │ │ - * │ │ │ │ │ - * See changeColor (above) for algorithm explanation │ │ │ │ │ - * │ │ │ │ │ - * @param {DOM} theDiv A child of the outer
that was │ │ │ │ │ - * supplied to the `round` method. │ │ │ │ │ - * │ │ │ │ │ - * @param {int} newOpacity The new opacity to use (0-1). │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Nullify references to prevent circular references and memory leaks. │ │ │ │ │ */ │ │ │ │ │ - changeOpacity: function(theDiv, newOpacity) { │ │ │ │ │ - │ │ │ │ │ - var mozillaOpacity = newOpacity; │ │ │ │ │ - var ieOpacity = 'alpha(opacity=' + newOpacity * 100 + ')'; │ │ │ │ │ - │ │ │ │ │ - theDiv.style.opacity = mozillaOpacity; │ │ │ │ │ - theDiv.style.filter = ieOpacity; │ │ │ │ │ - │ │ │ │ │ - var spanElements = theDiv.parentNode.getElementsByTagName("span"); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.position = null; │ │ │ │ │ │ │ │ │ │ - for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { │ │ │ │ │ - spanElements[currIdx].style.opacity = mozillaOpacity; │ │ │ │ │ - spanElements[currIdx].style.filter = ieOpacity; │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** this function takes care of redoing the rico cornering │ │ │ │ │ - * │ │ │ │ │ - * you can't just call updateRicoCorners() again and pass it a │ │ │ │ │ - * new options string. you have to first remove the divs that │ │ │ │ │ - * rico puts on top and below the content div. │ │ │ │ │ - * │ │ │ │ │ - * @param {DOM} theDiv - A child of the outer
that was │ │ │ │ │ - * supplied to the `round` method. │ │ │ │ │ + /** │ │ │ │ │ + * 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 . │ │ │ │ │ * │ │ │ │ │ - * @param {Object} options - list of options │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - reRound: function(theDiv, options) { │ │ │ │ │ - │ │ │ │ │ - var topRico = theDiv.parentNode.childNodes[0]; │ │ │ │ │ - //theDiv would be theDiv.parentNode.childNodes[1] │ │ │ │ │ - var bottomRico = theDiv.parentNode.childNodes[2]; │ │ │ │ │ - │ │ │ │ │ - theDiv.parentNode.removeChild(topRico); │ │ │ │ │ - theDiv.parentNode.removeChild(bottomRico); │ │ │ │ │ - │ │ │ │ │ - this.round(theDiv.parentNode, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - _roundCornersImpl: function(e, color, bgColor) { │ │ │ │ │ - if (this.options.border) { │ │ │ │ │ - this._renderBorder(e, bgColor); │ │ │ │ │ - } │ │ │ │ │ - if (this._isTopRounded()) { │ │ │ │ │ - this._roundTopCorners(e, color, bgColor); │ │ │ │ │ - } │ │ │ │ │ - if (this._isBottomRounded()) { │ │ │ │ │ - this._roundBottomCorners(e, color, bgColor); │ │ │ │ │ + draw: function(force) { │ │ │ │ │ + if (!force) { │ │ │ │ │ + //clear tile's contents and mark as not drawn │ │ │ │ │ + this.clear(); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - _renderBorder: function(el, bgColor) { │ │ │ │ │ - var borderValue = "1px solid " + this._borderColor(bgColor); │ │ │ │ │ - var borderL = "border-left: " + borderValue; │ │ │ │ │ - var borderR = "border-right: " + borderValue; │ │ │ │ │ - var style = "style='" + borderL + ";" + borderR + "'"; │ │ │ │ │ - el.innerHTML = "
" + el.innerHTML + "
"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - _roundTopCorners: function(el, color, bgColor) { │ │ │ │ │ - var corner = this._createCorner(bgColor); │ │ │ │ │ - for (var i = 0; i < this.options.numSlices; i++) { │ │ │ │ │ - corner.appendChild(this._createCornerSlice(color, bgColor, i, "top")); │ │ │ │ │ + var draw = this.shouldDraw(); │ │ │ │ │ + if (draw && !force && this.events.triggerEvent("beforedraw") === false) { │ │ │ │ │ + draw = null; │ │ │ │ │ } │ │ │ │ │ - el.style.paddingTop = 0; │ │ │ │ │ - el.insertBefore(corner, el.firstChild); │ │ │ │ │ + return draw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _roundBottomCorners: function(el, color, bgColor) { │ │ │ │ │ - var corner = this._createCorner(bgColor); │ │ │ │ │ - for (var i = (this.options.numSlices - 1); i >= 0; i--) { │ │ │ │ │ - corner.appendChild(this._createCornerSlice(color, bgColor, i, "bottom")); │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - el.style.paddingBottom = 0; │ │ │ │ │ - el.appendChild(corner); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - _createCorner: function(bgColor) { │ │ │ │ │ - var corner = document.createElement("div"); │ │ │ │ │ - corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); │ │ │ │ │ - return corner; │ │ │ │ │ + return withinMaxExtent || this.layer.displayOutsideMaxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _createCornerSlice: function(color, bgColor, n, position) { │ │ │ │ │ - var slice = document.createElement("span"); │ │ │ │ │ - │ │ │ │ │ - var inStyle = slice.style; │ │ │ │ │ - inStyle.backgroundColor = color; │ │ │ │ │ - inStyle.display = "block"; │ │ │ │ │ - inStyle.height = "1px"; │ │ │ │ │ - inStyle.overflow = "hidden"; │ │ │ │ │ - inStyle.fontSize = "1px"; │ │ │ │ │ - │ │ │ │ │ - var borderColor = this._borderColor(color, bgColor); │ │ │ │ │ - if (this.options.border && n == 0) { │ │ │ │ │ - inStyle.borderTopStyle = "solid"; │ │ │ │ │ - inStyle.borderTopWidth = "1px"; │ │ │ │ │ - inStyle.borderLeftWidth = "0px"; │ │ │ │ │ - inStyle.borderRightWidth = "0px"; │ │ │ │ │ - inStyle.borderBottomWidth = "0px"; │ │ │ │ │ - inStyle.height = "0px"; // assumes css compliant box model │ │ │ │ │ - inStyle.borderColor = borderColor; │ │ │ │ │ - } else if (borderColor) { │ │ │ │ │ - inStyle.borderColor = borderColor; │ │ │ │ │ - inStyle.borderStyle = "solid"; │ │ │ │ │ - inStyle.borderWidth = "0px 1px"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!this.options.compact && (n == (this.options.numSlices - 1))) { │ │ │ │ │ - inStyle.height = "2px"; │ │ │ │ │ + /** │ │ │ │ │ + * 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._setMargin(slice, n, position); │ │ │ │ │ - this._setBorder(slice, n, position); │ │ │ │ │ - return slice; │ │ │ │ │ + this.bounds = bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _setOptions: function(options) { │ │ │ │ │ - this.options = { │ │ │ │ │ - corners: "all", │ │ │ │ │ - color: "fromElement", │ │ │ │ │ - bgColor: "fromParent", │ │ │ │ │ - blend: true, │ │ │ │ │ - border: false, │ │ │ │ │ - compact: false │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(this.options, options || {}); │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Reposition the tile. │ │ │ │ │ + * │ │ │ │ │ + * 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.options.numSlices = this.options.compact ? 2 : 4; │ │ │ │ │ - if (this._isTransparent()) { │ │ │ │ │ - this.options.blend = false; │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + this.position = position.clone(); │ │ │ │ │ + if (redraw) { │ │ │ │ │ + this.draw(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _whichSideTop: function() { │ │ │ │ │ - if (this._hasString(this.options.corners, "all", "top")) { │ │ │ │ │ - return ""; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0) { │ │ │ │ │ - return ""; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.corners.indexOf("tl") >= 0) { │ │ │ │ │ - return "left"; │ │ │ │ │ - } else if (this.options.corners.indexOf("tr") >= 0) { │ │ │ │ │ - return "right"; │ │ │ │ │ - } │ │ │ │ │ - return ""; │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _whichSideBottom: function() { │ │ │ │ │ - if (this._hasString(this.options.corners, "all", "bottom")) { │ │ │ │ │ - return ""; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.corners.indexOf("bl") >= 0 && this.options.corners.indexOf("br") >= 0) { │ │ │ │ │ - return ""; │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tile" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Util/vendorPrefix.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - if (this.options.corners.indexOf("bl") >= 0) { │ │ │ │ │ - return "left"; │ │ │ │ │ - } else if (this.options.corners.indexOf("br") >= 0) { │ │ │ │ │ - return "right"; │ │ │ │ │ - } │ │ │ │ │ - return ""; │ │ │ │ │ - }, │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - _borderColor: function(color, bgColor) { │ │ │ │ │ - if (color == "transparent") { │ │ │ │ │ - return bgColor; │ │ │ │ │ - } else if (this.options.border) { │ │ │ │ │ - return this.options.border; │ │ │ │ │ - } else if (this.options.blend) { │ │ │ │ │ - return this._blend(bgColor, color); │ │ │ │ │ - } else { │ │ │ │ │ - return ""; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ +OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Util.vendorPrefix │ │ │ │ │ + * A collection of utility functions to detect vendor prefixed features │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Util.vendorPrefix = (function() { │ │ │ │ │ + "use strict"; │ │ │ │ │ │ │ │ │ │ - _setMargin: function(el, n, corners) { │ │ │ │ │ - var marginSize = this._marginSize(n); │ │ │ │ │ - var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); │ │ │ │ │ + var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], │ │ │ │ │ + divStyle = document.createElement("div").style, │ │ │ │ │ + cssCache = {}, │ │ │ │ │ + jsCache = {}; │ │ │ │ │ │ │ │ │ │ - if (whichSide == "left") { │ │ │ │ │ - el.style.marginLeft = marginSize + "px"; │ │ │ │ │ - el.style.marginRight = "0px"; │ │ │ │ │ - } else if (whichSide == "right") { │ │ │ │ │ - el.style.marginRight = marginSize + "px"; │ │ │ │ │ - el.style.marginLeft = "0px"; │ │ │ │ │ - } else { │ │ │ │ │ - el.style.marginLeft = marginSize + "px"; │ │ │ │ │ - el.style.marginRight = marginSize + "px"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - _setBorder: function(el, n, corners) { │ │ │ │ │ - var borderSize = this._borderSize(n); │ │ │ │ │ - var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); │ │ │ │ │ - if (whichSide == "left") { │ │ │ │ │ - el.style.borderLeftWidth = borderSize + "px"; │ │ │ │ │ - el.style.borderRightWidth = "0px"; │ │ │ │ │ - } else if (whichSide == "right") { │ │ │ │ │ - el.style.borderRightWidth = borderSize + "px"; │ │ │ │ │ - el.style.borderLeftWidth = "0px"; │ │ │ │ │ - } else { │ │ │ │ │ - el.style.borderLeftWidth = borderSize + "px"; │ │ │ │ │ - el.style.borderRightWidth = borderSize + "px"; │ │ │ │ │ - } │ │ │ │ │ - if (this.options.border != false) { │ │ │ │ │ - el.style.borderLeftWidth = borderSize + "px"; │ │ │ │ │ - el.style.borderRightWidth = borderSize + "px"; │ │ │ │ │ + /** │ │ │ │ │ + * Function: domToCss │ │ │ │ │ + * Converts a upper camel case DOM style property name to a CSS property │ │ │ │ │ + * i.e. transformOrigin -> transform-origin │ │ │ │ │ + * or WebkitTransformOrigin -> -webkit-transform-origin │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * prefixedDom - {String} The property to convert │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The CSS property │ │ │ │ │ + */ │ │ │ │ │ + function domToCss(prefixedDom) { │ │ │ │ │ + if (!prefixedDom) { │ │ │ │ │ + return null; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + return prefixedDom. │ │ │ │ │ + replace(/([A-Z])/g, function(c) { │ │ │ │ │ + return "-" + c.toLowerCase(); │ │ │ │ │ + }). │ │ │ │ │ + replace(/^ms-/, "-ms-"); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - _marginSize: function(n) { │ │ │ │ │ - if (this._isTransparent()) { │ │ │ │ │ - return 0; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: css │ │ │ │ │ + * Detect which property is used for a CSS property │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ + */ │ │ │ │ │ + function css(property) { │ │ │ │ │ + if (cssCache[property] === undefined) { │ │ │ │ │ + var domProperty = property. │ │ │ │ │ + replace(/(-[\s\S])/g, function(c) { │ │ │ │ │ + return c.charAt(1).toUpperCase(); │ │ │ │ │ + }); │ │ │ │ │ + var prefixedDom = style(domProperty); │ │ │ │ │ + cssCache[property] = domToCss(prefixedDom); │ │ │ │ │ } │ │ │ │ │ - var marginSizes = [5, 3, 2, 1]; │ │ │ │ │ - var blendedMarginSizes = [3, 2, 1, 0]; │ │ │ │ │ - var compactMarginSizes = [2, 1]; │ │ │ │ │ - var smBlendedMarginSizes = [1, 0]; │ │ │ │ │ + return cssCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (this.options.compact && this.options.blend) { │ │ │ │ │ - return smBlendedMarginSizes[n]; │ │ │ │ │ - } else if (this.options.compact) { │ │ │ │ │ - return compactMarginSizes[n]; │ │ │ │ │ - } else if (this.options.blend) { │ │ │ │ │ - return blendedMarginSizes[n]; │ │ │ │ │ - } else { │ │ │ │ │ - return marginSizes[n]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: js │ │ │ │ │ + * Detect which property is used for a JS property/method │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} The object to test on │ │ │ │ │ + * property - {String} The standard (unprefixed) JS property name │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The standard JS property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ + */ │ │ │ │ │ + function js(obj, property) { │ │ │ │ │ + if (jsCache[property] === undefined) { │ │ │ │ │ + var tmpProp, │ │ │ │ │ + i = 0, │ │ │ │ │ + l = VENDOR_PREFIXES.length, │ │ │ │ │ + prefix, │ │ │ │ │ + isStyleObj = (typeof obj.cssText !== "undefined"); │ │ │ │ │ │ │ │ │ │ - _borderSize: function(n) { │ │ │ │ │ - var transparentBorderSizes = [5, 3, 2, 1]; │ │ │ │ │ - var blendedBorderSizes = [2, 1, 1, 1]; │ │ │ │ │ - var compactBorderSizes = [1, 0]; │ │ │ │ │ - var actualBorderSizes = [0, 2, 0, 0]; │ │ │ │ │ + jsCache[property] = null; │ │ │ │ │ + for (; i < l; i++) { │ │ │ │ │ + prefix = VENDOR_PREFIXES[i]; │ │ │ │ │ + if (prefix) { │ │ │ │ │ + if (!isStyleObj) { │ │ │ │ │ + // js prefix should be lower-case, while style │ │ │ │ │ + // properties have upper case on first character │ │ │ │ │ + prefix = prefix.toLowerCase(); │ │ │ │ │ + } │ │ │ │ │ + tmpProp = prefix + property.charAt(0).toUpperCase() + property.slice(1); │ │ │ │ │ + } else { │ │ │ │ │ + tmpProp = property; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (this.options.compact && (this.options.blend || this._isTransparent())) { │ │ │ │ │ - return 1; │ │ │ │ │ - } else if (this.options.compact) { │ │ │ │ │ - return compactBorderSizes[n]; │ │ │ │ │ - } else if (this.options.blend) { │ │ │ │ │ - return blendedBorderSizes[n]; │ │ │ │ │ - } else if (this.options.border) { │ │ │ │ │ - return actualBorderSizes[n]; │ │ │ │ │ - } else if (this._isTransparent()) { │ │ │ │ │ - return transparentBorderSizes[n]; │ │ │ │ │ + if (obj[tmpProp] !== undefined) { │ │ │ │ │ + jsCache[property] = tmpProp; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return 0; │ │ │ │ │ - }, │ │ │ │ │ + return jsCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - _hasString: function(str) { │ │ │ │ │ - for (var i = 1; i < arguments.length; i++) │ │ │ │ │ - if (str.indexOf(arguments[i]) >= 0) { │ │ │ │ │ - return true; │ │ │ │ │ - } return false; │ │ │ │ │ - }, │ │ │ │ │ - _blend: function(c1, c2) { │ │ │ │ │ - var cc1 = OpenLayers.Rico.Color.createFromHex(c1); │ │ │ │ │ - cc1.blend(OpenLayers.Rico.Color.createFromHex(c2)); │ │ │ │ │ - return cc1; │ │ │ │ │ - }, │ │ │ │ │ - _background: function(el) { │ │ │ │ │ - try { │ │ │ │ │ - return OpenLayers.Rico.Color.createColorFromBackground(el).asHex(); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - return "#ffffff"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - _isTransparent: function() { │ │ │ │ │ - return this.options.color == "transparent"; │ │ │ │ │ - }, │ │ │ │ │ - _isTopRounded: function() { │ │ │ │ │ - return this._hasString(this.options.corners, "all", "top", "tl", "tr"); │ │ │ │ │ - }, │ │ │ │ │ - _isBottomRounded: function() { │ │ │ │ │ - return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); │ │ │ │ │ - }, │ │ │ │ │ - _hasSingleTextChild: function(el) { │ │ │ │ │ - return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: style │ │ │ │ │ + * Detect which property is used for a DOM style property │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} The standard (unprefixed) style property name │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The standard style property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ + */ │ │ │ │ │ + function style(property) { │ │ │ │ │ + return js(divStyle, property); │ │ │ │ │ } │ │ │ │ │ -}; │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + css: css, │ │ │ │ │ + js: js, │ │ │ │ │ + style: style, │ │ │ │ │ + │ │ │ │ │ + // used for testing │ │ │ │ │ + cssCache: cssCache, │ │ │ │ │ + jsCache: jsCache │ │ │ │ │ + }; │ │ │ │ │ +}()); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ 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 │ │ │ │ │ @@ -6259,4625 +6168,996 @@ │ │ │ │ │ │ │ │ │ │ OpenLayers.Event.observe(element, 'MSPointerUp', cb); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Events" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Request/XMLHttpRequest.js │ │ │ │ │ + OpenLayers/Animation.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ -// XMLHttpRequest.js Copyright (C) 2010 Sergey Ilinsky (http://www.ilinsky.com) │ │ │ │ │ -// │ │ │ │ │ -// Licensed under the Apache License, Version 2.0 (the "License"); │ │ │ │ │ -// you may not use this file except in compliance with the License. │ │ │ │ │ -// You may obtain a copy of the License at │ │ │ │ │ -// │ │ │ │ │ -// http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ │ -// │ │ │ │ │ -// Unless required by applicable law or agreed to in writing, software │ │ │ │ │ -// distributed under the License is distributed on an "AS IS" BASIS, │ │ │ │ │ -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ │ │ │ -// See the License for the specific language governing permissions and │ │ │ │ │ -// limitations under the License. │ │ │ │ │ +/* 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/Request.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -(function() { │ │ │ │ │ - │ │ │ │ │ - // Save reference to earlier defined object implementation (if any) │ │ │ │ │ - var oXMLHttpRequest = window.XMLHttpRequest; │ │ │ │ │ - │ │ │ │ │ - // Define on browser type │ │ │ │ │ - var bGecko = !!window.controllers, │ │ │ │ │ - bIE = window.document.all && !window.opera, │ │ │ │ │ - bIE7 = bIE && window.navigator.userAgent.match(/MSIE 7.0/); │ │ │ │ │ - │ │ │ │ │ - // Enables "XMLHttpRequest()" call next to "new XMLHttpReques()" │ │ │ │ │ - function fXMLHttpRequest() { │ │ │ │ │ - this._object = oXMLHttpRequest && !bIE7 ? new oXMLHttpRequest : new window.ActiveXObject("Microsoft.XMLHTTP"); │ │ │ │ │ - this._listeners = []; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Constructor │ │ │ │ │ - function cXMLHttpRequest() { │ │ │ │ │ - return new fXMLHttpRequest; │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype = fXMLHttpRequest.prototype; │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Firefox with Firebug installed would break pages if not executed │ │ │ │ │ - if (bGecko && oXMLHttpRequest.wrapped) │ │ │ │ │ - cXMLHttpRequest.wrapped = oXMLHttpRequest.wrapped; │ │ │ │ │ - │ │ │ │ │ - // Constants │ │ │ │ │ - cXMLHttpRequest.UNSENT = 0; │ │ │ │ │ - cXMLHttpRequest.OPENED = 1; │ │ │ │ │ - cXMLHttpRequest.HEADERS_RECEIVED = 2; │ │ │ │ │ - cXMLHttpRequest.LOADING = 3; │ │ │ │ │ - cXMLHttpRequest.DONE = 4; │ │ │ │ │ - │ │ │ │ │ - // Public Properties │ │ │ │ │ - cXMLHttpRequest.prototype.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ - cXMLHttpRequest.prototype.responseText = ''; │ │ │ │ │ - cXMLHttpRequest.prototype.responseXML = null; │ │ │ │ │ - cXMLHttpRequest.prototype.status = 0; │ │ │ │ │ - cXMLHttpRequest.prototype.statusText = ''; │ │ │ │ │ - │ │ │ │ │ - // Priority proposal │ │ │ │ │ - cXMLHttpRequest.prototype.priority = "NORMAL"; │ │ │ │ │ - │ │ │ │ │ - // Instance-level Events Handlers │ │ │ │ │ - cXMLHttpRequest.prototype.onreadystatechange = null; │ │ │ │ │ - │ │ │ │ │ - // Class-level Events Handlers │ │ │ │ │ - cXMLHttpRequest.onreadystatechange = null; │ │ │ │ │ - cXMLHttpRequest.onopen = null; │ │ │ │ │ - cXMLHttpRequest.onsend = null; │ │ │ │ │ - cXMLHttpRequest.onabort = null; │ │ │ │ │ - │ │ │ │ │ - // Public Methods │ │ │ │ │ - cXMLHttpRequest.prototype.open = function(sMethod, sUrl, bAsync, sUser, sPassword) { │ │ │ │ │ - // Delete headers, required when object is reused │ │ │ │ │ - delete this._headers; │ │ │ │ │ - │ │ │ │ │ - // When bAsync parameter value is omitted, use true as default │ │ │ │ │ - if (arguments.length < 3) │ │ │ │ │ - bAsync = true; │ │ │ │ │ - │ │ │ │ │ - // Save async parameter for fixing Gecko bug with missing readystatechange in synchronous requests │ │ │ │ │ - this._async = bAsync; │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Animation │ │ │ │ │ + * A collection of utility functions for executing methods that repaint a │ │ │ │ │ + * portion of the browser window. These methods take advantage of the │ │ │ │ │ + * browser's scheduled repaints where requestAnimationFrame is available. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Animation = (function(window) { │ │ │ │ │ │ │ │ │ │ - // Set the onreadystatechange handler │ │ │ │ │ - var oRequest = this, │ │ │ │ │ - nState = this.readyState, │ │ │ │ │ - fOnUnload; │ │ │ │ │ + /** │ │ │ │ │ + * Property: isNative │ │ │ │ │ + * {Boolean} true if a native requestAnimationFrame function is available │ │ │ │ │ + */ │ │ │ │ │ + var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ + var isNative = !!(requestAnimationFrame); │ │ │ │ │ │ │ │ │ │ - // BUGFIX: IE - memory leak on page unload (inter-page leak) │ │ │ │ │ - if (bIE && bAsync) { │ │ │ │ │ - fOnUnload = function() { │ │ │ │ │ - if (nState != cXMLHttpRequest.DONE) { │ │ │ │ │ - fCleanTransport(oRequest); │ │ │ │ │ - // Safe to abort here since onreadystatechange handler removed │ │ │ │ │ - oRequest.abort(); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Function: requestFrame │ │ │ │ │ + * Schedule a function to be called at the next available animation frame. │ │ │ │ │ + * Uses the native method where available. Where requestAnimationFrame is │ │ │ │ │ + * not available, setTimeout will be called with a 16ms delay. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ + * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ + */ │ │ │ │ │ + var requestFrame = (function() { │ │ │ │ │ + var request = window[requestAnimationFrame] || │ │ │ │ │ + function(callback, element) { │ │ │ │ │ + window.setTimeout(callback, 16); │ │ │ │ │ }; │ │ │ │ │ - window.attachEvent("onunload", fOnUnload); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // Add method sniffer │ │ │ │ │ - if (cXMLHttpRequest.onopen) │ │ │ │ │ - cXMLHttpRequest.onopen.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (arguments.length > 4) │ │ │ │ │ - this._object.open(sMethod, sUrl, bAsync, sUser, sPassword); │ │ │ │ │ - else │ │ │ │ │ - if (arguments.length > 3) │ │ │ │ │ - this._object.open(sMethod, sUrl, bAsync, sUser); │ │ │ │ │ - else │ │ │ │ │ - this._object.open(sMethod, sUrl, bAsync); │ │ │ │ │ - │ │ │ │ │ - this.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ - fReadyStateChange(this); │ │ │ │ │ - │ │ │ │ │ - this._object.onreadystatechange = function() { │ │ │ │ │ - if (bGecko && !bAsync) │ │ │ │ │ - return; │ │ │ │ │ - │ │ │ │ │ - // Synchronize state │ │ │ │ │ - oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Firefox fires unnecessary DONE when aborting │ │ │ │ │ - if (oRequest._aborted) { │ │ │ │ │ - // Reset readyState to UNSENT │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ - │ │ │ │ │ - // Return now │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (oRequest.readyState == cXMLHttpRequest.DONE) { │ │ │ │ │ - // Free up queue │ │ │ │ │ - delete oRequest._data; │ │ │ │ │ - /* if (bAsync) │ │ │ │ │ - fQueue_remove(oRequest);*/ │ │ │ │ │ - // │ │ │ │ │ - fCleanTransport(oRequest); │ │ │ │ │ - // Uncomment this block if you need a fix for IE cache │ │ │ │ │ - /* │ │ │ │ │ - // BUGFIX: IE - cache issue │ │ │ │ │ - if (!oRequest._object.getResponseHeader("Date")) { │ │ │ │ │ - // Save object to cache │ │ │ │ │ - oRequest._cached = oRequest._object; │ │ │ │ │ - │ │ │ │ │ - // Instantiate a new transport object │ │ │ │ │ - cXMLHttpRequest.call(oRequest); │ │ │ │ │ - │ │ │ │ │ - // Re-send request │ │ │ │ │ - if (sUser) { │ │ │ │ │ - if (sPassword) │ │ │ │ │ - oRequest._object.open(sMethod, sUrl, bAsync, sUser, sPassword); │ │ │ │ │ - else │ │ │ │ │ - oRequest._object.open(sMethod, sUrl, bAsync, sUser); │ │ │ │ │ - } │ │ │ │ │ - else │ │ │ │ │ - oRequest._object.open(sMethod, sUrl, bAsync); │ │ │ │ │ - oRequest._object.setRequestHeader("If-Modified-Since", oRequest._cached.getResponseHeader("Last-Modified") || new window.Date(0)); │ │ │ │ │ - // Copy headers set │ │ │ │ │ - if (oRequest._headers) │ │ │ │ │ - for (var sHeader in oRequest._headers) │ │ │ │ │ - if (typeof oRequest._headers[sHeader] == "string") // Some frameworks prototype objects with functions │ │ │ │ │ - oRequest._object.setRequestHeader(sHeader, oRequest._headers[sHeader]); │ │ │ │ │ - │ │ │ │ │ - oRequest._object.onreadystatechange = function() { │ │ │ │ │ - // Synchronize state │ │ │ │ │ - oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ - │ │ │ │ │ - if (oRequest._aborted) { │ │ │ │ │ - // │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ - │ │ │ │ │ - // Return │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (oRequest.readyState == cXMLHttpRequest.DONE) { │ │ │ │ │ - // Clean Object │ │ │ │ │ - fCleanTransport(oRequest); │ │ │ │ │ - │ │ │ │ │ - // get cached request │ │ │ │ │ - if (oRequest.status == 304) │ │ │ │ │ - oRequest._object = oRequest._cached; │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - delete oRequest._cached; │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - fReadyStateChange(oRequest); │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ - if (bIE && bAsync) │ │ │ │ │ - window.detachEvent("onunload", fOnUnload); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - oRequest._object.send(null); │ │ │ │ │ - │ │ │ │ │ - // Return now - wait until re-sent request is finished │ │ │ │ │ - return; │ │ │ │ │ - }; │ │ │ │ │ - */ │ │ │ │ │ - // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ - if (bIE && bAsync) │ │ │ │ │ - window.detachEvent("onunload", fOnUnload); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Some browsers (Internet Explorer, Gecko) fire OPEN readystate twice │ │ │ │ │ - if (nState != oRequest.readyState) │ │ │ │ │ - fReadyStateChange(oRequest); │ │ │ │ │ - │ │ │ │ │ - nState = oRequest.readyState; │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - function fXMLHttpRequest_send(oRequest) { │ │ │ │ │ - oRequest._object.send(oRequest._data); │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Gecko - missing readystatechange calls in synchronous requests │ │ │ │ │ - if (bGecko && !oRequest._async) { │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ - │ │ │ │ │ - // Synchronize state │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ - │ │ │ │ │ - // Simulate missing states │ │ │ │ │ - while (oRequest.readyState < cXMLHttpRequest.DONE) { │ │ │ │ │ - oRequest.readyState++; │ │ │ │ │ - fReadyStateChange(oRequest); │ │ │ │ │ - // Check if we are aborted │ │ │ │ │ - if (oRequest._aborted) │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.send = function(vData) { │ │ │ │ │ - // Add method sniffer │ │ │ │ │ - if (cXMLHttpRequest.onsend) │ │ │ │ │ - cXMLHttpRequest.onsend.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (!arguments.length) │ │ │ │ │ - vData = null; │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Safari - fails sending documents created/modified dynamically, so an explicit serialization required │ │ │ │ │ - // BUGFIX: IE - rewrites any custom mime-type to "text/xml" in case an XMLNode is sent │ │ │ │ │ - // BUGFIX: Gecko - fails sending Element (this is up to the implementation either to standard) │ │ │ │ │ - if (vData && vData.nodeType) { │ │ │ │ │ - vData = window.XMLSerializer ? new window.XMLSerializer().serializeToString(vData) : vData.xml; │ │ │ │ │ - if (!this._headers["Content-Type"]) │ │ │ │ │ - this._object.setRequestHeader("Content-Type", "application/xml"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this._data = vData; │ │ │ │ │ - /* │ │ │ │ │ - // Add to queue │ │ │ │ │ - if (this._async) │ │ │ │ │ - fQueue_add(this); │ │ │ │ │ - else*/ │ │ │ │ │ - fXMLHttpRequest_send(this); │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.abort = function() { │ │ │ │ │ - // Add method sniffer │ │ │ │ │ - if (cXMLHttpRequest.onabort) │ │ │ │ │ - cXMLHttpRequest.onabort.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: Gecko - unnecessary DONE when aborting │ │ │ │ │ - if (this.readyState > cXMLHttpRequest.UNSENT) │ │ │ │ │ - this._aborted = true; │ │ │ │ │ - │ │ │ │ │ - this._object.abort(); │ │ │ │ │ - │ │ │ │ │ - // BUGFIX: IE - memory leak │ │ │ │ │ - fCleanTransport(this); │ │ │ │ │ - │ │ │ │ │ - this.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ - │ │ │ │ │ - delete this._data; │ │ │ │ │ - /* if (this._async) │ │ │ │ │ - fQueue_remove(this);*/ │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.getAllResponseHeaders = function() { │ │ │ │ │ - return this._object.getAllResponseHeaders(); │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.getResponseHeader = function(sName) { │ │ │ │ │ - return this._object.getResponseHeader(sName); │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.setRequestHeader = function(sName, sValue) { │ │ │ │ │ - // BUGFIX: IE - cache issue │ │ │ │ │ - if (!this._headers) │ │ │ │ │ - this._headers = {}; │ │ │ │ │ - this._headers[sName] = sValue; │ │ │ │ │ - │ │ │ │ │ - return this._object.setRequestHeader(sName, sValue); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // EventTarget interface implementation │ │ │ │ │ - cXMLHttpRequest.prototype.addEventListener = function(sName, fHandler, bUseCapture) { │ │ │ │ │ - for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ - if (oListener[0] == sName && oListener[1] == fHandler && oListener[2] == bUseCapture) │ │ │ │ │ - return; │ │ │ │ │ - // Add listener │ │ │ │ │ - this._listeners.push([sName, fHandler, bUseCapture]); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - cXMLHttpRequest.prototype.removeEventListener = function(sName, fHandler, bUseCapture) { │ │ │ │ │ - for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ - if (oListener[0] == sName && oListener[1] == fHandler && oListener[2] == bUseCapture) │ │ │ │ │ - break; │ │ │ │ │ - // Remove listener │ │ │ │ │ - if (oListener) │ │ │ │ │ - this._listeners.splice(nIndex, 1); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - cXMLHttpRequest.prototype.dispatchEvent = function(oEvent) { │ │ │ │ │ - var oEventPseudo = { │ │ │ │ │ - 'type': oEvent.type, │ │ │ │ │ - 'target': this, │ │ │ │ │ - 'currentTarget': this, │ │ │ │ │ - 'eventPhase': 2, │ │ │ │ │ - 'bubbles': oEvent.bubbles, │ │ │ │ │ - 'cancelable': oEvent.cancelable, │ │ │ │ │ - 'timeStamp': oEvent.timeStamp, │ │ │ │ │ - 'stopPropagation': function() {}, // There is no flow │ │ │ │ │ - 'preventDefault': function() {}, // There is no default action │ │ │ │ │ - 'initEvent': function() {} // Original event object should be initialized │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Execute onreadystatechange │ │ │ │ │ - if (oEventPseudo.type == "readystatechange" && this.onreadystatechange) │ │ │ │ │ - (this.onreadystatechange.handleEvent || this.onreadystatechange).apply(this, [oEventPseudo]); │ │ │ │ │ - │ │ │ │ │ - // Execute listeners │ │ │ │ │ - for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ - if (oListener[0] == oEventPseudo.type && !oListener[2]) │ │ │ │ │ - (oListener[1].handleEvent || oListener[1]).apply(this, [oEventPseudo]); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - cXMLHttpRequest.prototype.toString = function() { │ │ │ │ │ - return '[' + "object" + ' ' + "XMLHttpRequest" + ']'; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - cXMLHttpRequest.toString = function() { │ │ │ │ │ - return '[' + "XMLHttpRequest" + ']'; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Helper function │ │ │ │ │ - function fReadyStateChange(oRequest) { │ │ │ │ │ - // Sniffing code │ │ │ │ │ - if (cXMLHttpRequest.onreadystatechange) │ │ │ │ │ - cXMLHttpRequest.onreadystatechange.apply(oRequest); │ │ │ │ │ - │ │ │ │ │ - // Fake event │ │ │ │ │ - oRequest.dispatchEvent({ │ │ │ │ │ - 'type': "readystatechange", │ │ │ │ │ - 'bubbles': false, │ │ │ │ │ - 'cancelable': false, │ │ │ │ │ - 'timeStamp': new Date + 0 │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - function fGetDocument(oRequest) { │ │ │ │ │ - var oDocument = oRequest.responseXML, │ │ │ │ │ - sResponse = oRequest.responseText; │ │ │ │ │ - // Try parsing responseText │ │ │ │ │ - if (bIE && sResponse && oDocument && !oDocument.documentElement && oRequest.getResponseHeader("Content-Type").match(/[^\/]+\/[^\+]+\+xml/)) { │ │ │ │ │ - oDocument = new window.ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ - oDocument.async = false; │ │ │ │ │ - oDocument.validateOnParse = false; │ │ │ │ │ - oDocument.loadXML(sResponse); │ │ │ │ │ - } │ │ │ │ │ - // Check if there is no error in document │ │ │ │ │ - if (oDocument) │ │ │ │ │ - if ((bIE && oDocument.parseError != 0) || !oDocument.documentElement || (oDocument.documentElement && oDocument.documentElement.tagName == "parsererror")) │ │ │ │ │ - return null; │ │ │ │ │ - return oDocument; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - function fSynchronizeValues(oRequest) { │ │ │ │ │ - try { │ │ │ │ │ - oRequest.responseText = oRequest._object.responseText; │ │ │ │ │ - } catch (e) {} │ │ │ │ │ - try { │ │ │ │ │ - oRequest.responseXML = fGetDocument(oRequest._object); │ │ │ │ │ - } catch (e) {} │ │ │ │ │ - try { │ │ │ │ │ - oRequest.status = oRequest._object.status; │ │ │ │ │ - } catch (e) {} │ │ │ │ │ - try { │ │ │ │ │ - oRequest.statusText = oRequest._object.statusText; │ │ │ │ │ - } catch (e) {} │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - function fCleanTransport(oRequest) { │ │ │ │ │ - // BUGFIX: IE - memory leak (on-page leak) │ │ │ │ │ - oRequest._object.onreadystatechange = new window.Function; │ │ │ │ │ - }; │ │ │ │ │ - /* │ │ │ │ │ - // Queue manager │ │ │ │ │ - var oQueuePending = {"CRITICAL":[],"HIGH":[],"NORMAL":[],"LOW":[],"LOWEST":[]}, │ │ │ │ │ - aQueueRunning = []; │ │ │ │ │ - function fQueue_add(oRequest) { │ │ │ │ │ - oQueuePending[oRequest.priority in oQueuePending ? oRequest.priority : "NORMAL"].push(oRequest); │ │ │ │ │ - // │ │ │ │ │ - setTimeout(fQueue_process); │ │ │ │ │ + // bind to window to avoid illegal invocation of native function │ │ │ │ │ + return function(callback, element) { │ │ │ │ │ + request.apply(window, [callback, element]); │ │ │ │ │ }; │ │ │ │ │ + })(); │ │ │ │ │ │ │ │ │ │ - function fQueue_remove(oRequest) { │ │ │ │ │ - for (var nIndex = 0, bFound = false; nIndex < aQueueRunning.length; nIndex++) │ │ │ │ │ - if (bFound) │ │ │ │ │ - aQueueRunning[nIndex - 1] = aQueueRunning[nIndex]; │ │ │ │ │ - else │ │ │ │ │ - if (aQueueRunning[nIndex] == oRequest) │ │ │ │ │ - bFound = true; │ │ │ │ │ - if (bFound) │ │ │ │ │ - aQueueRunning.length--; │ │ │ │ │ - // │ │ │ │ │ - setTimeout(fQueue_process); │ │ │ │ │ - }; │ │ │ │ │ + // private variables for animation loops │ │ │ │ │ + var counter = 0; │ │ │ │ │ + var loops = {}; │ │ │ │ │ │ │ │ │ │ - function fQueue_process() { │ │ │ │ │ - if (aQueueRunning.length < 6) { │ │ │ │ │ - for (var sPriority in oQueuePending) { │ │ │ │ │ - if (oQueuePending[sPriority].length) { │ │ │ │ │ - var oRequest = oQueuePending[sPriority][0]; │ │ │ │ │ - oQueuePending[sPriority] = oQueuePending[sPriority].slice(1); │ │ │ │ │ - // │ │ │ │ │ - aQueueRunning.push(oRequest); │ │ │ │ │ - // Send request │ │ │ │ │ - fXMLHttpRequest_send(oRequest); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Function: start │ │ │ │ │ + * Executes a method with in series for some │ │ │ │ │ + * duration. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ + * duration - {Number} Optional duration for the loop. If not provided, the │ │ │ │ │ + * animation loop will execute indefinitely. │ │ │ │ │ + * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} Identifier for the animation loop. Used to stop animations with │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + function start(callback, duration, element) { │ │ │ │ │ + duration = duration > 0 ? duration : Number.POSITIVE_INFINITY; │ │ │ │ │ + var id = ++counter; │ │ │ │ │ + var start = +new Date; │ │ │ │ │ + loops[id] = function() { │ │ │ │ │ + if (loops[id] && +new Date - start <= duration) { │ │ │ │ │ + callback(); │ │ │ │ │ + if (loops[id]) { │ │ │ │ │ + requestFrame(loops[id], element); │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + delete loops[id]; │ │ │ │ │ } │ │ │ │ │ }; │ │ │ │ │ - */ │ │ │ │ │ - // Internet Explorer 5.0 (missing apply) │ │ │ │ │ - if (!window.Function.prototype.apply) { │ │ │ │ │ - window.Function.prototype.apply = function(oRequest, oArguments) { │ │ │ │ │ - if (!oArguments) │ │ │ │ │ - oArguments = []; │ │ │ │ │ - oRequest.__func = this; │ │ │ │ │ - oRequest.__func(oArguments[0], oArguments[1], oArguments[2], oArguments[3], oArguments[4]); │ │ │ │ │ - delete oRequest.__func; │ │ │ │ │ - }; │ │ │ │ │ - }; │ │ │ │ │ + requestFrame(loops[id], element); │ │ │ │ │ + return id; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // Register new object with window │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Request.XMLHttpRequest │ │ │ │ │ - * Standard-compliant (W3C) cross-browser implementation of the │ │ │ │ │ - * XMLHttpRequest object. From │ │ │ │ │ - * http://code.google.com/p/xmlhttprequest/. │ │ │ │ │ + * Function: stop │ │ │ │ │ + * Terminates an animation loop started with . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {Number} Identifier returned from . │ │ │ │ │ */ │ │ │ │ │ - if (!OpenLayers.Request) { │ │ │ │ │ - /** │ │ │ │ │ - * This allows for OpenLayers/Request.js to be included │ │ │ │ │ - * before or after this script. │ │ │ │ │ - */ │ │ │ │ │ - OpenLayers.Request = {}; │ │ │ │ │ + function stop(id) { │ │ │ │ │ + delete loops[id]; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Request.XMLHttpRequest = cXMLHttpRequest; │ │ │ │ │ -})(); │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + isNative: isNative, │ │ │ │ │ + requestFrame: requestFrame, │ │ │ │ │ + start: start, │ │ │ │ │ + stop: stop │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ +})(window); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Request.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/Events.js │ │ │ │ │ - * @requires OpenLayers/Request/XMLHttpRequest.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * TODO: deprecate me │ │ │ │ │ - * Use OpenLayers.Request.proxy instead. │ │ │ │ │ + * Namespace: OpenLayers.Tween │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.ProxyHost = ""; │ │ │ │ │ +OpenLayers.Tween = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Request │ │ │ │ │ - * The OpenLayers.Request namespace contains convenience methods for working │ │ │ │ │ - * with XMLHttpRequests. These methods work with a cross-browser │ │ │ │ │ - * W3C compliant class. │ │ │ │ │ - */ │ │ │ │ │ -if (!OpenLayers.Request) { │ │ │ │ │ /** │ │ │ │ │ - * This allows for OpenLayers/Request/XMLHttpRequest.js to be included │ │ │ │ │ - * before or after this script. │ │ │ │ │ + * APIProperty: easing │ │ │ │ │ + * {(Function)} Easing equation used for the animation │ │ │ │ │ + * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ */ │ │ │ │ │ - OpenLayers.Request = {}; │ │ │ │ │ -} │ │ │ │ │ -OpenLayers.Util.extend(OpenLayers.Request, { │ │ │ │ │ + easing: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_CONFIG │ │ │ │ │ - * {Object} Default configuration for all requests. │ │ │ │ │ + * APIProperty: begin │ │ │ │ │ + * {Object} Values to start the animation with │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_CONFIG: { │ │ │ │ │ - method: "GET", │ │ │ │ │ - url: window.location.href, │ │ │ │ │ - async: true, │ │ │ │ │ - user: undefined, │ │ │ │ │ - password: undefined, │ │ │ │ │ - params: null, │ │ │ │ │ - proxy: OpenLayers.ProxyHost, │ │ │ │ │ - headers: {}, │ │ │ │ │ - data: null, │ │ │ │ │ - callback: function() {}, │ │ │ │ │ - success: null, │ │ │ │ │ - failure: null, │ │ │ │ │ - scope: null │ │ │ │ │ - }, │ │ │ │ │ + begin: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: URL_SPLIT_REGEX │ │ │ │ │ + * APIProperty: finish │ │ │ │ │ + * {Object} Values to finish the animation with │ │ │ │ │ */ │ │ │ │ │ - URL_SPLIT_REGEX: /([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/, │ │ │ │ │ + finish: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the {} object. │ │ │ │ │ - * │ │ │ │ │ - * All event listeners will receive an event object with three properties: │ │ │ │ │ - * request - {} The request object. │ │ │ │ │ - * config - {Object} The config object sent to the specific request method. │ │ │ │ │ - * requestUrl - {String} The request url. │ │ │ │ │ - * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * complete - Triggered when we have a response from the request, if a │ │ │ │ │ - * listener returns false, no further response processing will take │ │ │ │ │ - * place. │ │ │ │ │ - * success - Triggered when the HTTP response has a success code (200-299). │ │ │ │ │ - * failure - Triggered when the HTTP response does not have a success code. │ │ │ │ │ + * APIProperty: duration │ │ │ │ │ + * {int} duration of the tween (number of steps) │ │ │ │ │ */ │ │ │ │ │ - events: new OpenLayers.Events(this), │ │ │ │ │ + duration: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: makeSameOrigin │ │ │ │ │ - * Using the specified proxy, returns a same origin url of the provided url. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} An arbitrary url │ │ │ │ │ - * proxy {String|Function} The proxy to use to make the provided url a │ │ │ │ │ - * same origin url. │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {String} the same origin url. If no proxy is provided, the returned url │ │ │ │ │ - * will be the same as the provided url. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - makeSameOrigin: function(url, proxy) { │ │ │ │ │ - var sameOrigin = url.indexOf("http") !== 0; │ │ │ │ │ - var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX); │ │ │ │ │ - if (urlParts) { │ │ │ │ │ - var location = window.location; │ │ │ │ │ - sameOrigin = │ │ │ │ │ - urlParts[1] == location.protocol && │ │ │ │ │ - urlParts[3] == location.hostname; │ │ │ │ │ - var uPort = urlParts[4], │ │ │ │ │ - lPort = location.port; │ │ │ │ │ - if (uPort != 80 && uPort != "" || lPort != "80" && lPort != "") { │ │ │ │ │ - sameOrigin = sameOrigin && uPort == lPort; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!sameOrigin) { │ │ │ │ │ - if (proxy) { │ │ │ │ │ - if (typeof proxy == "function") { │ │ │ │ │ - url = proxy(url); │ │ │ │ │ - } else { │ │ │ │ │ - url = proxy + encodeURIComponent(url); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return url; │ │ │ │ │ - }, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: issue │ │ │ │ │ - * Create a new XMLHttpRequest object, open it, set any headers, bind │ │ │ │ │ - * a callback to done state, and send any data. It is recommended that │ │ │ │ │ - * you use one , , , , , or . │ │ │ │ │ - * This method is only documented to provide detail on the configuration │ │ │ │ │ - * options available to all request methods. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Object containing properties for configuring the │ │ │ │ │ - * request. Allowed configuration properties are described below. │ │ │ │ │ - * This object is modified and should not be reused. │ │ │ │ │ - * │ │ │ │ │ - * Allowed config properties: │ │ │ │ │ - * method - {String} One of GET, POST, PUT, DELETE, HEAD, or │ │ │ │ │ - * OPTIONS. Default is GET. │ │ │ │ │ - * url - {String} URL for the request. │ │ │ │ │ - * async - {Boolean} Open an asynchronous request. Default is true. │ │ │ │ │ - * user - {String} User for relevant authentication scheme. Set │ │ │ │ │ - * to null to clear current user. │ │ │ │ │ - * password - {String} Password for relevant authentication scheme. │ │ │ │ │ - * Set to null to clear current password. │ │ │ │ │ - * proxy - {String} Optional proxy. Defaults to │ │ │ │ │ - * . │ │ │ │ │ - * params - {Object} Any key:value pairs to be appended to the │ │ │ │ │ - * url as a query string. Assumes url doesn't already include a query │ │ │ │ │ - * string or hash. Typically, this is only appropriate for │ │ │ │ │ - * requests where the query string will be appended to the url. │ │ │ │ │ - * Parameter values that are arrays will be │ │ │ │ │ - * concatenated with a comma (note that this goes against form-encoding) │ │ │ │ │ - * as is done with . │ │ │ │ │ - * headers - {Object} Object with header:value pairs to be set on │ │ │ │ │ - * the request. │ │ │ │ │ - * data - {String | Document} Optional data to send with the request. │ │ │ │ │ - * Typically, this is only used with and requests. │ │ │ │ │ - * Make sure to provide the appropriate "Content-Type" header for your │ │ │ │ │ - * data. For and requests, the content type defaults to │ │ │ │ │ - * "application-xml". If your data is a different content type, or │ │ │ │ │ - * if you are using a different HTTP method, set the "Content-Type" │ │ │ │ │ - * header to match your data type. │ │ │ │ │ - * callback - {Function} Function to call when request is done. │ │ │ │ │ - * To determine if the request failed, check request.status (200 │ │ │ │ │ - * indicates success). │ │ │ │ │ - * success - {Function} Optional function to call if request status is in │ │ │ │ │ - * the 200s. This will be called in addition to callback above and │ │ │ │ │ - * would typically only be used as an alternative. │ │ │ │ │ - * failure - {Function} Optional function to call if request status is not │ │ │ │ │ - * in the 200s. This will be called in addition to callback above and │ │ │ │ │ - * would typically only be used as an alternative. │ │ │ │ │ - * scope - {Object} If callback is a public method on some object, │ │ │ │ │ - * set the scope to that object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. To abort the request before a response │ │ │ │ │ - * is received, call abort() on the request object. │ │ │ │ │ + * Property: time │ │ │ │ │ + * {int} Step counter │ │ │ │ │ */ │ │ │ │ │ - issue: function(config) { │ │ │ │ │ - // apply default config - proxy host may have changed │ │ │ │ │ - var defaultConfig = OpenLayers.Util.extend( │ │ │ │ │ - this.DEFAULT_CONFIG, { │ │ │ │ │ - proxy: OpenLayers.ProxyHost │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - config = config || {}; │ │ │ │ │ - config.headers = config.headers || {}; │ │ │ │ │ - config = OpenLayers.Util.applyDefaults(config, defaultConfig); │ │ │ │ │ - config.headers = OpenLayers.Util.applyDefaults(config.headers, defaultConfig.headers); │ │ │ │ │ - // Always set the "X-Requested-With" header to signal that this request │ │ │ │ │ - // was issued through the XHR-object. Since header keys are case │ │ │ │ │ - // insensitive and we want to allow overriding of the "X-Requested-With" │ │ │ │ │ - // header through the user we cannot use applyDefaults, but have to │ │ │ │ │ - // check manually whether we were called with a "X-Requested-With" │ │ │ │ │ - // header. │ │ │ │ │ - var customRequestedWithHeader = false, │ │ │ │ │ - headerKey; │ │ │ │ │ - for (headerKey in config.headers) { │ │ │ │ │ - if (config.headers.hasOwnProperty(headerKey)) { │ │ │ │ │ - if (headerKey.toLowerCase() === 'x-requested-with') { │ │ │ │ │ - customRequestedWithHeader = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (customRequestedWithHeader === false) { │ │ │ │ │ - // we did not have a custom "X-Requested-With" header │ │ │ │ │ - config.headers['X-Requested-With'] = 'XMLHttpRequest'; │ │ │ │ │ - } │ │ │ │ │ + time: null, │ │ │ │ │ │ │ │ │ │ - // create request, open, and set headers │ │ │ │ │ - var request = new OpenLayers.Request.XMLHttpRequest(); │ │ │ │ │ - var url = OpenLayers.Util.urlAppend(config.url, │ │ │ │ │ - OpenLayers.Util.getParameterString(config.params || {})); │ │ │ │ │ - url = OpenLayers.Request.makeSameOrigin(url, config.proxy); │ │ │ │ │ - request.open( │ │ │ │ │ - config.method, url, config.async, config.user, config.password │ │ │ │ │ - ); │ │ │ │ │ - for (var header in config.headers) { │ │ │ │ │ - request.setRequestHeader(header, config.headers[header]); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + minFrameRate: null, │ │ │ │ │ │ │ │ │ │ - var events = this.events; │ │ │ │ │ + /** │ │ │ │ │ + * Property: startTime │ │ │ │ │ + * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ + * frames │ │ │ │ │ + */ │ │ │ │ │ + startTime: null, │ │ │ │ │ │ │ │ │ │ - // we want to execute runCallbacks with "this" as the │ │ │ │ │ - // execution scope │ │ │ │ │ - var self = this; │ │ │ │ │ + /** │ │ │ │ │ + * Property: animationId │ │ │ │ │ + * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ + */ │ │ │ │ │ + animationId: null, │ │ │ │ │ │ │ │ │ │ - request.onreadystatechange = function() { │ │ │ │ │ - if (request.readyState == OpenLayers.Request.XMLHttpRequest.DONE) { │ │ │ │ │ - var proceed = events.triggerEvent( │ │ │ │ │ - "complete", { │ │ │ │ │ - request: request, │ │ │ │ │ - config: config, │ │ │ │ │ - requestUrl: url │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - if (proceed !== false) { │ │ │ │ │ - self.runCallbacks({ │ │ │ │ │ - request: request, │ │ │ │ │ - config: config, │ │ │ │ │ - requestUrl: url │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Property: playing │ │ │ │ │ + * {Boolean} Tells if the easing is currently playing │ │ │ │ │ + */ │ │ │ │ │ + playing: false, │ │ │ │ │ │ │ │ │ │ - // send request (optionally with data) and return │ │ │ │ │ - // call in a timeout for asynchronous requests so the return is │ │ │ │ │ - // available before readyState == 4 for cached docs │ │ │ │ │ - if (config.async === false) { │ │ │ │ │ - request.send(config.data); │ │ │ │ │ - } else { │ │ │ │ │ - window.setTimeout(function() { │ │ │ │ │ - if (request.readyState !== 0) { // W3C: 0-UNSENT │ │ │ │ │ - request.send(config.data); │ │ │ │ │ - } │ │ │ │ │ - }, 0); │ │ │ │ │ - } │ │ │ │ │ - return request; │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tween │ │ │ │ │ + * Creates a Tween. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * easing - {(Function)} easing function method to use │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(easing) { │ │ │ │ │ + this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: runCallbacks │ │ │ │ │ - * Calls the complete, success and failure callbacks. Application │ │ │ │ │ - * can listen to the "complete" event, have the listener │ │ │ │ │ - * display a confirm window and always return false, and │ │ │ │ │ - * execute OpenLayers.Request.runCallbacks if the user │ │ │ │ │ - * hits "yes" in the confirm window. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: start │ │ │ │ │ + * Plays the Tween, and calls the callback method on each step │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Hash containing request, config and requestUrl keys │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - runCallbacks: function(options) { │ │ │ │ │ - var request = options.request; │ │ │ │ │ - var config = options.config; │ │ │ │ │ - │ │ │ │ │ - // bind callbacks to readyState 4 (done) │ │ │ │ │ - var complete = (config.scope) ? │ │ │ │ │ - OpenLayers.Function.bind(config.callback, config.scope) : │ │ │ │ │ - config.callback; │ │ │ │ │ - │ │ │ │ │ - // optional success callback │ │ │ │ │ - var success; │ │ │ │ │ - if (config.success) { │ │ │ │ │ - success = (config.scope) ? │ │ │ │ │ - OpenLayers.Function.bind(config.success, config.scope) : │ │ │ │ │ - config.success; │ │ │ │ │ + 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) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // optional failure callback │ │ │ │ │ - var failure; │ │ │ │ │ - if (config.failure) { │ │ │ │ │ - failure = (config.scope) ? │ │ │ │ │ - OpenLayers.Function.bind(config.failure, config.scope) : │ │ │ │ │ - config.failure; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: stop │ │ │ │ │ + * Stops the Tween, and calls the done callback │ │ │ │ │ + * Doesn't do anything if animation is already finished │ │ │ │ │ + */ │ │ │ │ │ + stop: function() { │ │ │ │ │ + if (!this.playing) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (OpenLayers.Util.createUrlObject(config.url).protocol == "file:" && │ │ │ │ │ - request.responseText) { │ │ │ │ │ - request.status = 200; │ │ │ │ │ + if (this.callbacks && this.callbacks.done) { │ │ │ │ │ + this.callbacks.done.call(this, this.finish); │ │ │ │ │ } │ │ │ │ │ - complete(request); │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + this.playing = false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (!request.status || (request.status >= 200 && request.status < 300)) { │ │ │ │ │ - this.events.triggerEvent("success", options); │ │ │ │ │ - if (success) { │ │ │ │ │ - success(request); │ │ │ │ │ + /** │ │ │ │ │ + * Method: play │ │ │ │ │ + * Calls the appropriate easing method │ │ │ │ │ + */ │ │ │ │ │ + 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]); │ │ │ │ │ } │ │ │ │ │ - if (request.status && (request.status < 200 || request.status >= 300)) { │ │ │ │ │ - this.events.triggerEvent("failure", options); │ │ │ │ │ - if (failure) { │ │ │ │ │ - failure(request); │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: GET │ │ │ │ │ - * Send an HTTP GET request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to GET. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. │ │ │ │ │ - * This object is modified and should not be reused. │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - GET: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "GET" │ │ │ │ │ - }); │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: POST │ │ │ │ │ - * Send a POST request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to POST and "Content-Type" header set to "application/xml". │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. The │ │ │ │ │ - * default "Content-Type" header will be set to "application-xml" if │ │ │ │ │ - * none is provided. This object is modified and should not be reused. │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - POST: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "POST" │ │ │ │ │ - }); │ │ │ │ │ - // set content type to application/xml if it isn't already set │ │ │ │ │ - config.headers = config.headers ? config.headers : {}; │ │ │ │ │ - if (!("CONTENT-TYPE" in OpenLayers.Util.upperCaseObject(config.headers))) { │ │ │ │ │ - config.headers["Content-Type"] = "application/xml"; │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: PUT │ │ │ │ │ - * Send an HTTP PUT request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to PUT and "Content-Type" header set to "application/xml". │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. The │ │ │ │ │ - * default "Content-Type" header will be set to "application-xml" if │ │ │ │ │ - * none is provided. This object is modified and should not be reused. │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - PUT: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "PUT" │ │ │ │ │ - }); │ │ │ │ │ - // set content type to application/xml if it isn't already set │ │ │ │ │ - config.headers = config.headers ? config.headers : {}; │ │ │ │ │ - if (!("CONTENT-TYPE" in OpenLayers.Util.upperCaseObject(config.headers))) { │ │ │ │ │ - config.headers["Content-Type"] = "application/xml"; │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ + easeInOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing.Expo = { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: DELETE │ │ │ │ │ - * Send an HTTP DELETE request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to DELETE. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. │ │ │ │ │ - * This object is modified and should not be reused. │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - DELETE: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "DELETE" │ │ │ │ │ - }); │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: HEAD │ │ │ │ │ - * Send an HTTP HEAD request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to HEAD. │ │ │ │ │ - * │ │ │ │ │ + * Function: easeOut │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. │ │ │ │ │ - * This object is modified and should not be reused. │ │ │ │ │ + * 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 (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - HEAD: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "HEAD" │ │ │ │ │ - }); │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ + 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 = { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: OPTIONS │ │ │ │ │ - * Send an HTTP OPTIONS request. Additional configuration properties are │ │ │ │ │ - * documented in the method, with the method property set │ │ │ │ │ - * to OPTIONS. │ │ │ │ │ + * Function: easeIn │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * (t /= d) * t + b; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeOut │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} Object with properties for configuring the request. │ │ │ │ │ - * See the method for documentation of allowed properties. │ │ │ │ │ - * This object is modified and should not be reused. │ │ │ │ │ + * 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) * (t - 2) + b; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {XMLHttpRequest} Request object. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - OPTIONS: function(config) { │ │ │ │ │ - config = OpenLayers.Util.extend(config, { │ │ │ │ │ - method: "OPTIONS" │ │ │ │ │ - }); │ │ │ │ │ - return OpenLayers.Request.issue(config); │ │ │ │ │ - } │ │ │ │ │ + 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/Feature.js │ │ │ │ │ + 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 │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Feature │ │ │ │ │ - * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ - * class specifically combines a marker and a lonlat. │ │ │ │ │ + * 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.Feature = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: data │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - data: null, │ │ │ │ │ +OpenLayers.Projection = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: marker │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: proj │ │ │ │ │ + * {Object} Proj4js.Proj instance. │ │ │ │ │ */ │ │ │ │ │ - marker: null, │ │ │ │ │ + proj: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: popupClass │ │ │ │ │ - * {} The class which will be used to instantiate │ │ │ │ │ - * a new Popup. Default is . │ │ │ │ │ + * Property: projCode │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - popupClass: null, │ │ │ │ │ + projCode: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: popup │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: titleRegEx │ │ │ │ │ + * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ */ │ │ │ │ │ - popup: null, │ │ │ │ │ + titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature │ │ │ │ │ - * Constructor for features. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Projection │ │ │ │ │ + * This class offers several methods for interacting with a wrapped │ │ │ │ │ + * pro4js projection object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * data - {Object} │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ + * {} A projection object. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + initialize: function(projCode, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.projCode = projCode; │ │ │ │ │ + if (typeof Proj4js == "object") { │ │ │ │ │ + this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getCode │ │ │ │ │ + * Get the string SRS code. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ - * (based on its 'lonlat' property) │ │ │ │ │ + * {String} The SRS code. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getCode: function() { │ │ │ │ │ + return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ + * APIMethod: getUnits │ │ │ │ │ + * Get the units string for the projection -- returns null if │ │ │ │ │ + * proj4js is not available. │ │ │ │ │ * │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ - } │ │ │ │ │ - return this.marker; │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + return this.proj ? this.proj.units : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * Destroys marker. │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Convert projection to string (getCode wrapper). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The projection code. │ │ │ │ │ */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - this.marker.destroy(); │ │ │ │ │ + toString: function() { │ │ │ │ │ + return this.getCode(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: equals │ │ │ │ │ + * Test equality of two projection instances. Determines equality based │ │ │ │ │ + * soley on the projection code. │ │ │ │ │ * │ │ │ │ │ - * 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 . │ │ │ │ │ - * │ │ │ │ │ + * {Boolean} The two projections are equivalent. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + equals: function(projection) { │ │ │ │ │ + var p = projection, │ │ │ │ │ + equals = false; │ │ │ │ │ + if (p) { │ │ │ │ │ + if (!(p instanceof OpenLayers.Projection)) { │ │ │ │ │ + p = new OpenLayers.Projection(p); │ │ │ │ │ } │ │ │ │ │ - if (this.data.overflow != null) { │ │ │ │ │ - this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.popup.feature = this; │ │ │ │ │ } │ │ │ │ │ - return this.popup; │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ + /* Method: destroy │ │ │ │ │ + * Destroy projection object. │ │ │ │ │ */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - if (this.popup) { │ │ │ │ │ - this.popup.feature = null; │ │ │ │ │ - this.popup.destroy(); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + delete this.proj; │ │ │ │ │ + delete this.projCode; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Projection" │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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. */ │ │ │ │ │ +/** │ │ │ │ │ + * 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 = {}; │ │ │ │ │ │ │ │ │ │ -// TRASH THIS │ │ │ │ │ -OpenLayers.State = { │ │ │ │ │ - /** states */ │ │ │ │ │ - UNKNOWN: 'Unknown', │ │ │ │ │ - INSERT: 'Insert', │ │ │ │ │ - UPDATE: 'Update', │ │ │ │ │ - DELETE: 'Delete' │ │ │ │ │ +/** │ │ │ │ │ + * 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] │ │ │ │ │ + } │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Feature.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ + * 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Transform a point coordinate from one projection to another. Note that │ │ │ │ │ + * the input point is transformed in place. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ +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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: fid │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - fid: null, │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometry │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - geometry: null, │ │ │ │ │ +/** │ │ │ │ │ + * 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() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: attributes │ │ │ │ │ - * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ - * describe the feature. │ │ │ │ │ - */ │ │ │ │ │ - attributes: null, │ │ │ │ │ + var pole = 20037508.34; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: state │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - state: null, │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - style: null, │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} If this property is set it will be taken into account by │ │ │ │ │ - * {} when upadting or deleting the feature. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ + // 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({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: renderIntent │ │ │ │ │ - * {String} rendering intent currently being used │ │ │ │ │ + * Constant: Z_INDEX_BASE │ │ │ │ │ + * {Object} Base z-indexes for different classes of thing │ │ │ │ │ */ │ │ │ │ │ - renderIntent: "default", │ │ │ │ │ + Z_INDEX_BASE: { │ │ │ │ │ + BaseLayer: 100, │ │ │ │ │ + Overlay: 325, │ │ │ │ │ + Feature: 725, │ │ │ │ │ + Popup: 750, │ │ │ │ │ + Control: 1000 │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ * (code) │ │ │ │ │ - * { │ │ │ │ │ - * geometry: >Object │ │ │ │ │ - * } │ │ │ │ │ + * map.events.register(type, obj, listener); │ │ │ │ │ * (end) │ │ │ │ │ * │ │ │ │ │ - * When an application has made changes to feature attributes, it could │ │ │ │ │ - * have set the attributes to something like this: │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * attributes: { │ │ │ │ │ - * myAttribute: "original" │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} Unique identifier for the map │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + fractionalZoom: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ - * properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this vector feature. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the map │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - this.geometry ? this.geometry.clone() : null, │ │ │ │ │ - this.attributes, │ │ │ │ │ - this.style); │ │ │ │ │ - }, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * 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). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + allOverlays: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ - }, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create markers │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ + * Property: dragging │ │ │ │ │ + * {Boolean} The map is currently being dragged. │ │ │ │ │ */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ + dragging: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} Size of the main div (this.div) │ │ │ │ │ */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - // pass │ │ │ │ │ - }, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create popups │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ + * Property: viewPortDiv │ │ │ │ │ + * {HTMLDivElement} The element that represents the map viewport │ │ │ │ │ */ │ │ │ │ │ - createPopup: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ + viewPortDiv: 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/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.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({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: 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) │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: │ │ │ │ │ - * 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: │ │ │ │ │ - * {Boolean} Whether or not the tile should actually be drawn. Returns null │ │ │ │ │ - * if a beforedraw listener returned false. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Reposition the tile. │ │ │ │ │ - * │ │ │ │ │ - * 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/Strategy.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.Strategy │ │ │ │ │ - * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the strategy subclasses instead. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The layer this strategy belongs to. │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: active │ │ │ │ │ - * {Boolean} The control is active. │ │ │ │ │ - */ │ │ │ │ │ - active: 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. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: autoDestroy │ │ │ │ │ - * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ - * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy │ │ │ │ │ - * Abstract class for vector strategies. Create instances of a subclass. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - // set the active property here, so that user cannot override it │ │ │ │ │ - this.active = false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up the strategy. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.options = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setLayer │ │ │ │ │ - * Called to set the property. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - */ │ │ │ │ │ - setLayer: function(layer) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ - * the strategy was already active. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - this.active = true; │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully deactivated or false if │ │ │ │ │ - * the strategy was already inactive. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.active = false; │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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/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/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/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/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/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 │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Util.vendorPrefix │ │ │ │ │ - * A collection of utility functions to detect vendor prefixed features │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Util.vendorPrefix = (function() { │ │ │ │ │ - "use strict"; │ │ │ │ │ - │ │ │ │ │ - var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], │ │ │ │ │ - divStyle = document.createElement("div").style, │ │ │ │ │ - cssCache = {}, │ │ │ │ │ - jsCache = {}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: domToCss │ │ │ │ │ - * Converts a upper camel case DOM style property name to a CSS property │ │ │ │ │ - * i.e. transformOrigin -> transform-origin │ │ │ │ │ - * or WebkitTransformOrigin -> -webkit-transform-origin │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * prefixedDom - {String} The property to convert │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The CSS property │ │ │ │ │ - */ │ │ │ │ │ - function domToCss(prefixedDom) { │ │ │ │ │ - if (!prefixedDom) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - return prefixedDom. │ │ │ │ │ - replace(/([A-Z])/g, function(c) { │ │ │ │ │ - return "-" + c.toLowerCase(); │ │ │ │ │ - }). │ │ │ │ │ - replace(/^ms-/, "-ms-"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: css │ │ │ │ │ - * Detect which property is used for a CSS property │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function css(property) { │ │ │ │ │ - if (cssCache[property] === undefined) { │ │ │ │ │ - var domProperty = property. │ │ │ │ │ - replace(/(-[\s\S])/g, function(c) { │ │ │ │ │ - return c.charAt(1).toUpperCase(); │ │ │ │ │ - }); │ │ │ │ │ - var prefixedDom = style(domProperty); │ │ │ │ │ - cssCache[property] = domToCss(prefixedDom); │ │ │ │ │ - } │ │ │ │ │ - return cssCache[property]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: js │ │ │ │ │ - * Detect which property is used for a JS property/method │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} The object to test on │ │ │ │ │ - * property - {String} The standard (unprefixed) JS property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard JS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function js(obj, property) { │ │ │ │ │ - if (jsCache[property] === undefined) { │ │ │ │ │ - var tmpProp, │ │ │ │ │ - i = 0, │ │ │ │ │ - l = VENDOR_PREFIXES.length, │ │ │ │ │ - prefix, │ │ │ │ │ - isStyleObj = (typeof obj.cssText !== "undefined"); │ │ │ │ │ - │ │ │ │ │ - jsCache[property] = null; │ │ │ │ │ - for (; i < l; i++) { │ │ │ │ │ - prefix = VENDOR_PREFIXES[i]; │ │ │ │ │ - if (prefix) { │ │ │ │ │ - if (!isStyleObj) { │ │ │ │ │ - // js prefix should be lower-case, while style │ │ │ │ │ - // properties have upper case on first character │ │ │ │ │ - prefix = prefix.toLowerCase(); │ │ │ │ │ - } │ │ │ │ │ - tmpProp = prefix + property.charAt(0).toUpperCase() + property.slice(1); │ │ │ │ │ - } else { │ │ │ │ │ - tmpProp = property; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (obj[tmpProp] !== undefined) { │ │ │ │ │ - jsCache[property] = tmpProp; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return jsCache[property]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: style │ │ │ │ │ - * Detect which property is used for a DOM style property │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) style property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard style property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function style(property) { │ │ │ │ │ - return js(divStyle, property); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - css: css, │ │ │ │ │ - js: js, │ │ │ │ │ - style: style, │ │ │ │ │ - │ │ │ │ │ - // used for testing │ │ │ │ │ - cssCache: cssCache, │ │ │ │ │ - jsCache: jsCache │ │ │ │ │ - }; │ │ │ │ │ -}()); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Animation.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/Util/vendorPrefix.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Animation │ │ │ │ │ - * A collection of utility functions for executing methods that repaint a │ │ │ │ │ - * portion of the browser window. These methods take advantage of the │ │ │ │ │ - * browser's scheduled repaints where requestAnimationFrame is available. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Animation = (function(window) { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: isNative │ │ │ │ │ - * {Boolean} true if a native requestAnimationFrame function is available │ │ │ │ │ - */ │ │ │ │ │ - var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ - var isNative = !!(requestAnimationFrame); │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: requestFrame │ │ │ │ │ - * Schedule a function to be called at the next available animation frame. │ │ │ │ │ - * Uses the native method where available. Where requestAnimationFrame is │ │ │ │ │ - * not available, setTimeout will be called with a 16ms delay. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ - * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ - */ │ │ │ │ │ - var requestFrame = (function() { │ │ │ │ │ - var request = window[requestAnimationFrame] || │ │ │ │ │ - function(callback, element) { │ │ │ │ │ - window.setTimeout(callback, 16); │ │ │ │ │ - }; │ │ │ │ │ - // bind to window to avoid illegal invocation of native function │ │ │ │ │ - return function(callback, element) { │ │ │ │ │ - request.apply(window, [callback, element]); │ │ │ │ │ - }; │ │ │ │ │ - })(); │ │ │ │ │ - │ │ │ │ │ - // private variables for animation loops │ │ │ │ │ - var counter = 0; │ │ │ │ │ - var loops = {}; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: start │ │ │ │ │ - * Executes a method with in series for some │ │ │ │ │ - * duration. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ - * duration - {Number} Optional duration for the loop. If not provided, the │ │ │ │ │ - * animation loop will execute indefinitely. │ │ │ │ │ - * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} Identifier for the animation loop. Used to stop animations with │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - function start(callback, duration, element) { │ │ │ │ │ - duration = duration > 0 ? duration : Number.POSITIVE_INFINITY; │ │ │ │ │ - var id = ++counter; │ │ │ │ │ - var start = +new Date; │ │ │ │ │ - loops[id] = function() { │ │ │ │ │ - if (loops[id] && +new Date - start <= duration) { │ │ │ │ │ - callback(); │ │ │ │ │ - if (loops[id]) { │ │ │ │ │ - requestFrame(loops[id], element); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - delete loops[id]; │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - requestFrame(loops[id], element); │ │ │ │ │ - return id; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: stop │ │ │ │ │ - * Terminates an animation loop started with . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {Number} Identifier returned from . │ │ │ │ │ - */ │ │ │ │ │ - function stop(id) { │ │ │ │ │ - delete loops[id]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - isNative: isNative, │ │ │ │ │ - requestFrame: requestFrame, │ │ │ │ │ - start: start, │ │ │ │ │ - stop: stop │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ -})(window); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Tween │ │ │ │ │ - */ │ │ │ │ │ -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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: time │ │ │ │ │ - * {int} Step counter │ │ │ │ │ - */ │ │ │ │ │ - time: 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. │ │ │ │ │ - */ │ │ │ │ │ - minFrameRate: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: startTime │ │ │ │ │ - * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ - * frames │ │ │ │ │ - */ │ │ │ │ │ - startTime: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: animationId │ │ │ │ │ - * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ - */ │ │ │ │ │ - animationId: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(easing) { │ │ │ │ │ - this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: start │ │ │ │ │ - * Plays the Tween, and calls the callback method on each step │ │ │ │ │ - * │ │ │ │ │ - * 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) │ │ │ │ │ - */ │ │ │ │ │ - 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) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: stop │ │ │ │ │ - * Stops the Tween, and calls the done callback │ │ │ │ │ - * Doesn't do anything if animation is already finished │ │ │ │ │ - */ │ │ │ │ │ - stop: function() { │ │ │ │ │ - if (!this.playing) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.callbacks && this.callbacks.done) { │ │ │ │ │ - this.callbacks.done.call(this, this.finish); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - this.playing = false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: play │ │ │ │ │ - * Calls the appropriate easing method │ │ │ │ │ - */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - 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 │ │ │ │ │ - * │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - 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 = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - 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) │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ @@ -13602,24625 +9882,24161 @@ │ │ │ │ │ OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ /** │ │ │ │ │ * Constant: TILE_HEIGHT │ │ │ │ │ * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Icon.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/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Map.js │ │ │ │ │ + * @requires OpenLayers/Projection.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. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Layer │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} image url │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - size: null, │ │ │ │ │ + name: 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. │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - offset: null, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: calculateOffset │ │ │ │ │ - * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: opacity │ │ │ │ │ + * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ + * is 1. │ │ │ │ │ */ │ │ │ │ │ - calculateOffset: null, │ │ │ │ │ + opacity: 1, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - imageDiv: null, │ │ │ │ │ + alwaysInRange: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ - * with a 'x' and 'y' properties. │ │ │ │ │ + /** │ │ │ │ │ + * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ + * {Array} The properties that are used for calculating resolutions │ │ │ │ │ + * information. │ │ │ │ │ */ │ │ │ │ │ - px: null, │ │ │ │ │ + RESOLUTION_PROPERTIES: [ │ │ │ │ │ + 'scales', 'resolutions', │ │ │ │ │ + 'maxScale', 'minScale', │ │ │ │ │ + 'maxResolution', 'minResolution', │ │ │ │ │ + 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Icon │ │ │ │ │ - * Creates an icon, which is an image tag in a div. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ * │ │ │ │ │ - * 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} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ - var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ - this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: map │ │ │ │ │ + * {} This variable is set when the layer is added to │ │ │ │ │ + * the map, via the accessor function setMap(). │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Nullify references and remove event listeners to prevent circular │ │ │ │ │ - * references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ + * individually by all subclasses. Default is false │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // erase any drawn elements │ │ │ │ │ - this.erase(); │ │ │ │ │ + isBaseLayer: false, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ - this.imageDiv.innerHTML = ""; │ │ │ │ │ - this.imageDiv = null; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: alpha │ │ │ │ │ + * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + alpha: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A fresh copy of the icon. │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Icon(this.url, │ │ │ │ │ - this.size, │ │ │ │ │ - this.offset, │ │ │ │ │ - this.calculateOffset); │ │ │ │ │ - }, │ │ │ │ │ + displayInLayerSwitcher: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ + * APIProperty: visibility │ │ │ │ │ + * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ */ │ │ │ │ │ - setSize: function(size) { │ │ │ │ │ - if (size != null) { │ │ │ │ │ - this.size = size; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ + visibility: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} │ │ │ │ │ + * APIProperty: attribution │ │ │ │ │ + * {String} Attribution string, displayed when an │ │ │ │ │ + * has been added to the map. │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - if (url != null) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ + attribution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: inRange │ │ │ │ │ + * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ + * range. This is set in whenever the zoom │ │ │ │ │ + * changes. │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - this.size, │ │ │ │ │ - this.url, │ │ │ │ │ - "absolute"); │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - return this.imageDiv; │ │ │ │ │ - }, │ │ │ │ │ + inRange: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erase the underlying image element. │ │ │ │ │ + /** │ │ │ │ │ + * Propery: imageSize │ │ │ │ │ + * {} For layers with a gutter, the image is larger than │ │ │ │ │ + * the tile by twice the gutter in each dimension. │ │ │ │ │ */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ - OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + imageSize: null, │ │ │ │ │ + │ │ │ │ │ + // OPTIONS │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the icon's opacity │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ - null, null, null, null, opacity); │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - //if no px passed in, use stored location │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.px = px; │ │ │ │ │ - } │ │ │ │ │ + gutter: 0, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {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. │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ - }, │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ + * 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.). │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ + resolutions: null, │ │ │ │ │ │ │ │ │ │ - return isDrawn; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Marker.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ -/* 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: 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, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Icon.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ + numZoomLevels: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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({ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minScale: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: icon │ │ │ │ │ - * {} The icon used by this marker. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - icon: null, │ │ │ │ │ + maxScale: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} location of object │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayOutsideMaxExtent │ │ │ │ │ + * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ + * extent for this layer. Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ + displayOutsideMaxExtent: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} the event handler. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + wrapDateLine: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} the map this marker is attached to │ │ │ │ │ + /** │ │ │ │ │ + * Property: metadata │ │ │ │ │ + * {Object} This object can be used to store additional information on a │ │ │ │ │ + * layer object. │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ + metadata: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Marker │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} the position of this marker │ │ │ │ │ - * icon - {} the icon for this marker │ │ │ │ │ + * name - {String} The layer name │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - initialize: function(lonlat, icon) { │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ + initialize: function(name, options) { │ │ │ │ │ │ │ │ │ │ - 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.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.events = new OpenLayers.Events(this, this.icon.imageDiv); │ │ │ │ │ - }, │ │ │ │ │ + this.addOptions(options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.name = name; │ │ │ │ │ │ │ │ │ │ - this.map = null; │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.destroy(); │ │ │ │ │ - this.icon = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.style.width = "100%"; │ │ │ │ │ + this.div.style.height = "100%"; │ │ │ │ │ + this.div.dir = "ltr"; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - return this.icon.draw(px); │ │ │ │ │ - }, │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ + * setNewBaseLayer - {Boolean} Set a new base layer when this layer has │ │ │ │ │ + * been destroyed. Default is true. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.icon != null)) { │ │ │ │ │ - this.icon.moveTo(px); │ │ │ │ │ + destroy: function(setNewBaseLayer) { │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ } │ │ │ │ │ - this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ - }, │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.removeLayer(this, setNewBaseLayer); │ │ │ │ │ + } │ │ │ │ │ + this.projection = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ + this.name = null; │ │ │ │ │ + this.div = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ - */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ - return isDrawn; │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ + * Method: clone │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {} The layer to be cloned │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ } │ │ │ │ │ - return onScreen; │ │ │ │ │ + │ │ │ │ │ + // 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: 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). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - inflate: function(inflate) { │ │ │ │ │ - if (this.icon) { │ │ │ │ │ - this.icon.setSize({ │ │ │ │ │ - w: this.icon.size.w * inflate, │ │ │ │ │ - h: this.icon.size.h * inflate │ │ │ │ │ - }); │ │ │ │ │ + getOptions: function() { │ │ │ │ │ + var options = {}; │ │ │ │ │ + for (var o in this.options) { │ │ │ │ │ + options[o] = this[o]; │ │ │ │ │ } │ │ │ │ │ + return options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the opacity of the marker by changin the opacity of │ │ │ │ │ - * its icon │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setName │ │ │ │ │ + * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ + * on the map. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ + * newName - {String} The new name. │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - this.icon.setOpacity(opacity); │ │ │ │ │ + setName: function(newName) { │ │ │ │ │ + if (newName != this.name) { │ │ │ │ │ + this.name = newName; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "name" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * Change URL of the Icon Image. │ │ │ │ │ - * │ │ │ │ │ - * url - {String} │ │ │ │ │ - */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - this.icon.setUrl(url); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ * │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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/Geometry.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ │ │ │ │ │ -/* 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 (this.options == null) { │ │ │ │ │ + this.options = {}; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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({ │ │ │ │ │ + // update our copy for clone │ │ │ │ │ + OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique identifier for this geometry. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ + // add new options to this │ │ │ │ │ + OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: parent │ │ │ │ │ - * {}This is set when a Geometry is added as component │ │ │ │ │ - * of another geometry │ │ │ │ │ - */ │ │ │ │ │ - parent: null, │ │ │ │ │ + // 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(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The bounds of this geometry │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ + // 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) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry │ │ │ │ │ - * Creates a geometry object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function() { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ + * APIMethod: onMapResize │ │ │ │ │ + * This function can be implemented by subclasses │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.bounds = null; │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + //this function can be implemented by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this geometry. Does not set any non-standard │ │ │ │ │ - * properties of the cloned geometry. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this geometry. │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Geometry(); │ │ │ │ │ + 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: setBounds │ │ │ │ │ - * Set the bounds for this Geometry. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ + * do some init work in that case. │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - setBounds: function(bounds) { │ │ │ │ │ - if (bounds) { │ │ │ │ │ - this.bounds = bounds.clone(); │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ + var display = this.visibility; │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + display = display && this.inRange; │ │ │ │ │ } │ │ │ │ │ + this.display(display); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearBounds │ │ │ │ │ - * Nullify this components bounds and that of its parent as well. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - clearBounds: function() { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - if (this.parent) { │ │ │ │ │ - this.parent.clearBounds(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + moveByPx: function(dx, dy) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 - {} │ │ │ │ │ + * 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 - {} │ │ │ │ │ */ │ │ │ │ │ - extendBounds: function(newBounds) { │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if (!bounds) { │ │ │ │ │ - this.setBounds(newBounds); │ │ │ │ │ - } else { │ │ │ │ │ - this.bounds.extend(newBounds); │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getBounds │ │ │ │ │ - * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ - * is calculated again, this makes queries faster. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getBounds: function() { │ │ │ │ │ - if (this.bounds == null) { │ │ │ │ │ - this.calculateBounds(); │ │ │ │ │ + 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)); │ │ │ │ │ } │ │ │ │ │ - return this.bounds; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getVisibility │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ + */ │ │ │ │ │ + getVisibility: function() { │ │ │ │ │ + return this.visibility; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds for the geometry. │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - // │ │ │ │ │ - // This should be overridden by subclasses. │ │ │ │ │ - // │ │ │ │ │ + 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: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options depend on the specific geometry type. │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + if (display != (this.div.style.display != "none")) { │ │ │ │ │ + this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateInRange │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - distanceTo: function(geometry, options) {}, │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ + * Method: resolutionsFromScales │ │ │ │ │ + * Derive resolutions from scales. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * scales - {Array(Number)} Scales │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ + * Returns │ │ │ │ │ + * {Array(Number)} Resolutions │ │ │ │ │ */ │ │ │ │ │ - getVertices: function(nodes) {}, │ │ │ │ │ + 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: atPoint │ │ │ │ │ - * Note - This is only an approximation based on the bounds of the │ │ │ │ │ - * geometry. │ │ │ │ │ - * │ │ │ │ │ + * Method: calculateResolutions │ │ │ │ │ + * Calculate resolutions based on the provided properties. │ │ │ │ │ + * │ │ │ │ │ * 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 │ │ │ │ │ - * │ │ │ │ │ + * props - {Object} Properties │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the geometry is at the specified location │ │ │ │ │ + * {Array({Number})} Array of resolutions. │ │ │ │ │ */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ + calculateResolutions: function(props) { │ │ │ │ │ │ │ │ │ │ - var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ - var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ + var viewSize, wRes, hRes; │ │ │ │ │ │ │ │ │ │ - var toleranceBounds = │ │ │ │ │ - new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ - this.bounds.bottom - dY, │ │ │ │ │ - this.bounds.right + dX, │ │ │ │ │ - this.bounds.top + dY); │ │ │ │ │ + // 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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ + // 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); │ │ │ │ │ } │ │ │ │ │ - return atPoint; │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLength │ │ │ │ │ - * Calculate the length of this geometry. This method is defined in │ │ │ │ │ - * subclasses. │ │ │ │ │ + * APIMethod: getResolution │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The length of the collection by summing its parts │ │ │ │ │ + * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ + * resolutions array, indexed by current zoom level. │ │ │ │ │ */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - //to be overridden by geometries that actually have a length │ │ │ │ │ - // │ │ │ │ │ - return 0.0; │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + var zoom = this.map.getZoom(); │ │ │ │ │ + return this.getResolutionForZoom(zoom); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getArea │ │ │ │ │ - * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The area of the collection by summing its parts │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - //to be overridden by geometries that actually have an area │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ + // means it will user map's current center & resolution │ │ │ │ │ // │ │ │ │ │ - return 0.0; │ │ │ │ │ + return this.map.calculateBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ + * 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: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return null; │ │ │ │ │ + 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: 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. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} String representation of this geometry. │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - var string; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ - string = OpenLayers.Format.WKT.prototype.write( │ │ │ │ │ - new OpenLayers.Feature.Vector(this) │ │ │ │ │ - ); │ │ │ │ │ + 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 { │ │ │ │ │ - string = Object.prototype.toString.call(this); │ │ │ │ │ + resolution = this.resolutions[Math.round(zoom)]; │ │ │ │ │ } │ │ │ │ │ - return string; │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + var dRes = highRes - lowRes; │ │ │ │ │ + if (dRes > 0) { │ │ │ │ │ + zoom = lowZoom + ((highRes - resolution) / dRes); │ │ │ │ │ } 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); │ │ │ │ │ + zoom = lowZoom; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - 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 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); │ │ │ │ │ } │ │ │ │ │ - } 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 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" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - 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; │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * Method: getZIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} the z-index of this layer │ │ │ │ │ + */ │ │ │ │ │ + getZIndex: function() { │ │ │ │ │ + return this.div.style.zIndex; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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 │ │ │ │ │ - }; │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * 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/Format.js │ │ │ │ │ + OpenLayers/Strategy.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.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.Strategy │ │ │ │ │ + * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the strategy subclasses instead. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} A reference to options passed to the constructor. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The layer this strategy belongs to. │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + layer: 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. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ */ │ │ │ │ │ - externalProjection: null, │ │ │ │ │ + options: 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: active │ │ │ │ │ + * {Boolean} The control is active. │ │ │ │ │ */ │ │ │ │ │ - internalProjection: null, │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: data │ │ │ │ │ - * {Object} When is true, this is the parsed string sent to │ │ │ │ │ - * . │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - data: null, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: keepData │ │ │ │ │ - * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ + * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - keepData: false, │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * Constructor: OpenLayers.Strategy │ │ │ │ │ + * Abstract class for vector strategies. Create instances of a subclass. │ │ │ │ │ * │ │ │ │ │ * 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). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * An instance of OpenLayers.Format │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ this.options = options; │ │ │ │ │ + // set the active property here, so that user cannot override it │ │ │ │ │ + this.active = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + * Clean up the strategy. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() {}, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ - * Read data from a string, and return an object whose type depends on the │ │ │ │ │ - * subclass. │ │ │ │ │ - * │ │ │ │ │ + * Method: setLayer │ │ │ │ │ + * Called to set the property. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {string} Data to read/parse. │ │ │ │ │ + * layer - {} │ │ │ │ │ + */ │ │ │ │ │ + setLayer: function(layer) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * Depends on the subclass │ │ │ │ │ + * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ + * the strategy was already active. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - throw new Error('Read not implemented.'); │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + this.active = true; │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ - * Accept an object, and return a string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} Object to be serialized │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ + * tear-down. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string representation of the object. │ │ │ │ │ + * {Boolean} True if the strategy was successfully deactivated or false if │ │ │ │ │ + * the strategy was already inactive. │ │ │ │ │ */ │ │ │ │ │ - write: function(object) { │ │ │ │ │ - throw new Error('Write not implemented.'); │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.active = false; │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Strategy" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Point.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/Geometry.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Geometry.Point │ │ │ │ │ - * Point geometry class. │ │ │ │ │ - * │ │ │ │ │ - * 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.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ +OpenLayers.Popup = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: x │ │ │ │ │ - * {float} │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} custom event manager │ │ │ │ │ */ │ │ │ │ │ - x: null, │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** Property: id │ │ │ │ │ + * {String} the unique identifier assigned to this popup. │ │ │ │ │ + */ │ │ │ │ │ + id: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: y │ │ │ │ │ - * {float} │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} the position of this popup on the map │ │ │ │ │ */ │ │ │ │ │ - y: null, │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ - * Construct a point geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {float} │ │ │ │ │ - * y - {float} │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Property: div │ │ │ │ │ + * {DOMElement} the div that contains this popup. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ - this.x = parseFloat(x); │ │ │ │ │ - this.y = parseFloat(y); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentSize │ │ │ │ │ + * {} the width and height of the content. │ │ │ │ │ + */ │ │ │ │ │ + contentSize: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} the width and height of the popup. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ - } │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentHTML │ │ │ │ │ + * {String} An HTML string for this popup to display. │ │ │ │ │ + */ │ │ │ │ │ + contentHTML: null, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: backgroundColor │ │ │ │ │ + * {String} the background color used by the popup. │ │ │ │ │ + */ │ │ │ │ │ + backgroundColor: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ - * Create a new Bounds based on the lon/lat │ │ │ │ │ + * Property: opacity │ │ │ │ │ + * {float} the opacity of this popup (between 0.0 and 1.0) │ │ │ │ │ */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ - this.x, this.y); │ │ │ │ │ - }, │ │ │ │ │ + opacity: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geom - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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))); │ │ │ │ │ + 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. │ │ │ │ │ + */ │ │ │ │ │ + fixPadding: function() { │ │ │ │ │ + if (typeof this.padding == "number") { │ │ │ │ │ + this.padding = new OpenLayers.Bounds( │ │ │ │ │ + this.padding, this.padding, this.padding, this.padding │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: toShortString │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Shortened String representation of Point object. │ │ │ │ │ - * (ex. "5, 42") │ │ │ │ │ + * APIProperty: panMapIfOutOfView │ │ │ │ │ + * {Boolean} When drawn, pan map such that the entire popup is visible in │ │ │ │ │ + * the current viewport (if necessary). │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - toShortString: function() { │ │ │ │ │ - return (this.x + ", " + this.y); │ │ │ │ │ - }, │ │ │ │ │ + panMapIfOutOfView: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - this.x = this.x + x; │ │ │ │ │ - this.y = this.y + y; │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - }, │ │ │ │ │ + keepInMap: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * APIProperty: closeOnMove │ │ │ │ │ + * {Boolean} When map pans, close the popup. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + 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(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + this.closeDiv = null; │ │ │ │ │ + │ │ │ │ │ + this.div.removeChild(this.groupDiv); │ │ │ │ │ + this.groupDiv = null; │ │ │ │ │ + │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.removePopup(this); │ │ │ │ │ + } │ │ │ │ │ + this.map = null; │ │ │ │ │ + this.div = null; │ │ │ │ │ + │ │ │ │ │ + this.autoSize = null; │ │ │ │ │ + this.minSize = null; │ │ │ │ │ + this.maxSize = null; │ │ │ │ │ + this.padding = null; │ │ │ │ │ + this.panMapIfOutOfView = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Constructs the elements that make up the popup. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * px - {} the position the popup in pixels. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ + * {DOMElement} Reference to a div that contains the drawn popup │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + if (px == null) { │ │ │ │ │ + if ((this.lonlat != null) && (this.map != null)) { │ │ │ │ │ + px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // 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(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ + /** │ │ │ │ │ + * Method: updatePosition │ │ │ │ │ + * if the popup has a lonlat and its map members set, │ │ │ │ │ + * then have it move itself to its proper position │ │ │ │ │ */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - intersect = this.equals(geometry); │ │ │ │ │ - } else { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ + updatePosition: function() { │ │ │ │ │ + if ((this.lonlat) && (this.map)) { │ │ │ │ │ + var px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ + if (px) { │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Translate the x,y properties of the point from source to dest. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * px - {} the top and left position of the popup div. │ │ │ │ │ */ │ │ │ │ │ - transform: function(source, dest) { │ │ │ │ │ - if ((source && dest)) { │ │ │ │ │ - OpenLayers.Projection.transform( │ │ │ │ │ - this, source, dest); │ │ │ │ │ - this.bounds = null; │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.div != null)) { │ │ │ │ │ + this.div.style.left = px.x + "px"; │ │ │ │ │ + this.div.style.top = px.y + "px"; │ │ │ │ │ } │ │ │ │ │ - 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. │ │ │ │ │ + * Method: visible │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Boolean indicating whether or not the popup is visible │ │ │ │ │ */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - return [this]; │ │ │ │ │ + visible: function() { │ │ │ │ │ + return OpenLayers.Element.visible(this.div); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ + * Method: toggle │ │ │ │ │ + * Toggles visibility of the popup. │ │ │ │ │ */ │ │ │ │ │ - components: null, │ │ │ │ │ + toggle: function() { │ │ │ │ │ + if (this.visible()) { │ │ │ │ │ + this.hide(); │ │ │ │ │ + } else { │ │ │ │ │ + this.show(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: show │ │ │ │ │ + * Makes the popup visible. │ │ │ │ │ */ │ │ │ │ │ - componentTypes: null, │ │ │ │ │ + show: function() { │ │ │ │ │ + this.div.style.display = ''; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ + if (this.panMapIfOutOfView) { │ │ │ │ │ + this.panIntoView(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ + * Method: hide │ │ │ │ │ + * Makes the popup invisible. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.components.length = 0; │ │ │ │ │ - this.components = null; │ │ │ │ │ - OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ + hide: function() { │ │ │ │ │ + this.div.style.display = 'none'; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clone this geometry. │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * Used to adjust the size of the popup. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this collection │ │ │ │ │ + * Parameters: │ │ │ │ │ + * contentSize - {} the new size for the popup's │ │ │ │ │ + * contents div (in pixels). │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ + //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; │ │ │ │ │ │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ + //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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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()); │ │ │ │ │ + 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"; │ │ │ │ │ } │ │ │ │ │ - return strings.join(","); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds by iterating through the components and │ │ │ │ │ - * calling calling extendBounds() on each item. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - // 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); │ │ │ │ │ - } │ │ │ │ │ + this.setSize(newSize); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addComponents │ │ │ │ │ - * Add components to this geometry. │ │ │ │ │ + * Method: setBackgroundColor │ │ │ │ │ + * Sets the background color of the popup. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * components - {Array()} An array of geometries to add │ │ │ │ │ + * color - {String} the background color. eg "#FFBBBB" │ │ │ │ │ */ │ │ │ │ │ - addComponents: function(components) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ + setBackgroundColor: function(color) { │ │ │ │ │ + if (color != undefined) { │ │ │ │ │ + this.backgroundColor = color; │ │ │ │ │ } │ │ │ │ │ - for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ - this.addComponent(components[i]); │ │ │ │ │ + │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.div.style.backgroundColor = this.backgroundColor; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Sets the opacity of the popup. │ │ │ │ │ * │ │ │ │ │ * 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 │ │ │ │ │ + * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ */ │ │ │ │ │ - addComponent: function(component, index) { │ │ │ │ │ - var added = false; │ │ │ │ │ - if (component) { │ │ │ │ │ - if (this.componentTypes == null || │ │ │ │ │ - (OpenLayers.Util.indexOf(this.componentTypes, │ │ │ │ │ - component.CLASS_NAME) > -1)) { │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + if (opacity != undefined) { │ │ │ │ │ + this.opacity = opacity; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + 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 + ')'; │ │ │ │ │ } │ │ │ │ │ - return added; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: removeComponents │ │ │ │ │ - * Remove components from this geometry. │ │ │ │ │ + * Method: setBorder │ │ │ │ │ + * Sets the border style of the popup. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * components - {Array()} The components to be removed │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A component was removed. │ │ │ │ │ + * border - {String} The border style value. eg 2px │ │ │ │ │ */ │ │ │ │ │ - removeComponents: function(components) { │ │ │ │ │ - var removed = false; │ │ │ │ │ - │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ + setBorder: function(border) { │ │ │ │ │ + if (border != undefined) { │ │ │ │ │ + this.border = border; │ │ │ │ │ } │ │ │ │ │ - for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ - removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ + │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.div.style.border = this.border; │ │ │ │ │ } │ │ │ │ │ - return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeComponent │ │ │ │ │ - * Remove a component from this geometry. │ │ │ │ │ + * Method: setContentHTML │ │ │ │ │ + * Allows the user to set the HTML content of the popup. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * component - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ + * contentHTML - {String} HTML for the div. │ │ │ │ │ */ │ │ │ │ │ - removeComponent: function(component) { │ │ │ │ │ + setContentHTML: function(contentHTML) { │ │ │ │ │ │ │ │ │ │ - OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ + if (contentHTML != null) { │ │ │ │ │ + this.contentHTML = contentHTML; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ - // to this.getBounds(); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + if ((this.contentDiv != null) && │ │ │ │ │ + (this.contentHTML != null) && │ │ │ │ │ + (this.contentHTML != this.contentDiv.innerHTML)) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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(); │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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 │ │ │ │ │ + * Method: registerImageListeners │ │ │ │ │ + * Called when an image contained by the popup loaded. this function │ │ │ │ │ + * updates the popup size, then unregisters the image load listener. │ │ │ │ │ */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - area += this.components[i].getArea(); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ + registerImageListeners: function() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ + // 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); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.observe(img, 'load', img._onImgLoad); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Compute the centroid for this geometry collection. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getSafeContentSize │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ - * returning an area weighted average of all geometries in this collection. │ │ │ │ │ - * │ │ │ │ │ + * size - {} Desired size to make the popup. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ + * {} 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). │ │ │ │ │ */ │ │ │ │ │ - getCentroid: function(weighted) { │ │ │ │ │ - if (!weighted) { │ │ │ │ │ - return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - var len = this.components.length; │ │ │ │ │ - if (!len) { │ │ │ │ │ - return false; │ │ │ │ │ + │ │ │ │ │ + // 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)); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + // 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)); │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + │ │ │ │ │ + //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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + 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 new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ + return safeContentSize; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ + * 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) │ │ │ │ │ * │ │ │ │ │ - * 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); │ │ │ │ │ + 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 length; │ │ │ │ │ + return contentDivPadding; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: addCloseBox │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ - * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ + * callback - {Function} The callback to be called when the close button │ │ │ │ │ + * is clicked. │ │ │ │ │ */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - this.components[i].move(x, y); │ │ │ │ │ - } │ │ │ │ │ + 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)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: panIntoView │ │ │ │ │ + * Pans the map such that the popup is totaly viewable (if necessary) │ │ │ │ │ */ │ │ │ │ │ - rotate: function(angle, origin) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - this.components[i].rotate(angle, origin); │ │ │ │ │ + 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: resize │ │ │ │ │ - * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ - * a uniform scaling to a geometry. │ │ │ │ │ + /** │ │ │ │ │ + * Method: registerEvents │ │ │ │ │ + * Registers events on the popup. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Do this in a separate function so that subclasses can │ │ │ │ │ + * choose to override it if they wish to deal differently │ │ │ │ │ + * with mouse events │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - resize: function(scale, origin, ratio) { │ │ │ │ │ - for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ - this.components[i].resize(scale, origin, ratio); │ │ │ │ │ + registerEvents: function() { │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div, null, true); │ │ │ │ │ + │ │ │ │ │ + function onTouchstart(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - return this; │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + onmousedown: function(evt) { │ │ │ │ │ + this.mousedown = true; │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ + * 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: │ │ │ │ │ - * geometry - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + onmousemove: function(evt) { │ │ │ │ │ + if (this.mousedown) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - return equivalent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Reproject the components geometry from source to dest. │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + onmouseup: function(evt) { │ │ │ │ │ + if (this.mousedown) { │ │ │ │ │ + this.mousedown = false; │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ + * Method: onclick │ │ │ │ │ + * Ignore clicks, but allowing default browser handling │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + onclick: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + onmouseout: function(evt) { │ │ │ │ │ + this.mousedown = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Method: ondblclick │ │ │ │ │ + * Ignore double-clicks, but allowing default browser handling │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + ondblclick: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Popup" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ +OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ +OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ +OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ +OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + 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/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * MultiPoint is a collection of Points. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Feature │ │ │ │ │ + * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ + * class specifically combines a marker and a lonlat. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Geometry.MultiPoint = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.Collection, { │ │ │ │ │ +OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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"], │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * Create a new MultiPoint Geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addPoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be added │ │ │ │ │ - * index - {Integer} Optional index │ │ │ │ │ - */ │ │ │ │ │ - addPoint: function(point, index) { │ │ │ │ │ - this.addComponent(point, index); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removePoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be removed │ │ │ │ │ - */ │ │ │ │ │ - removePoint: function(point) { │ │ │ │ │ - this.removeComponent(point); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: data │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Curve.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: marker │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + marker: 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: popupClass │ │ │ │ │ + * {} The class which will be used to instantiate │ │ │ │ │ + * a new Popup. Default is . │ │ │ │ │ + */ │ │ │ │ │ + popupClass: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: popup │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + popup: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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, { │ │ │ │ │ + /** │ │ │ │ │ + * 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 + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ + * Method: onScreen │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Array()} │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLength │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ - * 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]); │ │ │ │ │ - } │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + │ │ │ │ │ + if (this.lonlat != null) { │ │ │ │ │ + this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ } │ │ │ │ │ - return length; │ │ │ │ │ + return this.marker; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ + * {} 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 . │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + if (this.data.overflow != null) { │ │ │ │ │ + this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + this.popup.feature = this; │ │ │ │ │ } │ │ │ │ │ - // convert to m │ │ │ │ │ - return length * 1000; │ │ │ │ │ + return this.popup; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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/Geometry/LineString.js │ │ │ │ │ + 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/Geometry/Curve.js │ │ │ │ │ + * @requires OpenLayers/Feature.js │ │ │ │ │ + * @requires OpenLayers/Util.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. │ │ │ │ │ + * 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.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ +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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ - * Create a new LineString geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * points - {Array()} An array of points used to │ │ │ │ │ - * generate the linestring │ │ │ │ │ - * │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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) │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} The point to be removed │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * geometry: >Object │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - removeComponent: function(point) { │ │ │ │ │ - var removed = this.components && (this.components.length > 2); │ │ │ │ │ - if (removed) { │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return removed; │ │ │ │ │ + this.style = style ? style : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layer) { │ │ │ │ │ + this.layer.removeFeatures(this); │ │ │ │ │ + this.layer = null; │ │ │ │ │ } │ │ │ │ │ - return intersect; │ │ │ │ │ + │ │ │ │ │ + this.geometry = null; │ │ │ │ │ + this.modified = null; │ │ │ │ │ + OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSortedSegments │ │ │ │ │ + * Method: clone │ │ │ │ │ + * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ + * properties. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {} An exact clone of this vector feature. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + this.geometry ? this.geometry.clone() : null, │ │ │ │ │ + this.attributes, │ │ │ │ │ + this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: splitWithSegment │ │ │ │ │ - * Split this geometry with the given segment. │ │ │ │ │ + * 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: │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {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). │ │ │ │ │ + * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ + * based on its bounds if boundsOnly is true). │ │ │ │ │ */ │ │ │ │ │ - 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()]; │ │ │ │ │ - } │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * {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. │ │ │ │ │ + * {Boolean} The feature is currently displayed. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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: 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. │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create markers │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - splitWith: function(geometry, options) { │ │ │ │ │ - return geometry.split(this, options); │ │ │ │ │ + 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 │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: createPopup │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create popups │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + createPopup: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {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. │ │ │ │ │ + * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + if (this.geometry) { │ │ │ │ │ + atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ + toleranceLat); │ │ │ │ │ } │ │ │ │ │ - return best; │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: simplify │ │ │ │ │ - * This function will return a simplified LineString. │ │ │ │ │ - * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ + * location - { or } the │ │ │ │ │ + * location to which to move the feature. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + move: function(location) { │ │ │ │ │ │ │ │ │ │ - return height; │ │ │ │ │ - }; │ │ │ │ │ + if (!this.layer || !this.geometry.move) { │ │ │ │ │ + //do nothing if no layer or immoveable geometry │ │ │ │ │ + return undefined; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var firstPoint = 0; │ │ │ │ │ - var lastPoint = points.length - 1; │ │ │ │ │ - var pointIndexsToKeep = []; │ │ │ │ │ + var pixel; │ │ │ │ │ + if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ + pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ + } else { │ │ │ │ │ + pixel = location; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - //Add the first and last index to the keepers │ │ │ │ │ - pointIndexsToKeep.push(firstPoint); │ │ │ │ │ - pointIndexsToKeep.push(lastPoint); │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //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); │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - douglasPeuckerReduction(points, firstPoint, lastPoint, tolerance); │ │ │ │ │ - var returnPoints = []; │ │ │ │ │ - pointIndexsToKeep.sort(compareNumbers); │ │ │ │ │ - for (var index = 0; index < pointIndexsToKeep.length; index++) { │ │ │ │ │ - returnPoints.push(points[pointIndexsToKeep[index]]); │ │ │ │ │ + } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ + switch (this.state) { │ │ │ │ │ + case OpenLayers.State.UNKNOWN: │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + this.state = state; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Geometry.LineString(returnPoints); │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - return this; │ │ │ │ │ + } 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.Geometry.LineString" │ │ │ │ │ + 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/Geometry/MultiLineString.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/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiLineString │ │ │ │ │ - * A MultiLineString is a geometry with multiple │ │ │ │ │ - * components. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Style │ │ │ │ │ + * This class represents a UserStyle obtained │ │ │ │ │ + * from a SLD, containing styling rules. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Geometry.MultiLineString = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.Collection, { │ │ │ │ │ +OpenLayers.Style = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.LineString"], │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiLineString │ │ │ │ │ - * Constructor for a MultiLineString Geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: split │ │ │ │ │ - * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} 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(geometry, options) { │ │ │ │ │ - var results = null; │ │ │ │ │ - var mutual = options && options.mutual; │ │ │ │ │ - var splits, sourceLine, sourceLines, sourceSplit, targetSplit; │ │ │ │ │ - var sourceParts = []; │ │ │ │ │ - var targetParts = [geometry]; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - sourceLine = this.components[i]; │ │ │ │ │ - sourceSplit = false; │ │ │ │ │ - for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ - splits = sourceLine.split(targetParts[j], options); │ │ │ │ │ - if (splits) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - sourceLines = splits[0]; │ │ │ │ │ - for (var k = 0, klen = sourceLines.length; k < klen; ++k) { │ │ │ │ │ - if (k === 0 && sourceParts.length) { │ │ │ │ │ - sourceParts[sourceParts.length - 1].addComponent( │ │ │ │ │ - sourceLines[k] │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - sourceParts.push( │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ - sourceLines[k] │ │ │ │ │ - ]) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - splits = splits[1]; │ │ │ │ │ - } │ │ │ │ │ - if (splits.length) { │ │ │ │ │ - // splice in new target parts │ │ │ │ │ - splits.unshift(j, 1); │ │ │ │ │ - Array.prototype.splice.apply(targetParts, splits); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!sourceSplit) { │ │ │ │ │ - // source line was not hit │ │ │ │ │ - if (sourceParts.length) { │ │ │ │ │ - // add line to existing multi │ │ │ │ │ - sourceParts[sourceParts.length - 1].addComponent( │ │ │ │ │ - sourceLine.clone() │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - // create a fresh multi │ │ │ │ │ - sourceParts = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString( │ │ │ │ │ - sourceLine.clone() │ │ │ │ │ - ) │ │ │ │ │ - ]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (targetParts && targetParts.length > 1) { │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - targetParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (sourceSplit || targetSplit) { │ │ │ │ │ - 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) { │ │ │ │ │ - var results = null; │ │ │ │ │ - var mutual = options && options.mutual; │ │ │ │ │ - var splits, targetLine, sourceLines, sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ - if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ - targetParts = []; │ │ │ │ │ - sourceParts = [geometry]; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - targetSplit = false; │ │ │ │ │ - targetLine = this.components[i]; │ │ │ │ │ - for (var j = 0; j < sourceParts.length; ++j) { │ │ │ │ │ - splits = sourceParts[j].split(targetLine, options); │ │ │ │ │ - if (splits) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - sourceLines = splits[0]; │ │ │ │ │ - if (sourceLines.length) { │ │ │ │ │ - // splice in new source parts │ │ │ │ │ - sourceLines.unshift(j, 1); │ │ │ │ │ - Array.prototype.splice.apply(sourceParts, sourceLines); │ │ │ │ │ - j += sourceLines.length - 2; │ │ │ │ │ - } │ │ │ │ │ - splits = splits[1]; │ │ │ │ │ - if (splits.length === 0) { │ │ │ │ │ - splits = [targetLine.clone()]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - for (var k = 0, klen = splits.length; k < klen; ++k) { │ │ │ │ │ - if (k === 0 && targetParts.length) { │ │ │ │ │ - targetParts[targetParts.length - 1].addComponent( │ │ │ │ │ - splits[k] │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - targetParts.push( │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ - splits[k] │ │ │ │ │ - ]) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!targetSplit) { │ │ │ │ │ - // target component was not hit │ │ │ │ │ - if (targetParts.length) { │ │ │ │ │ - // add it to any existing multi-line │ │ │ │ │ - targetParts[targetParts.length - 1].addComponent( │ │ │ │ │ - targetLine.clone() │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - // or start with a fresh multi-line │ │ │ │ │ - targetParts = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ - targetLine.clone() │ │ │ │ │ - ]) │ │ │ │ │ - ]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - results = geometry.split(this); │ │ │ │ │ - } │ │ │ │ │ - if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (targetParts && targetParts.length > 1) { │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - targetParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (sourceSplit || targetSplit) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - results = [sourceParts, targetParts]; │ │ │ │ │ - } else { │ │ │ │ │ - results = targetParts; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return results; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this style (set if included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.MultiLineString" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/LinearRing.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this style (set if abstract is included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + description: 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: layerName │ │ │ │ │ + * {} name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ + */ │ │ │ │ │ + layerName: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isDefault │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isDefault: false, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.LinearRing │ │ │ │ │ - * │ │ │ │ │ - * A Linear Ring is a special LineString which is closed. It closes itself │ │ │ │ │ - * automatically on every addPoint/removePoint by adding a copy of the first │ │ │ │ │ - * point as the last point. │ │ │ │ │ - * │ │ │ │ │ - * Also, as it is the first in the line family to close itself, a getArea() │ │ │ │ │ - * function is defined to calculate the enclosed area of the linearRing │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.LinearRing = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.LineString, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: rules │ │ │ │ │ + * {Array()} │ │ │ │ │ + */ │ │ │ │ │ + rules: 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: ["OpenLayers.Geometry.Point"], │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.LinearRing │ │ │ │ │ - * Linear rings are constructed with an array of points. This array │ │ │ │ │ - * can represent a closed or open ring. If the ring is open (the last │ │ │ │ │ - * point does not equal the first point), the constructor will close │ │ │ │ │ - * the ring. If the ring is already closed (the last point does equal │ │ │ │ │ - * the first point), it will be left closed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * points - {Array()} points │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addComponent │ │ │ │ │ - * Adds a point to geometry components. If the point is to be added to │ │ │ │ │ - * the end of the components array and it is the same as the last point │ │ │ │ │ - * already in that array, the duplicate point is not added. This has │ │ │ │ │ - * the effect of closing the ring if it is not already closed, and │ │ │ │ │ - * doing the right thing if it is already closed. This behavior can │ │ │ │ │ - * be overridden by calling the method with a non-null index as the │ │ │ │ │ - * second argument. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * index - {Integer} Index into the array to insert the component │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Was the Point successfully added? │ │ │ │ │ - */ │ │ │ │ │ - addComponent: function(point, index) { │ │ │ │ │ - var added = false; │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - //remove last point │ │ │ │ │ - var lastPoint = this.components.pop(); │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - // given an index, add the point │ │ │ │ │ - // without an index only add non-duplicate points │ │ │ │ │ - if (index != null || !point.equals(lastPoint)) { │ │ │ │ │ - added = OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - //append copy of first point │ │ │ │ │ - var firstPoint = this.components[0]; │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ - [firstPoint]); │ │ │ │ │ + /** │ │ │ │ │ + * 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) { │ │ │ │ │ │ │ │ │ │ - return added; │ │ │ │ │ - }, │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.rules = []; │ │ │ │ │ + if (options && options.rules) { │ │ │ │ │ + this.addRules(options.rules); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeComponent │ │ │ │ │ - * Removes a point from geometry components. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponent: function(point) { │ │ │ │ │ - var removed = this.components && (this.components.length > 3); │ │ │ │ │ - if (removed) { │ │ │ │ │ - //remove last point │ │ │ │ │ - this.components.pop(); │ │ │ │ │ + // use the default style from OpenLayers.Feature.Vector if no style │ │ │ │ │ + // was given in the constructor │ │ │ │ │ + this.setDefaultStyle(style || │ │ │ │ │ + OpenLayers.Feature.Vector.style["default"]); │ │ │ │ │ │ │ │ │ │ - //remove our point │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - //append copy of first point │ │ │ │ │ - var firstPoint = this.components[0]; │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ - [firstPoint]); │ │ │ │ │ - } │ │ │ │ │ - return removed; │ │ │ │ │ - }, │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 - 1; i++) { │ │ │ │ │ - this.components[i].move(x, y); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 - 1; ++i) { │ │ │ │ │ - this.components[i].rotate(angle, origin); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, len = this.components.length; i < len - 1; ++i) { │ │ │ │ │ - this.components[i].resize(scale, origin, ratio); │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ + var rules = this.rules; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 - 1; i++) { │ │ │ │ │ - var component = this.components[i]; │ │ │ │ │ - component.transform(source, dest); │ │ │ │ │ - } │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ + 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); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - if (this.components) { │ │ │ │ │ - var len = this.components.length; │ │ │ │ │ - if (len > 0 && len <= 2) { │ │ │ │ │ - return this.components[0].clone(); │ │ │ │ │ - } else if (len > 2) { │ │ │ │ │ - var sumX = 0.0; │ │ │ │ │ - var sumY = 0.0; │ │ │ │ │ - var x0 = this.components[0].x; │ │ │ │ │ - var y0 = this.components[0].y; │ │ │ │ │ - var area = -1 * this.getArea(); │ │ │ │ │ - if (area != 0) { │ │ │ │ │ - for (var i = 0; i < len - 1; i++) { │ │ │ │ │ - var b = this.components[i]; │ │ │ │ │ - var c = this.components[i + 1]; │ │ │ │ │ - sumX += (b.x + c.x - 2 * x0) * ((b.x - x0) * (c.y - y0) - (c.x - x0) * (b.y - y0)); │ │ │ │ │ - sumY += (b.y + c.y - 2 * y0) * ((b.x - x0) * (c.y - y0) - (c.x - x0) * (b.y - y0)); │ │ │ │ │ - } │ │ │ │ │ - var x = x0 + sumX / (6 * area); │ │ │ │ │ - var y = y0 + sumY / (6 * area); │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = 0; i < len - 1; i++) { │ │ │ │ │ - sumX += this.components[i].x; │ │ │ │ │ - sumY += this.components[i].y; │ │ │ │ │ - } │ │ │ │ │ - var x = sumX / (len - 1); │ │ │ │ │ - var y = sumY / (len - 1); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.Point(x, y); │ │ │ │ │ + if (applies) { │ │ │ │ │ + if (rule instanceof OpenLayers.Rule && rule.elseFilter) { │ │ │ │ │ + elseRules.push(rule); │ │ │ │ │ } else { │ │ │ │ │ - return null; │ │ │ │ │ + appliedRules = true; │ │ │ │ │ + this.applySymbolizer(rule, style, feature); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getArea │ │ │ │ │ - * Note - The area is positive if the ring is oriented CW, otherwise │ │ │ │ │ - * it will be negative. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The signed area for a ring. │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - if (this.components && (this.components.length > 2)) { │ │ │ │ │ - var sum = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len - 1; i++) { │ │ │ │ │ - var b = this.components[i]; │ │ │ │ │ - var c = this.components[i + 1]; │ │ │ │ │ - sum += (b.x + c.x) * (c.y - b.y); │ │ │ │ │ - } │ │ │ │ │ - area = -sum / 2.0; │ │ │ │ │ + // 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); │ │ │ │ │ } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicArea │ │ │ │ │ - * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ - * the earth. Note that this area will be positive if ring is oriented │ │ │ │ │ - * clockwise, otherwise it will be negative. │ │ │ │ │ - * │ │ │ │ │ - * 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 signed geodesic area of the polygon in square │ │ │ │ │ - * meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicArea: function(projection) { │ │ │ │ │ - var ring = this; // so we can work with a clone if needed │ │ │ │ │ - if (projection) { │ │ │ │ │ - var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - if (!gg.equals(projection)) { │ │ │ │ │ - ring = this.clone().transform(projection, gg); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - var len = ring.components && ring.components.length; │ │ │ │ │ - if (len > 2) { │ │ │ │ │ - var p1, p2; │ │ │ │ │ - for (var i = 0; i < len - 1; i++) { │ │ │ │ │ - p1 = ring.components[i]; │ │ │ │ │ - p2 = ring.components[i + 1]; │ │ │ │ │ - area += OpenLayers.Util.rad(p2.x - p1.x) * │ │ │ │ │ - (2 + Math.sin(OpenLayers.Util.rad(p1.y)) + │ │ │ │ │ - Math.sin(OpenLayers.Util.rad(p2.y))); │ │ │ │ │ - } │ │ │ │ │ - area = area * 6378137.0 * 6378137.0 / 2.0; │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ + // don't display if there were rules but none applied │ │ │ │ │ + if (rules.length > 0 && appliedRules == false) { │ │ │ │ │ + style.display = "none"; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: containsPoint │ │ │ │ │ - * Test if a point is inside a linear ring. For the case where a point │ │ │ │ │ - * is coincident with a linear ring edge, returns 1. Otherwise, │ │ │ │ │ - * returns boolean. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean | Number} The point is inside the linear ring. Returns 1 if │ │ │ │ │ - * the point is coincident with an edge. Returns boolean otherwise. │ │ │ │ │ - */ │ │ │ │ │ - containsPoint: function(point) { │ │ │ │ │ - var approx = OpenLayers.Number.limitSigDigs; │ │ │ │ │ - var digs = 14; │ │ │ │ │ - var px = approx(point.x, digs); │ │ │ │ │ - var py = approx(point.y, digs); │ │ │ │ │ + if (style.label != null && typeof style.label !== "string") { │ │ │ │ │ + style.label = String(style.label); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - function getX(y, x1, y1, x2, y2) { │ │ │ │ │ - return (y - y2) * ((x2 - x1) / (y2 - y1)) + x2; │ │ │ │ │ - } │ │ │ │ │ - var numSeg = this.components.length - 1; │ │ │ │ │ - var start, end, x1, y1, x2, y2, cx, cy; │ │ │ │ │ - var crosses = 0; │ │ │ │ │ - for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ - start = this.components[i]; │ │ │ │ │ - x1 = approx(start.x, digs); │ │ │ │ │ - y1 = approx(start.y, digs); │ │ │ │ │ - end = this.components[i + 1]; │ │ │ │ │ - x2 = approx(end.x, digs); │ │ │ │ │ - y2 = approx(end.y, digs); │ │ │ │ │ + return style; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * The following conditions enforce five edge-crossing rules: │ │ │ │ │ - * 1. points coincident with edges are considered contained; │ │ │ │ │ - * 2. an upward edge includes its starting endpoint, and │ │ │ │ │ - * excludes its final endpoint; │ │ │ │ │ - * 3. a downward edge excludes its starting endpoint, and │ │ │ │ │ - * includes its final endpoint; │ │ │ │ │ - * 4. horizontal edges are excluded; and │ │ │ │ │ - * 5. the edge-ray intersection point must be strictly right │ │ │ │ │ - * of the point P. │ │ │ │ │ - */ │ │ │ │ │ - if (y1 == y2) { │ │ │ │ │ - // horizontal edge │ │ │ │ │ - if (py == y1) { │ │ │ │ │ - // point on horizontal line │ │ │ │ │ - if (x1 <= x2 && (px >= x1 && px <= x2) || // right or vert │ │ │ │ │ - x1 >= x2 && (px <= x1 && px >= x2)) { // left or vert │ │ │ │ │ - // point on edge │ │ │ │ │ - crosses = -1; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // ignore other horizontal edges │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - cx = approx(getX(py, x1, y1, x2, y2), digs); │ │ │ │ │ - if (cx == px) { │ │ │ │ │ - // point on line │ │ │ │ │ - if (y1 < y2 && (py >= y1 && py <= y2) || // upward │ │ │ │ │ - y1 > y2 && (py <= y1 && py >= y2)) { // downward │ │ │ │ │ - // point on edge │ │ │ │ │ - crosses = -1; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (cx <= px) { │ │ │ │ │ - // no crossing to the right │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) { │ │ │ │ │ - // no crossing │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (y1 < y2 && (py >= y1 && py < y2) || // upward │ │ │ │ │ - y1 > y2 && (py < y1 && py >= y2)) { // downward │ │ │ │ │ - ++crosses; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var contained = (crosses == -1) ? │ │ │ │ │ - // on edge │ │ │ │ │ - 1 : │ │ │ │ │ - // even (out) or odd (in) │ │ │ │ │ - !!(crosses & 1); │ │ │ │ │ + /** │ │ │ │ │ + * 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]; │ │ │ │ │ │ │ │ │ │ - return contained; │ │ │ │ │ - }, │ │ │ │ │ + var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.containsPoint(geometry); │ │ │ │ │ - } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString") { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ - } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ - intersect = OpenLayers.Geometry.LineString.prototype.intersects.apply( │ │ │ │ │ - this, [geometry] │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - // check for component intersections │ │ │ │ │ - for (var i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - intersect = geometry.components[i].intersects(this); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - 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) { │ │ │ │ │ - return (nodes === true) ? [] : this.components.slice(0, this.components.length - 1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.LinearRing" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Polygon.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + // merge the style with the current style │ │ │ │ │ + return this.createLiterals( │ │ │ │ │ + OpenLayers.Util.extend(style, symbolizer), feature); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LinearRing.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Polygon │ │ │ │ │ - * Polygon is a collection of Geometry.LinearRings. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Polygon = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.Collection, { │ │ │ │ │ + for (var i in this.propertyStyles) { │ │ │ │ │ + style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); │ │ │ │ │ + } │ │ │ │ │ + return style; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.LinearRing"], │ │ │ │ │ + /** │ │ │ │ │ + * 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 = {}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Polygon │ │ │ │ │ - * Constructor for a Polygon geometry. │ │ │ │ │ - * The first ring (this.component[0])is the outer bounds of the polygon and │ │ │ │ │ - * all subsequent rings (this.component[1-n]) are internal holes. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - */ │ │ │ │ │ + // check the default style │ │ │ │ │ + var style = this.defaultStyle; │ │ │ │ │ + this.addPropertyStyles(propertyStyles, style); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getArea │ │ │ │ │ - * Calculated by subtracting the areas of the internal holes from the │ │ │ │ │ - * area of the outer hole. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {float} The area of the geometry │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - if (this.components && (this.components.length > 0)) { │ │ │ │ │ - area += Math.abs(this.components[0].getArea()); │ │ │ │ │ - for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ - area -= Math.abs(this.components[i].getArea()); │ │ │ │ │ + // 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 area; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 polygon in square meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicArea: function(projection) { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - if (this.components && (this.components.length > 0)) { │ │ │ │ │ - area += Math.abs(this.components[0].getGeodesicArea(projection)); │ │ │ │ │ - for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ - area -= Math.abs(this.components[i].getGeodesicArea(projection)); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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 area; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: containsPoint │ │ │ │ │ - * Test if a point is inside a polygon. Points on a polygon edge are │ │ │ │ │ - * considered inside. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean | Number} The point is inside the polygon. Returns 1 if the │ │ │ │ │ - * point is on an edge. Returns boolean otherwise. │ │ │ │ │ - */ │ │ │ │ │ - containsPoint: function(point) { │ │ │ │ │ - var numRings = this.components.length; │ │ │ │ │ - var contained = false; │ │ │ │ │ - if (numRings > 0) { │ │ │ │ │ - // check exterior ring - 1 means on edge, boolean otherwise │ │ │ │ │ - contained = this.components[0].containsPoint(point); │ │ │ │ │ - if (contained !== 1) { │ │ │ │ │ - if (contained && numRings > 1) { │ │ │ │ │ - // check interior rings │ │ │ │ │ - var hole; │ │ │ │ │ - for (var i = 1; i < numRings; ++i) { │ │ │ │ │ - hole = this.components[i].containsPoint(point); │ │ │ │ │ - if (hole) { │ │ │ │ │ - if (hole === 1) { │ │ │ │ │ - // on edge │ │ │ │ │ - contained = 1; │ │ │ │ │ - } else { │ │ │ │ │ - // in hole │ │ │ │ │ - contained = false; │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return contained; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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: 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; │ │ │ │ │ - var i, len; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - intersect = this.containsPoint(geometry); │ │ │ │ │ - } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString" || │ │ │ │ │ - geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ - // check if rings/linestrings intersect │ │ │ │ │ - for (i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - intersect = geometry.intersects(this.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!intersect) { │ │ │ │ │ - // check if this poly contains points of the ring/linestring │ │ │ │ │ - for (i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - intersect = this.containsPoint(geometry.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - for (i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - intersect = this.intersects(geometry.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // check case where this poly is wholly contained by another │ │ │ │ │ - if (!intersect && geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") { │ │ │ │ │ - // exterior ring points will be contained in the other geometry │ │ │ │ │ - var ring = this.components[0]; │ │ │ │ │ - for (i = 0, len = ring.components.length; i < len; ++i) { │ │ │ │ │ - intersect = geometry.containsPoint(ring.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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]; │ │ │ │ │ } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 result; │ │ │ │ │ - // this is the case where we might not be looking for distance to edge │ │ │ │ │ - if (!edge && this.intersects(geometry)) { │ │ │ │ │ - result = 0; │ │ │ │ │ - } else { │ │ │ │ │ - result = OpenLayers.Geometry.Collection.prototype.distanceTo.apply( │ │ │ │ │ - this, [geometry, options] │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * 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()); │ │ │ │ │ } │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + // 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" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Polygon" │ │ │ │ │ - }); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createRegularPolygon │ │ │ │ │ - * Create a regular polygon around a radius. Useful for creating circles │ │ │ │ │ - * and the like. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * origin - {} center of polygon. │ │ │ │ │ - * radius - {Float} distance to vertex, in map units. │ │ │ │ │ - * sides - {Integer} Number of sides. 20 approximates a circle. │ │ │ │ │ - * rotation - {Float} original angle of rotation, in degrees. │ │ │ │ │ + * 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.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) { │ │ │ │ │ - var angle = Math.PI * ((1 / sides) - (1 / 2)); │ │ │ │ │ - if (rotation) { │ │ │ │ │ - angle += (rotation / 180) * Math.PI; │ │ │ │ │ - } │ │ │ │ │ - var rotatedAngle, x, y; │ │ │ │ │ - var points = []; │ │ │ │ │ - for (var i = 0; i < sides; ++i) { │ │ │ │ │ - rotatedAngle = angle + (i * 2 * Math.PI / sides); │ │ │ │ │ - x = origin.x + (radius * Math.cos(rotatedAngle)); │ │ │ │ │ - y = origin.y + (radius * Math.sin(rotatedAngle)); │ │ │ │ │ - points.push(new OpenLayers.Geometry.Point(x, y)); │ │ │ │ │ +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); │ │ │ │ │ } │ │ │ │ │ - var ring = new OpenLayers.Geometry.LinearRing(points); │ │ │ │ │ - return new OpenLayers.Geometry.Polygon([ring]); │ │ │ │ │ + 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/Geometry/MultiPolygon.js │ │ │ │ │ + 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/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiPolygon │ │ │ │ │ - * MultiPolygon is a geometry with multiple │ │ │ │ │ - * components. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Geometry.MultiPolygon = 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.Polygon"], │ │ │ │ │ +OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiPolygon │ │ │ │ │ - * Create a new MultiPolygon geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} An array of polygons │ │ │ │ │ - * used to generate the MultiPolygon │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.MultiPolygon" │ │ │ │ │ - }); │ │ │ │ │ +/** │ │ │ │ │ + * 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/Format/WKT.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/Format.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WKT │ │ │ │ │ - * Class for reading and writing Well-Known Text. Create a new instance │ │ │ │ │ - * with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Rule │ │ │ │ │ + * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.WKT = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ +OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WKT │ │ │ │ │ - * Create a new parser for WKT │ │ │ │ │ + * 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 whose properties will be set on │ │ │ │ │ - * this instance │ │ │ │ │ - * │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * rule │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A new WKT parser. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - this.regExes = { │ │ │ │ │ - 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/, │ │ │ │ │ - 'spaces': /\s+/, │ │ │ │ │ - 'parenComma': /\)\s*,\s*\(/, │ │ │ │ │ - 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here │ │ │ │ │ - 'trimParens': /^\s*\(?(.*?)\)?\s*$/ │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Format.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.symbolizer = {}; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + if (this.symbolizers) { │ │ │ │ │ + delete this.symbolizer; │ │ │ │ │ + } │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Deserialize a WKT string and return a vector feature or an │ │ │ │ │ - * array of vector features. Supports WKT for POINT, MULTIPOINT, │ │ │ │ │ - * LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, and │ │ │ │ │ - * GEOMETRYCOLLECTION. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * wkt - {String} A WKT string │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {|Array} A feature or array of features for │ │ │ │ │ - * GEOMETRYCOLLECTION WKT. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - read: function(wkt) { │ │ │ │ │ - var features, type, str; │ │ │ │ │ - wkt = wkt.replace(/[\n\r]/g, " "); │ │ │ │ │ - var matches = this.regExes.typeStr.exec(wkt); │ │ │ │ │ - if (matches) { │ │ │ │ │ - type = matches[1].toLowerCase(); │ │ │ │ │ - str = matches[2]; │ │ │ │ │ - if (this.parse[type]) { │ │ │ │ │ - features = this.parse[type].apply(this, [str]); │ │ │ │ │ - } │ │ │ │ │ - if (this.internalProjection && this.externalProjection) { │ │ │ │ │ - if (features && │ │ │ │ │ - features.CLASS_NAME == "OpenLayers.Feature.Vector") { │ │ │ │ │ - features.geometry.transform(this.externalProjection, │ │ │ │ │ - this.internalProjection); │ │ │ │ │ - } else if (features && │ │ │ │ │ - type != "geometrycollection" && │ │ │ │ │ - typeof features == "object") { │ │ │ │ │ - for (var i = 0, len = features.length; i < len; i++) { │ │ │ │ │ - var component = features[i]; │ │ │ │ │ - component.geometry.transform(this.externalProjection, │ │ │ │ │ - this.internalProjection); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i in this.symbolizer) { │ │ │ │ │ + this.symbolizer[i] = null; │ │ │ │ │ } │ │ │ │ │ - return features; │ │ │ │ │ + this.symbolizer = null; │ │ │ │ │ + delete this.symbolizers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Serialize a feature or array of features into a WKT string. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * evaluates this rule for a specific feature │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {|Array} A feature or array of │ │ │ │ │ - * features │ │ │ │ │ - * │ │ │ │ │ + * feature - {} feature to apply the rule to. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The WKT string representation of the input geometries │ │ │ │ │ + * {Boolean} true if the rule applies, false if it does not. │ │ │ │ │ + * This rule is the default rule and always returns true. │ │ │ │ │ */ │ │ │ │ │ - write: function(features) { │ │ │ │ │ - var collection, geometry, isCollection; │ │ │ │ │ - if (features.constructor == Array) { │ │ │ │ │ - collection = features; │ │ │ │ │ - isCollection = true; │ │ │ │ │ - } else { │ │ │ │ │ - collection = [features]; │ │ │ │ │ - isCollection = false; │ │ │ │ │ + evaluate: function(feature) { │ │ │ │ │ + var context = this.getContext(feature); │ │ │ │ │ + var applies = true; │ │ │ │ │ + │ │ │ │ │ + if (this.minScaleDenominator || this.maxScaleDenominator) { │ │ │ │ │ + var scale = feature.layer.map.getScale(); │ │ │ │ │ } │ │ │ │ │ - var pieces = []; │ │ │ │ │ - if (isCollection) { │ │ │ │ │ - pieces.push('GEOMETRYCOLLECTION('); │ │ │ │ │ + │ │ │ │ │ + // check if within minScale/maxScale bounds │ │ │ │ │ + if (this.minScaleDenominator) { │ │ │ │ │ + applies = scale >= OpenLayers.Style.createLiteral( │ │ │ │ │ + this.minScaleDenominator, context); │ │ │ │ │ } │ │ │ │ │ - for (var i = 0, len = collection.length; i < len; ++i) { │ │ │ │ │ - if (isCollection && i > 0) { │ │ │ │ │ - pieces.push(','); │ │ │ │ │ - } │ │ │ │ │ - geometry = collection[i].geometry; │ │ │ │ │ - pieces.push(this.extractGeometry(geometry)); │ │ │ │ │ + if (applies && this.maxScaleDenominator) { │ │ │ │ │ + applies = scale < OpenLayers.Style.createLiteral( │ │ │ │ │ + this.maxScaleDenominator, context); │ │ │ │ │ } │ │ │ │ │ - if (isCollection) { │ │ │ │ │ - pieces.push(')'); │ │ │ │ │ + │ │ │ │ │ + // 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 pieces.join(''); │ │ │ │ │ + │ │ │ │ │ + return applies; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: extractGeometry │ │ │ │ │ - * Entry point to construct the WKT for a single Geometry object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A WKT string of representing the geometry │ │ │ │ │ + * Method: getContext │ │ │ │ │ + * Gets the context for evaluating this rule │ │ │ │ │ + * │ │ │ │ │ + * Paramters: │ │ │ │ │ + * feature - {} feature to take the context from if │ │ │ │ │ + * none is specified. │ │ │ │ │ */ │ │ │ │ │ - extractGeometry: function(geometry) { │ │ │ │ │ - var type = geometry.CLASS_NAME.split('.')[2].toLowerCase(); │ │ │ │ │ - if (!this.extract[type]) { │ │ │ │ │ - return null; │ │ │ │ │ + getContext: function(feature) { │ │ │ │ │ + var context = this.context; │ │ │ │ │ + if (!context) { │ │ │ │ │ + context = feature.attributes || feature.data; │ │ │ │ │ } │ │ │ │ │ - if (this.internalProjection && this.externalProjection) { │ │ │ │ │ - geometry = geometry.clone(); │ │ │ │ │ - geometry.transform(this.internalProjection, this.externalProjection); │ │ │ │ │ + if (typeof this.context == "function") { │ │ │ │ │ + context = this.context(feature); │ │ │ │ │ } │ │ │ │ │ - var wktType = type == 'collection' ? 'GEOMETRYCOLLECTION' : type.toUpperCase(); │ │ │ │ │ - var data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')'; │ │ │ │ │ - return data; │ │ │ │ │ + return context; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Object with properties corresponding to the geometry types. │ │ │ │ │ - * Property values are functions that do the actual data extraction. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this rule. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this rule. │ │ │ │ │ */ │ │ │ │ │ - extract: { │ │ │ │ │ - /** │ │ │ │ │ - * Return a space delimited string of point coordinates. │ │ │ │ │ - * @param {OpenLayers.Geometry.Point} point │ │ │ │ │ - * @returns {String} A string of coordinates representing the point │ │ │ │ │ - */ │ │ │ │ │ - 'point': function(point) { │ │ │ │ │ - return point.x + ' ' + point.y; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Return a comma delimited string of point coordinates from a multipoint. │ │ │ │ │ - * @param {OpenLayers.Geometry.MultiPoint} multipoint │ │ │ │ │ - * @returns {String} A string of point coordinate strings representing │ │ │ │ │ - * the multipoint │ │ │ │ │ - */ │ │ │ │ │ - 'multipoint': function(multipoint) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multipoint.components.length; i < len; ++i) { │ │ │ │ │ - array.push('(' + │ │ │ │ │ - this.extract.point.apply(this, [multipoint.components[i]]) + │ │ │ │ │ - ')'); │ │ │ │ │ - } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Return a comma delimited string of point coordinates from a line. │ │ │ │ │ - * @param {OpenLayers.Geometry.LineString} linestring │ │ │ │ │ - * @returns {String} A string of point coordinate strings representing │ │ │ │ │ - * the linestring │ │ │ │ │ - */ │ │ │ │ │ - 'linestring': function(linestring) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = linestring.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.point.apply(this, [linestring.components[i]])); │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Return a comma delimited string of linestring strings from a multilinestring. │ │ │ │ │ - * @param {OpenLayers.Geometry.MultiLineString} multilinestring │ │ │ │ │ - * @returns {String} A string of of linestring strings representing │ │ │ │ │ - * the multilinestring │ │ │ │ │ - */ │ │ │ │ │ - 'multilinestring': function(multilinestring) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multilinestring.components.length; i < len; ++i) { │ │ │ │ │ - array.push('(' + │ │ │ │ │ - this.extract.linestring.apply(this, [multilinestring.components[i]]) + │ │ │ │ │ - ')'); │ │ │ │ │ + } 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + // 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return a comma delimited string of linear ring arrays from a polygon. │ │ │ │ │ - * @param {OpenLayers.Geometry.Polygon} polygon │ │ │ │ │ - * @returns {String} An array of linear ring arrays representing the polygon │ │ │ │ │ - */ │ │ │ │ │ - 'polygon': function(polygon) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = polygon.components.length; i < len; ++i) { │ │ │ │ │ - array.push('(' + │ │ │ │ │ - this.extract.linestring.apply(this, [polygon.components[i]]) + │ │ │ │ │ - ')'); │ │ │ │ │ - } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/StyleMap.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return an array of polygon arrays from a multipolygon. │ │ │ │ │ - * @param {OpenLayers.Geometry.MultiPolygon} multipolygon │ │ │ │ │ - * @returns {String} An array of polygon arrays representing │ │ │ │ │ - * the multipolygon │ │ │ │ │ - */ │ │ │ │ │ - 'multipolygon': function(multipolygon) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multipolygon.components.length; i < len; ++i) { │ │ │ │ │ - array.push('(' + │ │ │ │ │ - this.extract.polygon.apply(this, [multipolygon.components[i]]) + │ │ │ │ │ - ')'); │ │ │ │ │ - } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - }, │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an │ │ │ │ │ - * @param {OpenLayers.Geometry.Collection} collection │ │ │ │ │ - * @returns {String} internal WKT representation of the collection │ │ │ │ │ - */ │ │ │ │ │ - 'collection': function(collection) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = collection.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extractGeometry.apply(this, [collection.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array.join(','); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.StyleMap │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.StyleMap = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Object with properties corresponding to the geometry types. │ │ │ │ │ - * Property values are functions that do the actual parsing. │ │ │ │ │ + * Property: styles │ │ │ │ │ + * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ + * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ */ │ │ │ │ │ - parse: { │ │ │ │ │ - /** │ │ │ │ │ - * Return point feature given a point WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the point │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A point feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'point': function(str) { │ │ │ │ │ - var coords = OpenLayers.String.trim(str).split(this.regExes.spaces); │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(coords[0], coords[1]) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Return a multipoint feature given a multipoint WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the multipoint │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A multipoint feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'multipoint': function(str) { │ │ │ │ │ - var point; │ │ │ │ │ - var points = OpenLayers.String.trim(str).split(','); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = points.length; i < len; ++i) { │ │ │ │ │ - point = points[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ - components.push(this.parse.point.apply(this, [point]).geometry); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.MultiPoint(components) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + styles: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return a linestring feature given a linestring WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the linestring │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A linestring feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'linestring': function(str) { │ │ │ │ │ - var points = OpenLayers.String.trim(str).split(','); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = points.length; i < len; ++i) { │ │ │ │ │ - components.push(this.parse.point.apply(this, [points[i]]).geometry); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LineString(components) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return a multilinestring feature given a multilinestring WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the multilinestring │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A multilinestring feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'multilinestring': function(str) { │ │ │ │ │ - var line; │ │ │ │ │ - var lines = OpenLayers.String.trim(str).split(this.regExes.parenComma); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = lines.length; i < len; ++i) { │ │ │ │ │ - line = lines[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ - components.push(this.parse.linestring.apply(this, [line]).geometry); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString(components) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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"]) │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return a polygon feature given a polygon WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the polygon │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A polygon feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'polygon': function(str) { │ │ │ │ │ - var ring, linestring, linearring; │ │ │ │ │ - var rings = OpenLayers.String.trim(str).split(this.regExes.parenComma); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = rings.length; i < len; ++i) { │ │ │ │ │ - ring = rings[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ - linestring = this.parse.linestring.apply(this, [ring]).geometry; │ │ │ │ │ - linearring = new OpenLayers.Geometry.LinearRing(linestring.components); │ │ │ │ │ - components.push(linearring); │ │ │ │ │ + // 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Polygon(components) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return a multipolygon feature given a multipolygon WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the multipolygon │ │ │ │ │ - * @returns {OpenLayers.Feature.Vector} A multipolygon feature │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'multipolygon': function(str) { │ │ │ │ │ - var polygon; │ │ │ │ │ - var polygons = OpenLayers.String.trim(str).split(this.regExes.doubleParenComma); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = polygons.length; i < len; ++i) { │ │ │ │ │ - polygon = polygons[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ - components.push(this.parse.polygon.apply(this, [polygon]).geometry); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.MultiPolygon(components) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var key in this.styles) { │ │ │ │ │ + this.styles[key].destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.styles = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Return an array of features given a geometrycollection WKT fragment. │ │ │ │ │ - * @param {String} str A WKT fragment representing the geometrycollection │ │ │ │ │ - * @returns {Array} An array of OpenLayers.Feature.Vector │ │ │ │ │ - * @private │ │ │ │ │ - */ │ │ │ │ │ - 'geometrycollection': function(str) { │ │ │ │ │ - // separate components of the collection with | │ │ │ │ │ - str = str.replace(/,\s*([A-Za-z])/g, '|$1'); │ │ │ │ │ - var wktArray = OpenLayers.String.trim(str).split('|'); │ │ │ │ │ - var components = []; │ │ │ │ │ - for (var i = 0, len = wktArray.length; i < len; ++i) { │ │ │ │ │ - components.push(OpenLayers.Format.WKT.prototype.read.apply(this, [wktArray[i]])); │ │ │ │ │ - } │ │ │ │ │ - return components; │ │ │ │ │ + /** │ │ │ │ │ + * 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.Format.WKT" │ │ │ │ │ + CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/JSON.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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Note: │ │ │ │ │ - * This work draws heavily from the public domain JSON serializer/deserializer │ │ │ │ │ - * at http://www.json.org/json.js. Rewritten so that it doesn't modify │ │ │ │ │ - * basic data prototypes. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Format.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.JSON │ │ │ │ │ - * A parser to read/write JSON safely. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * 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()); │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Format.JSON = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ +OpenLayers.Control = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: indent │ │ │ │ │ - * {String} For "pretty" printing, the indent string will be used once for │ │ │ │ │ - * each indentation level. │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - indent: " ", │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: space │ │ │ │ │ - * {String} For "pretty" printing, the space string will be used after │ │ │ │ │ - * the ":" separating a name/value pair. │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} this gets set in the addControl() function in │ │ │ │ │ + * OpenLayers.Map │ │ │ │ │ */ │ │ │ │ │ - space: " ", │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: newline │ │ │ │ │ - * {String} For "pretty" printing, the newline string will be used at the │ │ │ │ │ - * end of each name/value pair or array item. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} The element that contains the control, if not present the │ │ │ │ │ + * control is placed inside the map. │ │ │ │ │ */ │ │ │ │ │ - newline: "\n", │ │ │ │ │ + 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: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: level │ │ │ │ │ - * {Integer} For "pretty" printing, this is incremented/decremented during │ │ │ │ │ - * serialization. │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {string} This property is used for showing a tooltip over the │ │ │ │ │ + * Control. │ │ │ │ │ */ │ │ │ │ │ - level: 0, │ │ │ │ │ + title: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pretty │ │ │ │ │ - * {Boolean} Serialize with extra whitespace for structure. This is set │ │ │ │ │ - * by the method. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - pretty: false, │ │ │ │ │ + autoActivate: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: active │ │ │ │ │ + * {Boolean} The control is active (read-only). Use and │ │ │ │ │ + * to change control state. │ │ │ │ │ + */ │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: nativeJSON │ │ │ │ │ - * {Boolean} Does the browser support native json? │ │ │ │ │ + * Property: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - nativeJSON: (function() { │ │ │ │ │ - return !!(window.JSON && typeof JSON.parse == "function" && typeof JSON.stringify == "function"); │ │ │ │ │ - })(), │ │ │ │ │ + handlerOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.JSON │ │ │ │ │ - * Create a new parser for JSON. │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Deserialize a json string. │ │ │ │ │ + * 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: │ │ │ │ │ - * json - {String} A JSON string │ │ │ │ │ - * filter - {Function} A function which will be called for every key and │ │ │ │ │ - * value at every level of the final result. Each value will be │ │ │ │ │ - * replaced by the result of the filter function. This can be used to │ │ │ │ │ - * reform generic objects into instances of classes, or to transform │ │ │ │ │ - * date strings into Date objects. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object, array, string, or number . │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - read: function(json, filter) { │ │ │ │ │ - var object; │ │ │ │ │ - if (this.nativeJSON) { │ │ │ │ │ - object = JSON.parse(json, filter); │ │ │ │ │ - } else try { │ │ │ │ │ - /** │ │ │ │ │ - * Parsing happens in three stages. In the first stage, we run the │ │ │ │ │ - * text against a regular expression which looks for non-JSON │ │ │ │ │ - * characters. We are especially concerned with '()' and 'new' │ │ │ │ │ - * because they can cause invocation, and '=' because it can │ │ │ │ │ - * cause mutation. But just to be safe, we will reject all │ │ │ │ │ - * unexpected characters. │ │ │ │ │ - */ │ │ │ │ │ - if (/^[\],:{}\s]*$/.test(json.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { │ │ │ │ │ + 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, ""); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * In the second stage we use the eval function to compile the │ │ │ │ │ - * text into a JavaScript structure. The '{' operator is │ │ │ │ │ - * subject to a syntactic ambiguity in JavaScript - it can │ │ │ │ │ - * begin a block or an object literal. We wrap the text in │ │ │ │ │ - * parens to eliminate the ambiguity. │ │ │ │ │ - */ │ │ │ │ │ - object = eval('(' + json + ')'); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * In the optional third stage, we recursively walk the new │ │ │ │ │ - * structure, passing each name/value pair to a filter │ │ │ │ │ - * function for possible transformation. │ │ │ │ │ - */ │ │ │ │ │ - if (typeof filter === 'function') { │ │ │ │ │ - function walk(k, v) { │ │ │ │ │ - if (v && typeof v === 'object') { │ │ │ │ │ - for (var i in v) { │ │ │ │ │ - if (v.hasOwnProperty(i)) { │ │ │ │ │ - v[i] = walk(i, v[i]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return filter(k, v); │ │ │ │ │ - } │ │ │ │ │ - object = walk('', object); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } catch (e) { │ │ │ │ │ - // Fall through if the regexp test fails. │ │ │ │ │ + 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 + "_"); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.keepData) { │ │ │ │ │ - this.data = object; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ │ │ │ │ │ - return object; │ │ │ │ │ + // 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Serialize an object into a JSON string. │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * value - {String} The object, array, string, number, boolean or date │ │ │ │ │ - * to be serialized. │ │ │ │ │ - * pretty - {Boolean} Structure the output with newlines and indentation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The JSON string representation of the input value. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - write: function(value, pretty) { │ │ │ │ │ - this.pretty = !!pretty; │ │ │ │ │ - var json = null; │ │ │ │ │ - var type = typeof value; │ │ │ │ │ - if (this.serialize[type]) { │ │ │ │ │ - try { │ │ │ │ │ - json = (!this.pretty && this.nativeJSON) ? │ │ │ │ │ - JSON.stringify(value) : │ │ │ │ │ - this.serialize[type].apply(this, [value]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - OpenLayers.Console.error("Trouble serializing: " + err); │ │ │ │ │ - } │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.setMap(map); │ │ │ │ │ } │ │ │ │ │ - return json; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeIndent │ │ │ │ │ - * Output an indentation string depending on the indentation level. │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} An appropriate indentation string. │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ */ │ │ │ │ │ - writeIndent: function() { │ │ │ │ │ - var pieces = []; │ │ │ │ │ - if (this.pretty) { │ │ │ │ │ - for (var i = 0; i < this.level; ++i) { │ │ │ │ │ - pieces.push(this.indent); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return pieces.join(''); │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.position = px.clone(); │ │ │ │ │ + } │ │ │ │ │ + this.moveTo(this.position); │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeNewline │ │ │ │ │ - * Output a string representing a newline if in pretty printing mode. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ + * coordinates. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representing a new line. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - writeNewline: function() { │ │ │ │ │ - return (this.pretty) ? this.newline : ''; │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.div != null)) { │ │ │ │ │ + this.div.style.left = px.x + "px"; │ │ │ │ │ + this.div.style.top = px.y + "px"; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeSpace │ │ │ │ │ - * Output a string representing a space if in pretty printing mode. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} A space. │ │ │ │ │ + * {Boolean} True if the control was successfully activated or │ │ │ │ │ + * false if the control was already active. │ │ │ │ │ */ │ │ │ │ │ - writeSpace: function() { │ │ │ │ │ - return (this.pretty) ? this.space : ''; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: serialize │ │ │ │ │ - * Object with properties corresponding to the serializable data types. │ │ │ │ │ - * Property values are functions that do the actual serializing. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - serialize: { │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.object │ │ │ │ │ - * Transform an object into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} The object to be serialized. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the object. │ │ │ │ │ - */ │ │ │ │ │ - 'object': function(object) { │ │ │ │ │ - // three special objects that we want to treat differently │ │ │ │ │ - if (object == null) { │ │ │ │ │ - return "null"; │ │ │ │ │ - } │ │ │ │ │ - if (object.constructor == Date) { │ │ │ │ │ - return this.serialize.date.apply(this, [object]); │ │ │ │ │ - } │ │ │ │ │ - if (object.constructor == Array) { │ │ │ │ │ - return this.serialize.array.apply(this, [object]); │ │ │ │ │ - } │ │ │ │ │ - var pieces = ['{']; │ │ │ │ │ - this.level += 1; │ │ │ │ │ - var key, keyJSON, valueJSON; │ │ │ │ │ - │ │ │ │ │ - var addComma = false; │ │ │ │ │ - for (key in object) { │ │ │ │ │ - if (object.hasOwnProperty(key)) { │ │ │ │ │ - // recursive calls need to allow for sub-classing │ │ │ │ │ - keyJSON = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ - [key, this.pretty]); │ │ │ │ │ - valueJSON = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ - [object[key], this.pretty]); │ │ │ │ │ - if (keyJSON != null && valueJSON != null) { │ │ │ │ │ - if (addComma) { │ │ │ │ │ - pieces.push(','); │ │ │ │ │ - } │ │ │ │ │ - pieces.push(this.writeNewline(), this.writeIndent(), │ │ │ │ │ - keyJSON, ':', this.writeSpace(), valueJSON); │ │ │ │ │ - addComma = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.level -= 1; │ │ │ │ │ - pieces.push(this.writeNewline(), this.writeIndent(), '}'); │ │ │ │ │ - return pieces.join(''); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.array │ │ │ │ │ - * Transform an array into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Array} The array to be serialized │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the array. │ │ │ │ │ - */ │ │ │ │ │ - 'array': function(array) { │ │ │ │ │ - var json; │ │ │ │ │ - var pieces = ['[']; │ │ │ │ │ - this.level += 1; │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - // recursive calls need to allow for sub-classing │ │ │ │ │ - json = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ - [array[i], this.pretty]); │ │ │ │ │ - if (json != null) { │ │ │ │ │ - if (i > 0) { │ │ │ │ │ - pieces.push(','); │ │ │ │ │ - } │ │ │ │ │ - pieces.push(this.writeNewline(), this.writeIndent(), json); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.level -= 1; │ │ │ │ │ - pieces.push(this.writeNewline(), this.writeIndent(), ']'); │ │ │ │ │ - return pieces.join(''); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.string │ │ │ │ │ - * Transform a string into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * string - {String} The string to be serialized │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the string. │ │ │ │ │ - */ │ │ │ │ │ - 'string': function(string) { │ │ │ │ │ - // If the string contains no control characters, no quote characters, and no │ │ │ │ │ - // backslash characters, then we can simply slap some quotes around it. │ │ │ │ │ - // Otherwise we must also replace the offending characters with safe │ │ │ │ │ - // sequences. │ │ │ │ │ - var m = { │ │ │ │ │ - '\b': '\\b', │ │ │ │ │ - '\t': '\\t', │ │ │ │ │ - '\n': '\\n', │ │ │ │ │ - '\f': '\\f', │ │ │ │ │ - '\r': '\\r', │ │ │ │ │ - '"': '\\"', │ │ │ │ │ - '\\': '\\\\' │ │ │ │ │ - }; │ │ │ │ │ - if (/["\\\x00-\x1f]/.test(string)) { │ │ │ │ │ - return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) { │ │ │ │ │ - var c = m[b]; │ │ │ │ │ - if (c) { │ │ │ │ │ - return c; │ │ │ │ │ - } │ │ │ │ │ - c = b.charCodeAt(); │ │ │ │ │ - return '\\u00' + │ │ │ │ │ - Math.floor(c / 16).toString(16) + │ │ │ │ │ - (c % 16).toString(16); │ │ │ │ │ - }) + '"'; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.deactivate(); │ │ │ │ │ } │ │ │ │ │ - return '"' + string + '"'; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.number │ │ │ │ │ - * Transform a number into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * number - {Number} The number to be serialized. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the number. │ │ │ │ │ - */ │ │ │ │ │ - 'number': function(number) { │ │ │ │ │ - return isFinite(number) ? String(number) : "null"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.boolean │ │ │ │ │ - * Transform a boolean into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bool - {Boolean} The boolean to be serialized. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the boolean. │ │ │ │ │ - */ │ │ │ │ │ - 'boolean': function(bool) { │ │ │ │ │ - return String(bool); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: serialize.object │ │ │ │ │ - * Transform a date into a JSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * date - {Date} The date to be serialized. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A JSON string representing the date. │ │ │ │ │ - */ │ │ │ │ │ - 'date': function(date) { │ │ │ │ │ - function format(number) { │ │ │ │ │ - // Format integers to have at least two digits. │ │ │ │ │ - return (number < 10) ? '0' + number : number; │ │ │ │ │ + this.active = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, │ │ │ │ │ + this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return '"' + date.getFullYear() + '-' + │ │ │ │ │ - format(date.getMonth() + 1) + '-' + │ │ │ │ │ - format(date.getDate()) + 'T' + │ │ │ │ │ - format(date.getHours()) + ':' + │ │ │ │ │ - format(date.getMinutes()) + ':' + │ │ │ │ │ - format(date.getSeconds()) + '"'; │ │ │ │ │ + this.events.triggerEvent("deactivate"); │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.JSON" │ │ │ │ │ - │ │ │ │ │ + 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/Format/GeoJSON.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/Format/JSON.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.GeoJSON │ │ │ │ │ - * Read and write GeoJSON. Create a new parser 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. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { │ │ │ │ │ +OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: ignoreExtraDims │ │ │ │ │ - * {Boolean} Ignore dimensions higher than 2 when reading geometry │ │ │ │ │ - * coordinates. │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} image url │ │ │ │ │ */ │ │ │ │ │ - ignoreExtraDims: false, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.GeoJSON │ │ │ │ │ - * Create a new parser for GeoJSON. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Deserialize a GeoJSON string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * json - {String} A GeoJSON string │ │ │ │ │ - * type - {String} Optional string that determines the structure of │ │ │ │ │ - * the output. Supported values are "Geometry", "Feature", and │ │ │ │ │ - * "FeatureCollection". If absent or null, a default of │ │ │ │ │ - * "FeatureCollection" is assumed. │ │ │ │ │ - * filter - {Function} A function which will be called for every key and │ │ │ │ │ - * value at every level of the final result. Each value will be │ │ │ │ │ - * replaced by the result of the filter function. This can be used to │ │ │ │ │ - * reform generic objects into instances of classes, or to transform │ │ │ │ │ - * date strings into Date objects. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} The return depends on the value of the type argument. If type │ │ │ │ │ - * is "FeatureCollection" (the default), the return will be an array │ │ │ │ │ - * of . If type is "Geometry", the input json │ │ │ │ │ - * must represent a single geometry, and the return will be an │ │ │ │ │ - * . If type is "Feature", the input json must │ │ │ │ │ - * represent a single feature, and the return will be an │ │ │ │ │ - * . │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - read: function(json, type, filter) { │ │ │ │ │ - type = (type) ? type : "FeatureCollection"; │ │ │ │ │ - var results = null; │ │ │ │ │ - var obj = null; │ │ │ │ │ - if (typeof json == "string") { │ │ │ │ │ - obj = OpenLayers.Format.JSON.prototype.read.apply(this, │ │ │ │ │ - [json, filter]); │ │ │ │ │ - } else { │ │ │ │ │ - obj = json; │ │ │ │ │ - } │ │ │ │ │ - if (!obj) { │ │ │ │ │ - OpenLayers.Console.error("Bad JSON: " + json); │ │ │ │ │ - } else if (typeof(obj.type) != "string") { │ │ │ │ │ - OpenLayers.Console.error("Bad GeoJSON - no type: " + json); │ │ │ │ │ - } else if (this.isValidType(obj, type)) { │ │ │ │ │ - switch (type) { │ │ │ │ │ - case "Geometry": │ │ │ │ │ - try { │ │ │ │ │ - results = this.parseGeometry(obj); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - OpenLayers.Console.error(err); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case "Feature": │ │ │ │ │ - try { │ │ │ │ │ - results = this.parseFeature(obj); │ │ │ │ │ - results.type = "Feature"; │ │ │ │ │ - } catch (err) { │ │ │ │ │ - OpenLayers.Console.error(err); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case "FeatureCollection": │ │ │ │ │ - // for type FeatureCollection, we allow input to be any type │ │ │ │ │ - results = []; │ │ │ │ │ - switch (obj.type) { │ │ │ │ │ - case "Feature": │ │ │ │ │ - try { │ │ │ │ │ - results.push(this.parseFeature(obj)); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - results = null; │ │ │ │ │ - OpenLayers.Console.error(err); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case "FeatureCollection": │ │ │ │ │ - for (var i = 0, len = obj.features.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - results.push(this.parseFeature(obj.features[i])); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - results = null; │ │ │ │ │ - OpenLayers.Console.error(err); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - try { │ │ │ │ │ - var geom = this.parseGeometry(obj); │ │ │ │ │ - results.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - results = null; │ │ │ │ │ - OpenLayers.Console.error(err); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return results; │ │ │ │ │ + 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: isValidType │ │ │ │ │ - * Check if a GeoJSON object is a valid representative of the given type. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The object is valid GeoJSON object of the given type. │ │ │ │ │ + * {} A fresh copy of the icon. │ │ │ │ │ */ │ │ │ │ │ - isValidType: function(obj, type) { │ │ │ │ │ - var valid = false; │ │ │ │ │ - switch (type) { │ │ │ │ │ - case "Geometry": │ │ │ │ │ - if (OpenLayers.Util.indexOf( │ │ │ │ │ - ["Point", "MultiPoint", "LineString", "MultiLineString", │ │ │ │ │ - "Polygon", "MultiPolygon", "Box", "GeometryCollection" │ │ │ │ │ - ], │ │ │ │ │ - obj.type) == -1) { │ │ │ │ │ - // unsupported geometry type │ │ │ │ │ - OpenLayers.Console.error("Unsupported geometry type: " + │ │ │ │ │ - obj.type); │ │ │ │ │ - } else { │ │ │ │ │ - valid = true; │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case "FeatureCollection": │ │ │ │ │ - // allow for any type to be converted to a feature collection │ │ │ │ │ - valid = true; │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - // for Feature types must match │ │ │ │ │ - if (obj.type == type) { │ │ │ │ │ - valid = true; │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Console.error("Cannot convert types from " + │ │ │ │ │ - obj.type + " to " + type); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return valid; │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Icon(this.url, │ │ │ │ │ + this.size, │ │ │ │ │ + this.offset, │ │ │ │ │ + this.calculateOffset); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseFeature │ │ │ │ │ - * Convert a feature object from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} An object created from a GeoJSON object │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature. │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ - parseFeature: function(obj) { │ │ │ │ │ - var feature, geometry, attributes, bbox; │ │ │ │ │ - attributes = (obj.properties) ? obj.properties : {}; │ │ │ │ │ - bbox = (obj.geometry && obj.geometry.bbox) || obj.bbox; │ │ │ │ │ - try { │ │ │ │ │ - geometry = this.parseGeometry(obj.geometry); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - // deal with bad geometries │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - feature = new OpenLayers.Feature.Vector(geometry, attributes); │ │ │ │ │ - if (bbox) { │ │ │ │ │ - feature.bounds = OpenLayers.Bounds.fromArray(bbox); │ │ │ │ │ - } │ │ │ │ │ - if (obj.id) { │ │ │ │ │ - feature.fid = obj.id; │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + if (size != null) { │ │ │ │ │ + this.size = size; │ │ │ │ │ } │ │ │ │ │ - return feature; │ │ │ │ │ + this.draw(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseGeometry │ │ │ │ │ - * Convert a geometry object from GeoJSON into an . │ │ │ │ │ - * │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} An object created from a GeoJSON object │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - parseGeometry: function(obj) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - var geometry, collection = false; │ │ │ │ │ - if (obj.type == "GeometryCollection") { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(obj.geometries))) { │ │ │ │ │ - throw "GeometryCollection must have geometries array: " + obj; │ │ │ │ │ - } │ │ │ │ │ - var numGeom = obj.geometries.length; │ │ │ │ │ - var components = new Array(numGeom); │ │ │ │ │ - for (var i = 0; i < numGeom; ++i) { │ │ │ │ │ - components[i] = this.parseGeometry.apply( │ │ │ │ │ - this, [obj.geometries[i]] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - geometry = new OpenLayers.Geometry.Collection(components); │ │ │ │ │ - collection = true; │ │ │ │ │ - } else { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(obj.coordinates))) { │ │ │ │ │ - throw "Geometry must have coordinates array: " + obj; │ │ │ │ │ - } │ │ │ │ │ - if (!this.parseCoords[obj.type.toLowerCase()]) { │ │ │ │ │ - throw "Unsupported geometry type: " + obj.type; │ │ │ │ │ - } │ │ │ │ │ - try { │ │ │ │ │ - geometry = this.parseCoords[obj.type.toLowerCase()].apply( │ │ │ │ │ - this, [obj.coordinates] │ │ │ │ │ - ); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - // deal with bad coordinates │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // We don't reproject collections because the children are reprojected │ │ │ │ │ - // for us when they are created. │ │ │ │ │ - if (this.internalProjection && this.externalProjection && !collection) { │ │ │ │ │ - geometry.transform(this.externalProjection, │ │ │ │ │ - this.internalProjection); │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + if (url != null) { │ │ │ │ │ + this.url = url; │ │ │ │ │ } │ │ │ │ │ - return geometry; │ │ │ │ │ + this.draw(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: parseCoords │ │ │ │ │ - * Object with properties corresponding to the GeoJSON geometry types. │ │ │ │ │ - * Property values are functions that do the actual parsing. │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - parseCoords: { │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.point │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "point": function(array) { │ │ │ │ │ - if (this.ignoreExtraDims == false && │ │ │ │ │ - array.length != 2) { │ │ │ │ │ - throw "Only 2D points are supported: " + array; │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.Point(array[0], array[1]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.multipoint │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "multipoint": function(array) { │ │ │ │ │ - var points = []; │ │ │ │ │ - var p = null; │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - p = this.parseCoords["point"].apply(this, [array[i]]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - points.push(p); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.MultiPoint(points); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.linestring │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "linestring": function(array) { │ │ │ │ │ - var points = []; │ │ │ │ │ - var p = null; │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - p = this.parseCoords["point"].apply(this, [array[i]]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - points.push(p); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.LineString(points); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.multilinestring │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "multilinestring": function(array) { │ │ │ │ │ - var lines = []; │ │ │ │ │ - var l = null; │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - l = this.parseCoords["linestring"].apply(this, [array[i]]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - lines.push(l); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.MultiLineString(lines); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.polygon │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "polygon": function(array) { │ │ │ │ │ - var rings = []; │ │ │ │ │ - var r, l; │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - l = this.parseCoords["linestring"].apply(this, [array[i]]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - r = new OpenLayers.Geometry.LinearRing(l.components); │ │ │ │ │ - rings.push(r); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.Polygon(rings); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.multipolygon │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "multipolygon": function(array) { │ │ │ │ │ - var polys = []; │ │ │ │ │ - var p = null; │ │ │ │ │ - for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ - try { │ │ │ │ │ - p = this.parseCoords["polygon"].apply(this, [array[i]]); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - throw err; │ │ │ │ │ - } │ │ │ │ │ - polys.push(p); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.MultiPolygon(polys); │ │ │ │ │ - }, │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + this.size, │ │ │ │ │ + this.url, │ │ │ │ │ + "absolute"); │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + return this.imageDiv; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseCoords.box │ │ │ │ │ - * Convert a coordinate array from GeoJSON into an │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry. │ │ │ │ │ - */ │ │ │ │ │ - "box": function(array) { │ │ │ │ │ - if (array.length != 2) { │ │ │ │ │ - throw "GeoJSON box coordinates must have 2 elements"; │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.Polygon([ │ │ │ │ │ - new OpenLayers.Geometry.LinearRing([ │ │ │ │ │ - new OpenLayers.Geometry.Point(array[0][0], array[0][1]), │ │ │ │ │ - new OpenLayers.Geometry.Point(array[1][0], array[0][1]), │ │ │ │ │ - new OpenLayers.Geometry.Point(array[1][0], array[1][1]), │ │ │ │ │ - new OpenLayers.Geometry.Point(array[0][0], array[1][1]), │ │ │ │ │ - new OpenLayers.Geometry.Point(array[0][0], array[0][1]) │ │ │ │ │ - ]) │ │ │ │ │ - ]); │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erase the underlying image element. │ │ │ │ │ + */ │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ + OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Serialize a feature, geometry, array of features into a GeoJSON string. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the icon's opacity │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} An , , │ │ │ │ │ - * or an array of features. │ │ │ │ │ - * pretty - {Boolean} Structure the output with newlines and indentation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The GeoJSON string representation of the input geometry, │ │ │ │ │ - * features, or array of features. │ │ │ │ │ + * opacity - {float} │ │ │ │ │ */ │ │ │ │ │ - write: function(obj, pretty) { │ │ │ │ │ - var geojson = { │ │ │ │ │ - "type": null │ │ │ │ │ - }; │ │ │ │ │ - if (OpenLayers.Util.isArray(obj)) { │ │ │ │ │ - geojson.type = "FeatureCollection"; │ │ │ │ │ - var numFeatures = obj.length; │ │ │ │ │ - geojson.features = new Array(numFeatures); │ │ │ │ │ - for (var i = 0; i < numFeatures; ++i) { │ │ │ │ │ - var element = obj[i]; │ │ │ │ │ - if (!element instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - var msg = "FeatureCollection only supports collections " + │ │ │ │ │ - "of features: " + element; │ │ │ │ │ - throw msg; │ │ │ │ │ - } │ │ │ │ │ - geojson.features[i] = this.extract.feature.apply( │ │ │ │ │ - this, [element] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } else if (obj.CLASS_NAME.indexOf("OpenLayers.Geometry") == 0) { │ │ │ │ │ - geojson = this.extract.geometry.apply(this, [obj]); │ │ │ │ │ - } else if (obj instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - geojson = this.extract.feature.apply(this, [obj]); │ │ │ │ │ - if (obj.layer && obj.layer.projection) { │ │ │ │ │ - geojson.crs = this.createCRSObject(obj); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ - [geojson, pretty]); │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ + null, null, null, null, opacity); │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createCRSObject │ │ │ │ │ - * Create the CRS object for an object. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * move icon to passed in px. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * object - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object which can be assigned to the crs property │ │ │ │ │ - * of a GeoJSON object. │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - createCRSObject: function(object) { │ │ │ │ │ - var proj = object.layer.projection.toString(); │ │ │ │ │ - var crs = {}; │ │ │ │ │ - if (proj.match(/epsg:/i)) { │ │ │ │ │ - var code = parseInt(proj.substring(proj.indexOf(":") + 1)); │ │ │ │ │ - if (code == 4326) { │ │ │ │ │ - crs = { │ │ │ │ │ - "type": "name", │ │ │ │ │ - "properties": { │ │ │ │ │ - "name": "urn:ogc:def:crs:OGC:1.3:CRS84" │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ + 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 { │ │ │ │ │ - crs = { │ │ │ │ │ - "type": "name", │ │ │ │ │ - "properties": { │ │ │ │ │ - "name": "EPSG:" + code │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return crs; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: extract │ │ │ │ │ - * Object with properties corresponding to the GeoJSON types. │ │ │ │ │ - * Property values are functions that do the actual value extraction. │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - extract: { │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.feature │ │ │ │ │ - * Return a partial GeoJSON object representing a single feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the point. │ │ │ │ │ - */ │ │ │ │ │ - 'feature': function(feature) { │ │ │ │ │ - var geom = this.extract.geometry.apply(this, [feature.geometry]); │ │ │ │ │ - var json = { │ │ │ │ │ - "type": "Feature", │ │ │ │ │ - "properties": feature.attributes, │ │ │ │ │ - "geometry": geom │ │ │ │ │ - }; │ │ │ │ │ - if (feature.fid != null) { │ │ │ │ │ - json.id = feature.fid; │ │ │ │ │ - } │ │ │ │ │ - return json; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.geometry │ │ │ │ │ - * Return a GeoJSON object representing a single geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the geometry. │ │ │ │ │ - */ │ │ │ │ │ - 'geometry': function(geometry) { │ │ │ │ │ - if (geometry == null) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - if (this.internalProjection && this.externalProjection) { │ │ │ │ │ - geometry = geometry.clone(); │ │ │ │ │ - geometry.transform(this.internalProjection, │ │ │ │ │ - this.externalProjection); │ │ │ │ │ - } │ │ │ │ │ - var geometryType = geometry.CLASS_NAME.split('.')[2]; │ │ │ │ │ - var data = this.extract[geometryType.toLowerCase()].apply(this, [geometry]); │ │ │ │ │ - var json; │ │ │ │ │ - if (geometryType == "Collection") { │ │ │ │ │ - json = { │ │ │ │ │ - "type": "GeometryCollection", │ │ │ │ │ - "geometries": data │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - json = { │ │ │ │ │ - "type": geometryType, │ │ │ │ │ - "coordinates": data │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return json; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.point │ │ │ │ │ - * Return an array of coordinates from a point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of coordinates representing the point. │ │ │ │ │ - */ │ │ │ │ │ - 'point': function(point) { │ │ │ │ │ - return [point.x, point.y]; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.multipoint │ │ │ │ │ - * Return an array of point coordinates from a multipoint. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * multipoint - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of point coordinate arrays representing │ │ │ │ │ - * the multipoint. │ │ │ │ │ - */ │ │ │ │ │ - 'multipoint': function(multipoint) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multipoint.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.point.apply(this, [multipoint.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.linestring │ │ │ │ │ - * Return an array of coordinate arrays from a linestring. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * linestring - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of coordinate arrays representing │ │ │ │ │ - * the linestring. │ │ │ │ │ - */ │ │ │ │ │ - 'linestring': function(linestring) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = linestring.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.point.apply(this, [linestring.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.multilinestring │ │ │ │ │ - * Return an array of linestring arrays from a linestring. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * multilinestring - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of linestring arrays representing │ │ │ │ │ - * the multilinestring. │ │ │ │ │ - */ │ │ │ │ │ - 'multilinestring': function(multilinestring) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multilinestring.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.linestring.apply(this, [multilinestring.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.polygon │ │ │ │ │ - * Return an array of linear ring arrays from a polygon. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * polygon - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of linear ring arrays representing the polygon. │ │ │ │ │ - */ │ │ │ │ │ - 'polygon': function(polygon) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = polygon.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.linestring.apply(this, [polygon.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.multipolygon │ │ │ │ │ - * Return an array of polygon arrays from a multipolygon. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * multipolygon - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of polygon arrays representing │ │ │ │ │ - * the multipolygon │ │ │ │ │ - */ │ │ │ │ │ - 'multipolygon': function(multipolygon) { │ │ │ │ │ - var array = []; │ │ │ │ │ - for (var i = 0, len = multipolygon.components.length; i < len; ++i) { │ │ │ │ │ - array.push(this.extract.polygon.apply(this, [multipolygon.components[i]])); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - }, │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: extract.collection │ │ │ │ │ - * Return an array of geometries from a geometry collection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * collection - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of geometry objects representing the geometry │ │ │ │ │ - * collection. │ │ │ │ │ - */ │ │ │ │ │ - 'collection': function(collection) { │ │ │ │ │ - var len = collection.components.length; │ │ │ │ │ - var array = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - array[i] = this.extract.geometry.apply( │ │ │ │ │ - this, [collection.components[i]] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return array; │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * 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.Format.GeoJSON" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/XML.js │ │ │ │ │ + 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/Format.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Icon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.XML │ │ │ │ │ - * Read and write XML. For cross-browser XML generation, use methods on an │ │ │ │ │ - * instance of the XML format class instead of on document. │ │ │ │ │ - * The DOM creation and traversing methods exposed here all mimic the │ │ │ │ │ - * W3C XML DOM methods. Create a new parser with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Marker │ │ │ │ │ + * Instances of OpenLayers.Marker are a combination of a │ │ │ │ │ + * and an . │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Format.XML = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. Properties │ │ │ │ │ - * of this object should not be set individually. Read-only. All │ │ │ │ │ - * XML subclasses should have their own namespaces object. Use │ │ │ │ │ - * to add or set a namespace alias after construction. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaceAlias │ │ │ │ │ - * {Object} Mapping of namespace URI to namespace alias. This object │ │ │ │ │ - * is read-only. Use to add or set a namespace alias. │ │ │ │ │ - */ │ │ │ │ │ - namespaceAlias: null, │ │ │ │ │ +OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - * {String} The default namespace alias for creating element nodes. │ │ │ │ │ + /** │ │ │ │ │ + * Property: icon │ │ │ │ │ + * {} The icon used by this marker. │ │ │ │ │ */ │ │ │ │ │ - defaultPrefix: null, │ │ │ │ │ + icon: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} location of object │ │ │ │ │ */ │ │ │ │ │ - readers: {}, │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} the event handler. │ │ │ │ │ */ │ │ │ │ │ - writers: {}, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: xmldom │ │ │ │ │ - * {XMLDom} If this browser uses ActiveX, this will be set to a XMLDOM │ │ │ │ │ - * object. It is not intended to be a browser sniffing property. │ │ │ │ │ - * Instead, the xmldom property is used instead of document │ │ │ │ │ - * where namespaced node creation methods are not supported. In all │ │ │ │ │ - * other browsers, this remains null. │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} the map this marker is attached to │ │ │ │ │ */ │ │ │ │ │ - xmldom: null, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.XML │ │ │ │ │ - * Construct an XML parser. The parser is used to read and write XML. │ │ │ │ │ - * Reading XML from a string returns a DOM element. Writing XML from │ │ │ │ │ - * a DOM element returns a string. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Marker │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on │ │ │ │ │ - * the object. │ │ │ │ │ + * lonlat - {} the position of this marker │ │ │ │ │ + * icon - {} the icon for this marker │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - if (window.ActiveXObject) { │ │ │ │ │ - this.xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Format.prototype.initialize.apply(this, [options]); │ │ │ │ │ - // clone the namespace object and set all namespace aliases │ │ │ │ │ - this.namespaces = OpenLayers.Util.extend({}, this.namespaces); │ │ │ │ │ - this.namespaceAlias = {}; │ │ │ │ │ - for (var alias in this.namespaces) { │ │ │ │ │ - this.namespaceAlias[this.namespaces[alias]] = alias; │ │ │ │ │ + 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: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + * 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() { │ │ │ │ │ - this.xmldom = null; │ │ │ │ │ - OpenLayers.Format.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + // erase any drawn features │ │ │ │ │ + this.erase(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setNamespace │ │ │ │ │ - * Set a namespace alias and URI for the format. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * alias - {String} The namespace alias (prefix). │ │ │ │ │ - * uri - {String} The namespace URI. │ │ │ │ │ - */ │ │ │ │ │ - setNamespace: function(alias, uri) { │ │ │ │ │ - this.namespaces[alias] = uri; │ │ │ │ │ - this.namespaceAlias[uri] = alias; │ │ │ │ │ + this.map = null; │ │ │ │ │ + │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.destroy(); │ │ │ │ │ + this.icon = null; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Deserialize a XML string and return a DOM node. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Calls draw on the icon, and returns that output. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * text - {String} A XML string │ │ │ │ │ - │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A DOM node │ │ │ │ │ + * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ + * location passed-in │ │ │ │ │ */ │ │ │ │ │ - read: function(text) { │ │ │ │ │ - var index = text.indexOf('<'); │ │ │ │ │ - if (index > 0) { │ │ │ │ │ - text = text.substring(index); │ │ │ │ │ - } │ │ │ │ │ - var node = OpenLayers.Util.Try( │ │ │ │ │ - OpenLayers.Function.bind(( │ │ │ │ │ - function() { │ │ │ │ │ - var xmldom; │ │ │ │ │ - /** │ │ │ │ │ - * Since we want to be able to call this method on the prototype │ │ │ │ │ - * itself, this.xmldom may not exist even if in IE. │ │ │ │ │ - */ │ │ │ │ │ - if (window.ActiveXObject && !this.xmldom) { │ │ │ │ │ - xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ - } else { │ │ │ │ │ - xmldom = this.xmldom; │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - xmldom.loadXML(text); │ │ │ │ │ - return xmldom; │ │ │ │ │ - } │ │ │ │ │ - ), this), │ │ │ │ │ - function() { │ │ │ │ │ - return new DOMParser().parseFromString(text, 'text/xml'); │ │ │ │ │ - }, │ │ │ │ │ - function() { │ │ │ │ │ - var req = new XMLHttpRequest(); │ │ │ │ │ - req.open("GET", "data:" + "text/xml" + │ │ │ │ │ - ";charset=utf-8," + encodeURIComponent(text), false); │ │ │ │ │ - if (req.overrideMimeType) { │ │ │ │ │ - req.overrideMimeType("text/xml"); │ │ │ │ │ - } │ │ │ │ │ - req.send(null); │ │ │ │ │ - return req.responseXML; │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + return this.icon.draw(px); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.keepData) { │ │ │ │ │ - this.data = node; │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erases any drawn elements for this marker. │ │ │ │ │ + */ │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.erase(); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return node; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Serialize a DOM node into a XML string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A DOM node. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Move the marker to the new location. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The XML string representation of the input node. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - write: function(node) { │ │ │ │ │ - var data; │ │ │ │ │ - if (this.xmldom) { │ │ │ │ │ - data = node.xml; │ │ │ │ │ - } else { │ │ │ │ │ - var serializer = new XMLSerializer(); │ │ │ │ │ - if (node.nodeType == 1) { │ │ │ │ │ - // Add nodes to a document before serializing. Everything else │ │ │ │ │ - // is serialized as is. This may need more work. See #1218 . │ │ │ │ │ - var doc = document.implementation.createDocument("", "", null); │ │ │ │ │ - if (doc.importNode) { │ │ │ │ │ - node = doc.importNode(node, true); │ │ │ │ │ - } │ │ │ │ │ - doc.appendChild(node); │ │ │ │ │ - data = serializer.serializeToString(doc); │ │ │ │ │ - } else { │ │ │ │ │ - data = serializer.serializeToString(node); │ │ │ │ │ - } │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.icon != null)) { │ │ │ │ │ + this.icon.moveTo(px); │ │ │ │ │ } │ │ │ │ │ - return data; │ │ │ │ │ + this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createElementNS │ │ │ │ │ - * Create a new element with namespace. This node can be appended to │ │ │ │ │ - * another node with the standard node.appendChild method. For │ │ │ │ │ - * cross-browser support, this method must be used instead of │ │ │ │ │ - * document.createElementNS. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * uri - {String} Namespace URI for the element. │ │ │ │ │ - * name - {String} The qualified name of the element (prefix:localname). │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Element} A DOM element with namespace. │ │ │ │ │ + * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ */ │ │ │ │ │ - createElementNS: function(uri, name) { │ │ │ │ │ - var element; │ │ │ │ │ - if (this.xmldom) { │ │ │ │ │ - if (typeof uri == "string") { │ │ │ │ │ - element = this.xmldom.createNode(1, name, uri); │ │ │ │ │ - } else { │ │ │ │ │ - element = this.xmldom.createNode(1, name, ""); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - element = document.createElementNS(uri, name); │ │ │ │ │ - } │ │ │ │ │ - return element; │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ + return isDrawn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createDocumentFragment │ │ │ │ │ - * Create a document fragment node that can be appended to another node │ │ │ │ │ - * created by createElementNS. This will call │ │ │ │ │ - * document.createDocumentFragment outside of IE. In IE, the ActiveX │ │ │ │ │ - * object's createDocumentFragment method is used. │ │ │ │ │ + * Method: onScreen │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Element} A document fragment. │ │ │ │ │ + * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ */ │ │ │ │ │ - createDocumentFragment: function() { │ │ │ │ │ - var element; │ │ │ │ │ - if (this.xmldom) { │ │ │ │ │ - element = this.xmldom.createDocumentFragment(); │ │ │ │ │ - } else { │ │ │ │ │ - element = document.createDocumentFragment(); │ │ │ │ │ + onScreen: function() { │ │ │ │ │ + │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var screenBounds = this.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ } │ │ │ │ │ - return element; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createTextNode │ │ │ │ │ - * Create a text node. This node can be appended to another node with │ │ │ │ │ - * the standard node.appendChild method. For cross-browser support, │ │ │ │ │ - * this method must be used instead of document.createTextNode. │ │ │ │ │ - * │ │ │ │ │ + * Method: inflate │ │ │ │ │ + * Englarges the markers icon by the specified ratio. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * text - {String} The text of the node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A DOM text node. │ │ │ │ │ + * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ + * will double the size). │ │ │ │ │ */ │ │ │ │ │ - createTextNode: function(text) { │ │ │ │ │ - var node; │ │ │ │ │ - if (typeof text !== "string") { │ │ │ │ │ - text = String(text); │ │ │ │ │ - } │ │ │ │ │ - if (this.xmldom) { │ │ │ │ │ - node = this.xmldom.createTextNode(text); │ │ │ │ │ - } else { │ │ │ │ │ - node = document.createTextNode(text); │ │ │ │ │ + inflate: function(inflate) { │ │ │ │ │ + if (this.icon) { │ │ │ │ │ + this.icon.setSize({ │ │ │ │ │ + w: this.icon.size.w * inflate, │ │ │ │ │ + h: this.icon.size.h * inflate │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getElementsByTagNameNS │ │ │ │ │ - * Get a list of elements on a node given the namespace URI and local name. │ │ │ │ │ - * To return all nodes in a given namespace, use '*' for the name │ │ │ │ │ - * argument. To return all nodes of a given (local) name, regardless │ │ │ │ │ - * of namespace, use '*' for the uri argument. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the opacity of the marker by changin the opacity of │ │ │ │ │ + * its icon │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {Element} Node on which to search for other nodes. │ │ │ │ │ - * uri - {String} Namespace URI. │ │ │ │ │ - * name - {String} Local name of the tag (without the prefix). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {NodeList} A node list or array of elements. │ │ │ │ │ + * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ */ │ │ │ │ │ - getElementsByTagNameNS: function(node, uri, name) { │ │ │ │ │ - var elements = []; │ │ │ │ │ - if (node.getElementsByTagNameNS) { │ │ │ │ │ - elements = node.getElementsByTagNameNS(uri, name); │ │ │ │ │ - } else { │ │ │ │ │ - // brute force method │ │ │ │ │ - var allNodes = node.getElementsByTagName("*"); │ │ │ │ │ - var potentialNode, fullName; │ │ │ │ │ - for (var i = 0, len = allNodes.length; i < len; ++i) { │ │ │ │ │ - potentialNode = allNodes[i]; │ │ │ │ │ - fullName = (potentialNode.prefix) ? │ │ │ │ │ - (potentialNode.prefix + ":" + name) : name; │ │ │ │ │ - if ((name == "*") || (fullName == potentialNode.nodeName)) { │ │ │ │ │ - if ((uri == "*") || (uri == potentialNode.namespaceURI)) { │ │ │ │ │ - elements.push(potentialNode); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return elements; │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + this.icon.setOpacity(opacity); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getAttributeNodeNS │ │ │ │ │ - * Get an attribute node given the namespace URI and local name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {Element} Node on which to search for attribute nodes. │ │ │ │ │ - * uri - {String} Namespace URI. │ │ │ │ │ - * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * Change URL of the Icon Image. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} An attribute node or null if none found. │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - getAttributeNodeNS: function(node, uri, name) { │ │ │ │ │ - var attributeNode = null; │ │ │ │ │ - if (node.getAttributeNodeNS) { │ │ │ │ │ - attributeNode = node.getAttributeNodeNS(uri, name); │ │ │ │ │ - } else { │ │ │ │ │ - var attributes = node.attributes; │ │ │ │ │ - var potentialNode, fullName; │ │ │ │ │ - for (var i = 0, len = attributes.length; i < len; ++i) { │ │ │ │ │ - potentialNode = attributes[i]; │ │ │ │ │ - if (potentialNode.namespaceURI == uri) { │ │ │ │ │ - fullName = (potentialNode.prefix) ? │ │ │ │ │ - (potentialNode.prefix + ":" + name) : name; │ │ │ │ │ - if (fullName == potentialNode.nodeName) { │ │ │ │ │ - attributeNode = potentialNode; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return attributeNode; │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + this.icon.setUrl(url); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getAttributeNS │ │ │ │ │ - * Get an attribute value given the namespace URI and local name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {Element} Node on which to search for an attribute. │ │ │ │ │ - * uri - {String} Namespace URI. │ │ │ │ │ - * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} An attribute value or and empty string if none found. │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - getAttributeNS: function(node, uri, name) { │ │ │ │ │ - var attributeValue = ""; │ │ │ │ │ - if (node.getAttributeNS) { │ │ │ │ │ - attributeValue = node.getAttributeNS(uri, name) || ""; │ │ │ │ │ - } else { │ │ │ │ │ - var attributeNode = this.getAttributeNodeNS(node, uri, name); │ │ │ │ │ - if (attributeNode) { │ │ │ │ │ - attributeValue = attributeNode.nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return attributeValue; │ │ │ │ │ + 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/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/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer │ │ │ │ │ + * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getChildValue │ │ │ │ │ - * Get the textual value of the node if it exists, or return an │ │ │ │ │ - * optional default string. Returns an empty string if no first child │ │ │ │ │ - * exists and no default value is supplied. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The element used to look for a first child value. │ │ │ │ │ - * def - {String} Optional string to return in the event that no │ │ │ │ │ - * first child value exists. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The value of the first child of the given node. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getChildValue: function(node, def) { │ │ │ │ │ - var value = def || ""; │ │ │ │ │ - if (node) { │ │ │ │ │ - for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - switch (child.nodeType) { │ │ │ │ │ - case 3: // text node │ │ │ │ │ - case 4: // cdata section │ │ │ │ │ - value += child.nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return value; │ │ │ │ │ - }, │ │ │ │ │ + zIndex: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: isSimpleContent │ │ │ │ │ - * Test if the given node has only simple content (i.e. no child element │ │ │ │ │ - * nodes). │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {DOMElement} An element node. │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The node has no child element nodes (nodes of type 1). │ │ │ │ │ + * A new symbolizer. │ │ │ │ │ */ │ │ │ │ │ - isSimpleContent: function(node) { │ │ │ │ │ - var simple = true; │ │ │ │ │ - for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - if (child.nodeType === 1) { │ │ │ │ │ - simple = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return simple; │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: contentType │ │ │ │ │ - * Determine the content type for a given node. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a copy of this symbolizer. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} One of OpenLayers.Format.XML.CONTENT_TYPE.{EMPTY,SIMPLE,COMPLEX,MIXED} │ │ │ │ │ - * if the node has no, simple, complex, or mixed content. │ │ │ │ │ + * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ */ │ │ │ │ │ - contentType: function(node) { │ │ │ │ │ - var simple = false, │ │ │ │ │ - complex = false; │ │ │ │ │ + clone: function() { │ │ │ │ │ + var Type = eval(this.CLASS_NAME); │ │ │ │ │ + return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var type = OpenLayers.Format.XML.CONTENT_TYPE.EMPTY; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ │ │ │ │ │ - for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - switch (child.nodeType) { │ │ │ │ │ - case 1: // element │ │ │ │ │ - complex = true; │ │ │ │ │ - break; │ │ │ │ │ - case 8: // comment │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - simple = true; │ │ │ │ │ - } │ │ │ │ │ - if (complex && simple) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - if (complex && simple) { │ │ │ │ │ - type = OpenLayers.Format.XML.CONTENT_TYPE.MIXED; │ │ │ │ │ - } else if (complex) { │ │ │ │ │ - return OpenLayers.Format.XML.CONTENT_TYPE.COMPLEX; │ │ │ │ │ - } else if (simple) { │ │ │ │ │ - return OpenLayers.Format.XML.CONTENT_TYPE.SIMPLE; │ │ │ │ │ - } │ │ │ │ │ - return type; │ │ │ │ │ - }, │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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 │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Point │ │ │ │ │ + * A symbolizer used to render point features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Point = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: hasAttributeNS │ │ │ │ │ - * Determine whether a node has a particular attribute matching the given │ │ │ │ │ - * name and namespace. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {Element} Node on which to search for an attribute. │ │ │ │ │ - * uri - {String} Namespace URI. │ │ │ │ │ - * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ + * APIProperty: strokeColor │ │ │ │ │ + * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ + * for red). │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The node has an attribute matching the name and namespace. │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - hasAttributeNS: function(node, uri, name) { │ │ │ │ │ - var found = false; │ │ │ │ │ - if (node.hasAttributeNS) { │ │ │ │ │ - found = node.hasAttributeNS(uri, name); │ │ │ │ │ - } else { │ │ │ │ │ - found = !!this.getAttributeNodeNS(node, uri, name); │ │ │ │ │ - } │ │ │ │ │ - return found; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setAttributeNS │ │ │ │ │ - * Adds a new attribute or changes the value of an attribute with the given │ │ │ │ │ - * namespace and name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {Element} Element node on which to set the attribute. │ │ │ │ │ - * uri - {String} Namespace URI for the attribute. │ │ │ │ │ - * name - {String} Qualified name (prefix:localname) for the attribute. │ │ │ │ │ - * value - {String} Attribute value. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - setAttributeNS: function(node, uri, name, value) { │ │ │ │ │ - if (node.setAttributeNS) { │ │ │ │ │ - node.setAttributeNS(uri, name, value); │ │ │ │ │ - } else { │ │ │ │ │ - if (this.xmldom) { │ │ │ │ │ - if (uri) { │ │ │ │ │ - var attribute = node.ownerDocument.createNode( │ │ │ │ │ - 2, name, uri │ │ │ │ │ - ); │ │ │ │ │ - attribute.nodeValue = value; │ │ │ │ │ - node.setAttributeNode(attribute); │ │ │ │ │ - } else { │ │ │ │ │ - node.setAttribute(name, value); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - throw "setAttributeNS not implemented"; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createElementNSPlus │ │ │ │ │ - * Shorthand for creating namespaced elements with optional attributes and │ │ │ │ │ - * child text nodes. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The qualified node name. │ │ │ │ │ - * options - {Object} Optional object for node configuration. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * uri - {String} Optional namespace uri for the element - supply a prefix │ │ │ │ │ - * instead if the namespace uri is a property of the format's namespace │ │ │ │ │ - * object. │ │ │ │ │ - * attributes - {Object} Optional attributes to be set using the │ │ │ │ │ - * method. │ │ │ │ │ - * value - {String} Optional text to be appended as a text node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Element} An element node. │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - createElementNSPlus: function(name, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - // order of prefix preference │ │ │ │ │ - // 1. in the uri option │ │ │ │ │ - // 2. in the prefix option │ │ │ │ │ - // 3. in the qualified name │ │ │ │ │ - // 4. from the defaultPrefix │ │ │ │ │ - var uri = options.uri || this.namespaces[options.prefix]; │ │ │ │ │ - if (!uri) { │ │ │ │ │ - var loc = name.indexOf(":"); │ │ │ │ │ - uri = this.namespaces[name.substring(0, loc)]; │ │ │ │ │ - } │ │ │ │ │ - if (!uri) { │ │ │ │ │ - uri = this.namespaces[this.defaultPrefix]; │ │ │ │ │ - } │ │ │ │ │ - var node = this.createElementNS(uri, name); │ │ │ │ │ - if (options.attributes) { │ │ │ │ │ - this.setAttributes(node, options.attributes); │ │ │ │ │ - } │ │ │ │ │ - var value = options.value; │ │ │ │ │ - if (value != null) { │ │ │ │ │ - node.appendChild(this.createTextNode(value)); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setAttributes │ │ │ │ │ - * Set multiple attributes given key value pairs from an object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {Element} An element node. │ │ │ │ │ - * obj - {Object || Array} An object whose properties represent attribute │ │ │ │ │ - * names and values represent attribute values. If an attribute name │ │ │ │ │ - * is a qualified name ("prefix:local"), the prefix will be looked up │ │ │ │ │ - * in the parsers {namespaces} object. If the prefix is found, │ │ │ │ │ - * setAttributeNS will be used instead of setAttribute. │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - setAttributes: function(node, obj) { │ │ │ │ │ - var value, uri; │ │ │ │ │ - for (var name in obj) { │ │ │ │ │ - if (obj[name] != null && obj[name].toString) { │ │ │ │ │ - value = obj[name].toString(); │ │ │ │ │ - // check for qualified attribute name ("prefix:local") │ │ │ │ │ - uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; │ │ │ │ │ - this.setAttributeNS(node, uri, name, value); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: readNode │ │ │ │ │ - * Shorthand for applying one of the named readers given the node │ │ │ │ │ - * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ - * generally extend or modify the second. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node to be read (required). │ │ │ │ │ - * obj - {Object} The object to be modified (optional). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ + * Property: strokeDashstyle │ │ │ │ │ + * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ + * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ + * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ + * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - readNode: function(node, obj) { │ │ │ │ │ - if (!obj) { │ │ │ │ │ - obj = {}; │ │ │ │ │ - } │ │ │ │ │ - var group = this.readers[node.namespaceURI ? this.namespaceAlias[node.namespaceURI] : this.defaultPrefix]; │ │ │ │ │ - if (group) { │ │ │ │ │ - var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ - var reader = group[local] || group["*"]; │ │ │ │ │ - if (reader) { │ │ │ │ │ - reader.apply(this, [node, obj]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: readChildNodes │ │ │ │ │ - * Shorthand for applying the named readers to all children of a node. │ │ │ │ │ - * For each child of type 1 (element), is called. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node to be read (required). │ │ │ │ │ - * obj - {Object} The object to be modified (optional). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} The input object, modified. │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - readChildNodes: function(node, obj) { │ │ │ │ │ - if (!obj) { │ │ │ │ │ - obj = {}; │ │ │ │ │ - } │ │ │ │ │ - var children = node.childNodes; │ │ │ │ │ - var child; │ │ │ │ │ - for (var i = 0, len = children.length; i < len; ++i) { │ │ │ │ │ - child = children[i]; │ │ │ │ │ - if (child.nodeType == 1) { │ │ │ │ │ - this.readNode(child, obj); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeNode │ │ │ │ │ - * Shorthand for applying one of the named writers and appending the │ │ │ │ │ - * results to a node. If a qualified name is not provided for the │ │ │ │ │ - * second argument (and a local name is used instead), the namespace │ │ │ │ │ - * of the parent node will be assumed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The name of a node to generate. If a qualified name │ │ │ │ │ - * (e.g. "pre:Name") is used, the namespace prefix is assumed to be │ │ │ │ │ - * in the group. If a local name is used (e.g. "Name") then │ │ │ │ │ - * the namespace of the parent is assumed. If a local name is used │ │ │ │ │ - * and no parent is supplied, then the default namespace is assumed. │ │ │ │ │ - * obj - {Object} Structure containing data for the writer. │ │ │ │ │ - * parent - {DOMElement} Result will be appended to this node. If no parent │ │ │ │ │ - * is supplied, the node will not be appended to anything. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The child node. │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - writeNode: function(name, obj, parent) { │ │ │ │ │ - var prefix, local; │ │ │ │ │ - var split = name.indexOf(":"); │ │ │ │ │ - if (split > 0) { │ │ │ │ │ - prefix = name.substring(0, split); │ │ │ │ │ - local = name.substring(split + 1); │ │ │ │ │ - } else { │ │ │ │ │ - if (parent) { │ │ │ │ │ - prefix = this.namespaceAlias[parent.namespaceURI]; │ │ │ │ │ - } else { │ │ │ │ │ - prefix = this.defaultPrefix; │ │ │ │ │ - } │ │ │ │ │ - local = name; │ │ │ │ │ - } │ │ │ │ │ - var child = this.writers[prefix][local].apply(this, [obj]); │ │ │ │ │ - if (parent) { │ │ │ │ │ - parent.appendChild(child); │ │ │ │ │ - } │ │ │ │ │ - return child; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getChildEl │ │ │ │ │ - * Get the first child element. Optionally only return the first child │ │ │ │ │ - * if it matches the given name and namespace URI. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The parent node. │ │ │ │ │ - * name - {String} Optional node name (local) to search for. │ │ │ │ │ - * uri - {String} Optional namespace URI to search for. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The first child. Returns null if no element is found, if │ │ │ │ │ - * something significant besides an element is found, or if the element │ │ │ │ │ - * found does not match the optional name and uri. │ │ │ │ │ + * APIProperty: pointRadius │ │ │ │ │ + * {Number} Pixel point radius. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getChildEl: function(node, name, uri) { │ │ │ │ │ - return node && this.getThisOrNextEl(node.firstChild, name, uri); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getNextEl │ │ │ │ │ - * Get the next sibling element. Optionally get the first sibling only │ │ │ │ │ - * if it matches the given local name and namespace URI. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node. │ │ │ │ │ - * name - {String} Optional local name of the sibling to search for. │ │ │ │ │ - * uri - {String} Optional namespace URI of the sibling to search for. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The next sibling element. Returns null if no element is │ │ │ │ │ - * found, something significant besides an element is found, or the │ │ │ │ │ - * found element does not match the optional name and uri. │ │ │ │ │ + * APIProperty: externalGraphic │ │ │ │ │ + * {String} Url to an external graphic that will be used for rendering │ │ │ │ │ + * points. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getNextEl: function(node, name, uri) { │ │ │ │ │ - return node && this.getThisOrNextEl(node.nextSibling, name, uri); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getThisOrNextEl │ │ │ │ │ - * Return this node or the next element node. Optionally get the first │ │ │ │ │ - * sibling with the given local name or namespace URI. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node. │ │ │ │ │ - * name - {String} Optional local name of the sibling to search for. │ │ │ │ │ - * uri - {String} Optional namespace URI of the sibling to search for. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The next sibling element. Returns null if no element is │ │ │ │ │ - * found, something significant besides an element is found, or the │ │ │ │ │ - * found element does not match the query. │ │ │ │ │ + * APIProperty: graphicWidth │ │ │ │ │ + * {Number} Pixel width for sizing an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getThisOrNextEl: function(node, name, uri) { │ │ │ │ │ - outer: for (var sibling = node; sibling; sibling = sibling.nextSibling) { │ │ │ │ │ - switch (sibling.nodeType) { │ │ │ │ │ - case 1: // Element │ │ │ │ │ - if ((!name || name === (sibling.localName || sibling.nodeName.split(":").pop())) && │ │ │ │ │ - (!uri || uri === sibling.namespaceURI)) { │ │ │ │ │ - // matches │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - sibling = null; │ │ │ │ │ - break outer; │ │ │ │ │ - case 3: // Text │ │ │ │ │ - if (/^\s*$/.test(sibling.nodeValue)) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - case 4: // CDATA │ │ │ │ │ - case 6: // ENTITY_NODE │ │ │ │ │ - case 12: // NOTATION_NODE │ │ │ │ │ - case 10: // DOCUMENT_TYPE_NODE │ │ │ │ │ - case 11: // DOCUMENT_FRAGMENT_NODE │ │ │ │ │ - sibling = null; │ │ │ │ │ - break outer; │ │ │ │ │ - } // ignore comments and processing instructions │ │ │ │ │ - } │ │ │ │ │ - return sibling || null; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: lookupNamespaceURI │ │ │ │ │ - * Takes a prefix and returns the namespace URI associated with it on the given │ │ │ │ │ - * node if found (and null if not). Supplying null for the prefix will │ │ │ │ │ - * return the default namespace. │ │ │ │ │ - * │ │ │ │ │ - * For browsers that support it, this calls the native lookupNamesapceURI │ │ │ │ │ - * function. In other browsers, this is an implementation of │ │ │ │ │ - * http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI. │ │ │ │ │ - * │ │ │ │ │ - * For browsers that don't support the attribute.ownerElement property, this │ │ │ │ │ - * method cannot be called on attribute nodes. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node from which to start looking. │ │ │ │ │ - * prefix - {String} The prefix to lookup or null to lookup the default namespace. │ │ │ │ │ + * APIProperty: graphicHeight │ │ │ │ │ + * {Number} Pixel height for sizing an external graphic. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The namespace URI for the given prefix. Returns null if the prefix │ │ │ │ │ - * cannot be found or the node is the wrong type. │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - lookupNamespaceURI: function(node, prefix) { │ │ │ │ │ - var uri = null; │ │ │ │ │ - if (node) { │ │ │ │ │ - if (node.lookupNamespaceURI) { │ │ │ │ │ - uri = node.lookupNamespaceURI(prefix); │ │ │ │ │ - } else { │ │ │ │ │ - outer: switch (node.nodeType) { │ │ │ │ │ - case 1: // ELEMENT_NODE │ │ │ │ │ - if (node.namespaceURI !== null && node.prefix === prefix) { │ │ │ │ │ - uri = node.namespaceURI; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - var len = node.attributes.length; │ │ │ │ │ - if (len) { │ │ │ │ │ - var attr; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - attr = node.attributes[i]; │ │ │ │ │ - if (attr.prefix === "xmlns" && attr.name === "xmlns:" + prefix) { │ │ │ │ │ - uri = attr.value || null; │ │ │ │ │ - break outer; │ │ │ │ │ - } else if (attr.name === "xmlns" && prefix === null) { │ │ │ │ │ - uri = attr.value || null; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - uri = this.lookupNamespaceURI(node.parentNode, prefix); │ │ │ │ │ - break outer; │ │ │ │ │ - case 2: // ATTRIBUTE_NODE │ │ │ │ │ - uri = this.lookupNamespaceURI(node.ownerElement, prefix); │ │ │ │ │ - break outer; │ │ │ │ │ - case 9: // DOCUMENT_NODE │ │ │ │ │ - uri = this.lookupNamespaceURI(node.documentElement, prefix); │ │ │ │ │ - break outer; │ │ │ │ │ - case 6: // ENTITY_NODE │ │ │ │ │ - case 12: // NOTATION_NODE │ │ │ │ │ - case 10: // DOCUMENT_TYPE_NODE │ │ │ │ │ - case 11: // DOCUMENT_FRAGMENT_NODE │ │ │ │ │ - break outer; │ │ │ │ │ - default: │ │ │ │ │ - // TEXT_NODE (3), CDATA_SECTION_NODE (4), ENTITY_REFERENCE_NODE (5), │ │ │ │ │ - // PROCESSING_INSTRUCTION_NODE (7), COMMENT_NODE (8) │ │ │ │ │ - uri = this.lookupNamespaceURI(node.parentNode, prefix); │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return uri; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getXMLDoc │ │ │ │ │ - * Get an XML document for nodes that are not supported in HTML (e.g. │ │ │ │ │ - * createCDATASection). On IE, this will either return an existing or │ │ │ │ │ - * create a new on the instance. On other browsers, this will │ │ │ │ │ - * either return an existing or create a new shared document (see │ │ │ │ │ - * ). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {XMLDocument} │ │ │ │ │ + * APIProperty: graphicOpacity │ │ │ │ │ + * {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getXMLDoc: function() { │ │ │ │ │ - if (!OpenLayers.Format.XML.document && !this.xmldom) { │ │ │ │ │ - if (document.implementation && document.implementation.createDocument) { │ │ │ │ │ - OpenLayers.Format.XML.document = │ │ │ │ │ - document.implementation.createDocument("", "", null); │ │ │ │ │ - } else if (!this.xmldom && window.ActiveXObject) { │ │ │ │ │ - this.xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Format.XML.document || this.xmldom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.XML" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Format.XML.CONTENT_TYPE = { │ │ │ │ │ - EMPTY: 0, │ │ │ │ │ - SIMPLE: 1, │ │ │ │ │ - COMPLEX: 2, │ │ │ │ │ - MIXED: 3 │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: OpenLayers.Format.XML.lookupNamespaceURI │ │ │ │ │ - * Takes a prefix and returns the namespace URI associated with it on the given │ │ │ │ │ - * node if found (and null if not). Supplying null for the prefix will │ │ │ │ │ - * return the default namespace. │ │ │ │ │ - * │ │ │ │ │ - * For browsers that support it, this calls the native lookupNamesapceURI │ │ │ │ │ - * function. In other browsers, this is an implementation of │ │ │ │ │ - * http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI. │ │ │ │ │ - * │ │ │ │ │ - * For browsers that don't support the attribute.ownerElement property, this │ │ │ │ │ - * method cannot be called on attribute nodes. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node from which to start looking. │ │ │ │ │ - * prefix - {String} The prefix to lookup or null to lookup the default namespace. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The namespace URI for the given prefix. Returns null if the prefix │ │ │ │ │ - * cannot be found or the node is the wrong type. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.XML.lookupNamespaceURI = OpenLayers.Function.bind( │ │ │ │ │ - OpenLayers.Format.XML.prototype.lookupNamespaceURI, │ │ │ │ │ - OpenLayers.Format.XML.prototype │ │ │ │ │ -); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Property: OpenLayers.Format.XML.document │ │ │ │ │ - * {XMLDocument} XML document to reuse for creating non-HTML compliant nodes, │ │ │ │ │ - * like document.createCDATASection. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.XML.document = null; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/OGCExceptionReport.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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.OGCExceptionReport │ │ │ │ │ - * Class to read exception reports for various OGC services and versions. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.OGCExceptionReport = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + * APIProperty: graphicXOffset │ │ │ │ │ + * {Number} Pixel offset along the positive x axis for displacing an │ │ │ │ │ + * external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ogc: "http://www.opengis.net/ogc" │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + * APIProperty: graphicYOffset │ │ │ │ │ + * {Number} Pixel offset along the positive y axis for displacing an │ │ │ │ │ + * external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ + * APIProperty: rotation │ │ │ │ │ + * {Number} The rotation of a graphic in the clockwise direction about its │ │ │ │ │ + * center point (or any point off center as specified by │ │ │ │ │ + * and ). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - defaultPrefix: "ogc", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.OGCExceptionReport │ │ │ │ │ - * Create a new parser for OGC exception reports. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * APIProperty: graphicName │ │ │ │ │ + * {String} Named graphic to use when rendering points. Supported values │ │ │ │ │ + * include "circle", "square", "star", "x", "cross", and "triangle". │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read OGC exception report data from a string, and return an object with │ │ │ │ │ - * information about the exceptions. │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Point │ │ │ │ │ + * Create a symbolizer for rendering points. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Information about the exceptions that occurred. │ │ │ │ │ - */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - var result; │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - var root = data.documentElement; │ │ │ │ │ - var exceptionInfo = { │ │ │ │ │ - exceptionReport: null │ │ │ │ │ - }; │ │ │ │ │ - if (root) { │ │ │ │ │ - this.readChildNodes(data, exceptionInfo); │ │ │ │ │ - if (exceptionInfo.exceptionReport === null) { │ │ │ │ │ - // fall-back to OWSCommon since this is a common output format for exceptions │ │ │ │ │ - // we cannot easily use the ows readers directly since they differ for 1.0 and 1.1 │ │ │ │ │ - exceptionInfo = new OpenLayers.Format.OWSCommon().read(data); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return exceptionInfo; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * A new point symbolizer. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "ogc": { │ │ │ │ │ - "ServiceExceptionReport": function(node, obj) { │ │ │ │ │ - obj.exceptionReport = { │ │ │ │ │ - exceptions: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ - }, │ │ │ │ │ - "ServiceException": function(node, exceptionReport) { │ │ │ │ │ - var exception = { │ │ │ │ │ - code: node.getAttribute("code"), │ │ │ │ │ - locator: node.getAttribute("locator"), │ │ │ │ │ - text: this.getChildValue(node) │ │ │ │ │ - }; │ │ │ │ │ - exceptionReport.exceptions.push(exception); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.OGCExceptionReport" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Point" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/XML/VersionedOGC.js │ │ │ │ │ + OpenLayers/Symbolizer/Line.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/OGCExceptionReport.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.XML.VersionedOGC │ │ │ │ │ - * Base class for versioned formats, i.e. a format which supports multiple │ │ │ │ │ - * versions. │ │ │ │ │ - * │ │ │ │ │ - * To enable checking if parsing succeeded, you will need to define a property │ │ │ │ │ - * called errorProperty on the parser you want to check. The parser will then │ │ │ │ │ - * check the returned object to see if that property is present. If it is, it │ │ │ │ │ - * assumes the parsing was successful. If it is not present (or is null), it will │ │ │ │ │ - * pass the document through an OGCExceptionReport parser. │ │ │ │ │ - * │ │ │ │ │ - * If errorProperty is undefined for the parser, this error checking mechanism │ │ │ │ │ - * will be disabled. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Line │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: defaultVersion │ │ │ │ │ - * {String} Version number to assume if none found. │ │ │ │ │ - */ │ │ │ │ │ - defaultVersion: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: version │ │ │ │ │ - * {String} Specify a version string if one is known. │ │ │ │ │ - */ │ │ │ │ │ - version: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: profile │ │ │ │ │ - * {String} If provided, use a custom profile. │ │ │ │ │ - */ │ │ │ │ │ - profile: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: allowFallback │ │ │ │ │ - * {Boolean} If a profiled parser cannot be found for the returned version, │ │ │ │ │ - * use a non-profiled parser as the fallback. Application code using this │ │ │ │ │ - * should take into account that the return object structure might be │ │ │ │ │ - * missing the specifics of the profile. Defaults to false. │ │ │ │ │ - */ │ │ │ │ │ - allowFallback: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: name │ │ │ │ │ - * {String} The name of this parser, this is the part of the CLASS_NAME │ │ │ │ │ - * except for "OpenLayers.Format." │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ +OpenLayers.Symbolizer.Line = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stringifyOutput │ │ │ │ │ - * {Boolean} If true, write will return a string otherwise a DOMElement. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: strokeColor │ │ │ │ │ + * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ + * for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - stringifyOutput: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: parser │ │ │ │ │ - * {Object} Instance of the versioned parser. Cached for multiple read and │ │ │ │ │ - * write calls of the same version. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - parser: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.XML.VersionedOGC. │ │ │ │ │ - * Constructor. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on │ │ │ │ │ - * the object. │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ - var className = this.CLASS_NAME; │ │ │ │ │ - this.name = className.substring(className.lastIndexOf(".") + 1); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getVersion │ │ │ │ │ - * Returns the version to use. Subclasses can override this function │ │ │ │ │ - * if a different version detection is needed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * root - {DOMElement} │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The version to use. │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getVersion: function(root, options) { │ │ │ │ │ - var version; │ │ │ │ │ - // read │ │ │ │ │ - if (root) { │ │ │ │ │ - version = this.version; │ │ │ │ │ - if (!version) { │ │ │ │ │ - version = root.getAttribute("version"); │ │ │ │ │ - if (!version) { │ │ │ │ │ - version = this.defaultVersion; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { // write │ │ │ │ │ - version = (options && options.version) || │ │ │ │ │ - this.version || this.defaultVersion; │ │ │ │ │ - } │ │ │ │ │ - return version; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getParser │ │ │ │ │ - * Get an instance of the cached parser if available, otherwise create one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * version - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: strokeDashstyle │ │ │ │ │ + * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ + * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ + * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ + * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getParser: function(version) { │ │ │ │ │ - version = version || this.defaultVersion; │ │ │ │ │ - var profile = this.profile ? "_" + this.profile : ""; │ │ │ │ │ - if (!this.parser || this.parser.VERSION != version) { │ │ │ │ │ - var format = OpenLayers.Format[this.name][ │ │ │ │ │ - "v" + version.replace(/\./g, "_") + profile │ │ │ │ │ - ]; │ │ │ │ │ - if (!format) { │ │ │ │ │ - if (profile !== "" && this.allowFallback) { │ │ │ │ │ - // fallback to the non-profiled version of the parser │ │ │ │ │ - profile = ""; │ │ │ │ │ - format = OpenLayers.Format[this.name][ │ │ │ │ │ - "v" + version.replace(/\./g, "_") │ │ │ │ │ - ]; │ │ │ │ │ - } │ │ │ │ │ - if (!format) { │ │ │ │ │ - throw "Can't find a " + this.name + " parser for version " + │ │ │ │ │ - version + profile; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.parser = new format(this.options); │ │ │ │ │ - } │ │ │ │ │ - return this.parser; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Write a document. │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Line │ │ │ │ │ + * Create a symbolizer for rendering lines. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} An object representing the document. │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The document as a string │ │ │ │ │ + * A new line symbolizer. │ │ │ │ │ */ │ │ │ │ │ - write: function(obj, options) { │ │ │ │ │ - var version = this.getVersion(null, options); │ │ │ │ │ - this.parser = this.getParser(version); │ │ │ │ │ - var root = this.parser.write(obj, options); │ │ │ │ │ - if (this.stringifyOutput === false) { │ │ │ │ │ - return root; │ │ │ │ │ - } else { │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read a doc and return an object representing the document. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String | DOMElement} Data to read. │ │ │ │ │ - * options - {Object} Options for the reader. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the document. │ │ │ │ │ - */ │ │ │ │ │ - read: function(data, options) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - var root = data.documentElement; │ │ │ │ │ - var version = this.getVersion(root); │ │ │ │ │ - this.parser = this.getParser(version); // Select the parser │ │ │ │ │ - var obj = this.parser.read(data, options); // Parse the data │ │ │ │ │ - │ │ │ │ │ - var errorProperty = this.parser.errorProperty || null; │ │ │ │ │ - if (errorProperty !== null && obj[errorProperty] === undefined) { │ │ │ │ │ - // an error must have happened, so parse it and report back │ │ │ │ │ - var format = new OpenLayers.Format.OGCExceptionReport(); │ │ │ │ │ - obj.error = format.read(data); │ │ │ │ │ - } │ │ │ │ │ - obj.version = version; │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Line" │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.XML.VersionedOGC" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/OWSCommon.js │ │ │ │ │ + OpenLayers/Symbolizer/Polygon.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/VersionedOGC.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.OWSCommon │ │ │ │ │ - * Read OWSCommon. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ +OpenLayers.Symbolizer.Polygon = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: defaultVersion │ │ │ │ │ - * {String} Version number to assume if none found. Default is "1.0.0". │ │ │ │ │ + * APIProperty: strokeColor │ │ │ │ │ + * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ + * for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - defaultVersion: "1.0.0", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.OWSCommon │ │ │ │ │ - * Create a new parser for OWSCommon. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getVersion │ │ │ │ │ - * Returns the version to use. Subclasses can override this function │ │ │ │ │ - * if a different version detection is needed. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * root - {DOMElement} │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The version to use. │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - getVersion: function(root, options) { │ │ │ │ │ - var version = this.version; │ │ │ │ │ - if (!version) { │ │ │ │ │ - // remember version does not correspond to the OWS version │ │ │ │ │ - // it corresponds to the WMS/WFS/WCS etc. request version │ │ │ │ │ - var uri = root.getAttribute("xmlns:ows"); │ │ │ │ │ - // the above will fail if the namespace prefix is different than │ │ │ │ │ - // ows and if the namespace is declared on a different element │ │ │ │ │ - if (uri && uri.substring(uri.lastIndexOf("/") + 1) === "1.1") { │ │ │ │ │ - version = "1.1.0"; │ │ │ │ │ - } │ │ │ │ │ - if (!version) { │ │ │ │ │ - version = this.defaultVersion; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return version; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read an OWSCommon document and return an object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String | DOMElement} Data to read. │ │ │ │ │ - * options - {Object} Options for the reader. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the structure of the document. │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.OWSCommon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/OWSCommon/v1.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/OWSCommon.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.OWSCommon.v1 │ │ │ │ │ - * Common readers and writers for OWSCommon v1.X formats │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + * Property: strokeDashstyle │ │ │ │ │ + * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ + * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ + * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ + * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {DOMElement} An OWSCommon document element. │ │ │ │ │ - * options - {Object} Options for the reader. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the OWSCommon document. │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - read: function(data, options) { │ │ │ │ │ - options = OpenLayers.Util.applyDefaults(options, this.options); │ │ │ │ │ - var ows = {}; │ │ │ │ │ - this.readChildNodes(data, ows); │ │ │ │ │ - return ows; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "ows": { │ │ │ │ │ - "Exception": function(node, exceptionReport) { │ │ │ │ │ - var exception = { │ │ │ │ │ - code: node.getAttribute('exceptionCode'), │ │ │ │ │ - locator: node.getAttribute('locator'), │ │ │ │ │ - texts: [] │ │ │ │ │ - }; │ │ │ │ │ - exceptionReport.exceptions.push(exception); │ │ │ │ │ - this.readChildNodes(node, exception); │ │ │ │ │ - }, │ │ │ │ │ - "ExceptionText": function(node, exception) { │ │ │ │ │ - var text = this.getChildValue(node); │ │ │ │ │ - exception.texts.push(text); │ │ │ │ │ - }, │ │ │ │ │ - "ServiceIdentification": function(node, obj) { │ │ │ │ │ - obj.serviceIdentification = {}; │ │ │ │ │ - this.readChildNodes(node, obj.serviceIdentification); │ │ │ │ │ - }, │ │ │ │ │ - "Title": function(node, obj) { │ │ │ │ │ - obj.title = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Abstract": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification["abstract"] = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Keywords": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification.keywords = {}; │ │ │ │ │ - this.readChildNodes(node, serviceIdentification.keywords); │ │ │ │ │ - }, │ │ │ │ │ - "Keyword": function(node, keywords) { │ │ │ │ │ - keywords[this.getChildValue(node)] = true; │ │ │ │ │ - }, │ │ │ │ │ - "ServiceType": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification.serviceType = { │ │ │ │ │ - codeSpace: node.getAttribute('codeSpace'), │ │ │ │ │ - value: this.getChildValue(node) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - "ServiceTypeVersion": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification.serviceTypeVersion = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Fees": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification.fees = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "AccessConstraints": function(node, serviceIdentification) { │ │ │ │ │ - serviceIdentification.accessConstraints = │ │ │ │ │ - this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "ServiceProvider": function(node, obj) { │ │ │ │ │ - obj.serviceProvider = {}; │ │ │ │ │ - this.readChildNodes(node, obj.serviceProvider); │ │ │ │ │ - }, │ │ │ │ │ - "ProviderName": function(node, serviceProvider) { │ │ │ │ │ - serviceProvider.providerName = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "ProviderSite": function(node, serviceProvider) { │ │ │ │ │ - serviceProvider.providerSite = this.getAttributeNS(node, │ │ │ │ │ - this.namespaces.xlink, "href"); │ │ │ │ │ - }, │ │ │ │ │ - "ServiceContact": function(node, serviceProvider) { │ │ │ │ │ - serviceProvider.serviceContact = {}; │ │ │ │ │ - this.readChildNodes(node, serviceProvider.serviceContact); │ │ │ │ │ - }, │ │ │ │ │ - "IndividualName": function(node, serviceContact) { │ │ │ │ │ - serviceContact.individualName = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "PositionName": function(node, serviceContact) { │ │ │ │ │ - serviceContact.positionName = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "ContactInfo": function(node, serviceContact) { │ │ │ │ │ - serviceContact.contactInfo = {}; │ │ │ │ │ - this.readChildNodes(node, serviceContact.contactInfo); │ │ │ │ │ - }, │ │ │ │ │ - "Phone": function(node, contactInfo) { │ │ │ │ │ - contactInfo.phone = {}; │ │ │ │ │ - this.readChildNodes(node, contactInfo.phone); │ │ │ │ │ - }, │ │ │ │ │ - "Voice": function(node, phone) { │ │ │ │ │ - phone.voice = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Address": function(node, contactInfo) { │ │ │ │ │ - contactInfo.address = {}; │ │ │ │ │ - this.readChildNodes(node, contactInfo.address); │ │ │ │ │ - }, │ │ │ │ │ - "DeliveryPoint": function(node, address) { │ │ │ │ │ - address.deliveryPoint = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "City": function(node, address) { │ │ │ │ │ - address.city = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "AdministrativeArea": function(node, address) { │ │ │ │ │ - address.administrativeArea = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "PostalCode": function(node, address) { │ │ │ │ │ - address.postalCode = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Country": function(node, address) { │ │ │ │ │ - address.country = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "ElectronicMailAddress": function(node, address) { │ │ │ │ │ - address.electronicMailAddress = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Role": function(node, serviceContact) { │ │ │ │ │ - serviceContact.role = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "OperationsMetadata": function(node, obj) { │ │ │ │ │ - obj.operationsMetadata = {}; │ │ │ │ │ - this.readChildNodes(node, obj.operationsMetadata); │ │ │ │ │ - }, │ │ │ │ │ - "Operation": function(node, operationsMetadata) { │ │ │ │ │ - var name = node.getAttribute("name"); │ │ │ │ │ - operationsMetadata[name] = {}; │ │ │ │ │ - this.readChildNodes(node, operationsMetadata[name]); │ │ │ │ │ - }, │ │ │ │ │ - "DCP": function(node, operation) { │ │ │ │ │ - operation.dcp = {}; │ │ │ │ │ - this.readChildNodes(node, operation.dcp); │ │ │ │ │ - }, │ │ │ │ │ - "HTTP": function(node, dcp) { │ │ │ │ │ - dcp.http = {}; │ │ │ │ │ - this.readChildNodes(node, dcp.http); │ │ │ │ │ - }, │ │ │ │ │ - "Get": function(node, http) { │ │ │ │ │ - if (!http.get) { │ │ │ │ │ - http.get = []; │ │ │ │ │ - } │ │ │ │ │ - var obj = { │ │ │ │ │ - url: this.getAttributeNS(node, this.namespaces.xlink, "href") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - http.get.push(obj); │ │ │ │ │ - }, │ │ │ │ │ - "Post": function(node, http) { │ │ │ │ │ - if (!http.post) { │ │ │ │ │ - http.post = []; │ │ │ │ │ - } │ │ │ │ │ - var obj = { │ │ │ │ │ - url: this.getAttributeNS(node, this.namespaces.xlink, "href") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - http.post.push(obj); │ │ │ │ │ - }, │ │ │ │ │ - "Parameter": function(node, operation) { │ │ │ │ │ - if (!operation.parameters) { │ │ │ │ │ - operation.parameters = {}; │ │ │ │ │ - } │ │ │ │ │ - var name = node.getAttribute("name"); │ │ │ │ │ - operation.parameters[name] = {}; │ │ │ │ │ - this.readChildNodes(node, operation.parameters[name]); │ │ │ │ │ - }, │ │ │ │ │ - "Constraint": function(node, obj) { │ │ │ │ │ - if (!obj.constraints) { │ │ │ │ │ - obj.constraints = {}; │ │ │ │ │ - } │ │ │ │ │ - var name = node.getAttribute("name"); │ │ │ │ │ - obj.constraints[name] = {}; │ │ │ │ │ - this.readChildNodes(node, obj.constraints[name]); │ │ │ │ │ - }, │ │ │ │ │ - "Value": function(node, allowedValues) { │ │ │ │ │ - allowedValues[this.getChildValue(node)] = true; │ │ │ │ │ - }, │ │ │ │ │ - "OutputFormat": function(node, obj) { │ │ │ │ │ - obj.formats.push({ │ │ │ │ │ - value: this.getChildValue(node) │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "WGS84BoundingBox": function(node, obj) { │ │ │ │ │ - var boundingBox = {}; │ │ │ │ │ - boundingBox.crs = node.getAttribute("crs"); │ │ │ │ │ - if (obj.BoundingBox) { │ │ │ │ │ - obj.BoundingBox.push(boundingBox); │ │ │ │ │ - } else { │ │ │ │ │ - obj.projection = boundingBox.crs; │ │ │ │ │ - boundingBox = obj; │ │ │ │ │ - } │ │ │ │ │ - this.readChildNodes(node, boundingBox); │ │ │ │ │ - }, │ │ │ │ │ - "BoundingBox": function(node, obj) { │ │ │ │ │ - // FIXME: We consider that BoundingBox is the same as WGS84BoundingBox │ │ │ │ │ - // LowerCorner = "min_x min_y" │ │ │ │ │ - // UpperCorner = "max_x max_y" │ │ │ │ │ - // It should normally depend on the projection │ │ │ │ │ - this.readers['ows']['WGS84BoundingBox'].apply(this, [node, obj]); │ │ │ │ │ - }, │ │ │ │ │ - "LowerCorner": function(node, obj) { │ │ │ │ │ - var str = this.getChildValue(node).replace( │ │ │ │ │ - this.regExes.trimSpace, ""); │ │ │ │ │ - str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ - var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ - obj.left = pointList[0]; │ │ │ │ │ - obj.bottom = pointList[1]; │ │ │ │ │ - }, │ │ │ │ │ - "UpperCorner": function(node, obj) { │ │ │ │ │ - var str = this.getChildValue(node).replace( │ │ │ │ │ - this.regExes.trimSpace, ""); │ │ │ │ │ - str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ - var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ - obj.right = pointList[0]; │ │ │ │ │ - obj.top = pointList[1]; │ │ │ │ │ - obj.bounds = new OpenLayers.Bounds(obj.left, obj.bottom, │ │ │ │ │ - obj.right, obj.top); │ │ │ │ │ - delete obj.left; │ │ │ │ │ - delete obj.bottom; │ │ │ │ │ - delete obj.right; │ │ │ │ │ - delete obj.top; │ │ │ │ │ - }, │ │ │ │ │ - "Language": function(node, obj) { │ │ │ │ │ - obj.language = this.getChildValue(node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * Create a symbolizer for rendering polygons. │ │ │ │ │ + * │ │ │ │ │ + * 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 polygon symbolizer. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ows": { │ │ │ │ │ - "BoundingBox": function(options, nodeName) { │ │ │ │ │ - var node = this.createElementNSPlus(nodeName || "ows:BoundingBox", { │ │ │ │ │ - attributes: { │ │ │ │ │ - crs: options.projection │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:LowerCorner", options, node); │ │ │ │ │ - this.writeNode("ows:UpperCorner", options, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LowerCorner": function(options) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:LowerCorner", { │ │ │ │ │ - value: options.bounds.left + " " + options.bounds.bottom │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "UpperCorner": function(options) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:UpperCorner", { │ │ │ │ │ - value: options.bounds.right + " " + options.bounds.top │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Identifier": function(identifier) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:Identifier", { │ │ │ │ │ - value: identifier │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Title": function(title) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:Title", { │ │ │ │ │ - value: title │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Abstract": function(abstractValue) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:Abstract", { │ │ │ │ │ - value: abstractValue │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "OutputFormat": function(format) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:OutputFormat", { │ │ │ │ │ - value: format │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.OWSCommon.v1" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Polygon" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/OWSCommon/v1_1_0.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/OWSCommon/v1.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.OWSCommon.v1_1_0 │ │ │ │ │ - * Parser for OWS Common version 1.1.0. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink" │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: { │ │ │ │ │ - "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "ExceptionReport": function(node, obj) { │ │ │ │ │ - obj.exceptionReport = { │ │ │ │ │ - version: node.getAttribute('version'), │ │ │ │ │ - language: node.getAttribute('xml:lang'), │ │ │ │ │ - exceptions: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ - }, │ │ │ │ │ - "AllowedValues": function(node, parameter) { │ │ │ │ │ - parameter.allowedValues = {}; │ │ │ │ │ - this.readChildNodes(node, parameter.allowedValues); │ │ │ │ │ - }, │ │ │ │ │ - "AnyValue": function(node, parameter) { │ │ │ │ │ - parameter.anyValue = true; │ │ │ │ │ - }, │ │ │ │ │ - "DataType": function(node, parameter) { │ │ │ │ │ - parameter.dataType = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Range": function(node, allowedValues) { │ │ │ │ │ - allowedValues.range = {}; │ │ │ │ │ - this.readChildNodes(node, allowedValues.range); │ │ │ │ │ - }, │ │ │ │ │ - "MinimumValue": function(node, range) { │ │ │ │ │ - range.minValue = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "MaximumValue": function(node, range) { │ │ │ │ │ - range.maxValue = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Identifier": function(node, obj) { │ │ │ │ │ - obj.identifier = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "SupportedCRS": function(node, obj) { │ │ │ │ │ - obj.supportedCRS = this.getChildValue(node); │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.OWSCommon.v1.prototype.readers["ows"]) │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "Range": function(range) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:Range", { │ │ │ │ │ - attributes: { │ │ │ │ │ - 'ows:rangeClosure': range.closure │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:MinimumValue", range.minValue, node); │ │ │ │ │ - this.writeNode("ows:MaximumValue", range.maxValue, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MinimumValue": function(minValue) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:MinimumValue", { │ │ │ │ │ - value: minValue │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MaximumValue": function(maxValue) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:MaximumValue", { │ │ │ │ │ - value: maxValue │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Value": function(value) { │ │ │ │ │ - var node = this.createElementNSPlus("ows:Value", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.OWSCommon.v1.prototype.writers["ows"]) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_1_0" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WCSGetCoverage.js │ │ │ │ │ + OpenLayers/Symbolizer/Text.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 │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WCSGetCoverage version 1.1.0 │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Text │ │ │ │ │ + * A symbolizer used to render text labels for features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.WCSGetCoverage = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ +OpenLayers.Symbolizer.Text = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: label │ │ │ │ │ + * {String} The text for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ - wcs: "http://www.opengis.net/wcs/1.1", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontFamily │ │ │ │ │ + * {String} The font family for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.1.2 │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontSize │ │ │ │ │ + * {String} The font size for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - VERSION: "1.1.2", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontWeight │ │ │ │ │ + * {String} The font weight for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/wcs/1.1 http://schemas.opengis.net/wcs/1.1/wcsGetCoverage.xsd", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WCSGetCoverage │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * Property: fontStyle │ │ │ │ │ + * {String} The font style for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Text │ │ │ │ │ + * Create a symbolizer for rendering text labels. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object. │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A WCS GetCoverage request XML string. │ │ │ │ │ - */ │ │ │ │ │ - write: function(options) { │ │ │ │ │ - var node = this.writeNode("wcs:GetCoverage", options); │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - node, this.namespaces.xsi, │ │ │ │ │ - "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ - ); │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * A new text symbolizer. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "wcs": { │ │ │ │ │ - "GetCoverage": function(options) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:GetCoverage", { │ │ │ │ │ - attributes: { │ │ │ │ │ - version: options.version || this.VERSION, │ │ │ │ │ - service: 'WCS' │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:Identifier", options.identifier, node); │ │ │ │ │ - this.writeNode("wcs:DomainSubset", options.domainSubset, node); │ │ │ │ │ - this.writeNode("wcs:Output", options.output, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "DomainSubset": function(domainSubset) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:DomainSubset", {}); │ │ │ │ │ - this.writeNode("ows:BoundingBox", domainSubset.boundingBox, node); │ │ │ │ │ - if (domainSubset.temporalSubset) { │ │ │ │ │ - this.writeNode("wcs:TemporalSubset", domainSubset.temporalSubset, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "TemporalSubset": function(temporalSubset) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:TemporalSubset", {}); │ │ │ │ │ - for (var i = 0, len = temporalSubset.timePeriods.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("wcs:TimePeriod", temporalSubset.timePeriods[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "TimePeriod": function(timePeriod) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:TimePeriod", {}); │ │ │ │ │ - this.writeNode("wcs:BeginPosition", timePeriod.begin, node); │ │ │ │ │ - this.writeNode("wcs:EndPosition", timePeriod.end, node); │ │ │ │ │ - if (timePeriod.resolution) { │ │ │ │ │ - this.writeNode("wcs:TimeResolution", timePeriod.resolution, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "BeginPosition": function(begin) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:BeginPosition", { │ │ │ │ │ - value: begin │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "EndPosition": function(end) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:EndPosition", { │ │ │ │ │ - value: end │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "TimeResolution": function(resolution) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:TimeResolution", { │ │ │ │ │ - value: resolution │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Output": function(output) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:Output", { │ │ │ │ │ - attributes: { │ │ │ │ │ - format: output.format, │ │ │ │ │ - store: output.store │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (output.gridCRS) { │ │ │ │ │ - this.writeNode("wcs:GridCRS", output.gridCRS, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "GridCRS": function(gridCRS) { │ │ │ │ │ - var node = this.createElementNSPlus("wcs:GridCRS", {}); │ │ │ │ │ - this.writeNode("wcs:GridBaseCRS", gridCRS.baseCRS, node); │ │ │ │ │ - if (gridCRS.type) { │ │ │ │ │ - this.writeNode("wcs:GridType", gridCRS.type, node); │ │ │ │ │ - } │ │ │ │ │ - if (gridCRS.origin) { │ │ │ │ │ - this.writeNode("wcs:GridOrigin", gridCRS.origin, node); │ │ │ │ │ - } │ │ │ │ │ - this.writeNode("wcs:GridOffsets", gridCRS.offsets, node); │ │ │ │ │ - if (gridCRS.CS) { │ │ │ │ │ - this.writeNode("wcs:GridCS", gridCRS.CS, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "GridBaseCRS": function(baseCRS) { │ │ │ │ │ - return this.createElementNSPlus("wcs:GridBaseCRS", { │ │ │ │ │ - value: baseCRS │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "GridOrigin": function(origin) { │ │ │ │ │ - return this.createElementNSPlus("wcs:GridOrigin", { │ │ │ │ │ - value: origin │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "GridType": function(type) { │ │ │ │ │ - return this.createElementNSPlus("wcs:GridType", { │ │ │ │ │ - value: type │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "GridOffsets": function(offsets) { │ │ │ │ │ - return this.createElementNSPlus("wcs:GridOffsets", { │ │ │ │ │ - value: offsets │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "GridCS": function(CS) { │ │ │ │ │ - return this.createElementNSPlus("wcs:GridCS", { │ │ │ │ │ - value: CS │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WCSGetCoverage" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Text" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WFST.js │ │ │ │ │ + OpenLayers/Symbolizer/Raster.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.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: OpenLayers.Format.WFST │ │ │ │ │ - * Used to create a versioned WFS protocol. Default version is 1.0.0. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A WFST format of the given version. │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Raster │ │ │ │ │ + * A symbolizer used to render raster images. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.WFST = function(options) { │ │ │ │ │ - options = OpenLayers.Util.applyDefaults( │ │ │ │ │ - options, OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ - ); │ │ │ │ │ - var cls = OpenLayers.Format.WFST["v" + options.version.replace(/\./g, "_")]; │ │ │ │ │ - if (!cls) { │ │ │ │ │ - throw "Unsupported WFST version: " + options.version; │ │ │ │ │ - } │ │ │ │ │ - return new cls(options); │ │ │ │ │ -}; │ │ │ │ │ +OpenLayers.Symbolizer.Raster = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ - * {Object} Default properties for the WFST format. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.WFST.DEFAULTS = { │ │ │ │ │ - "version": "1.0.0" │ │ │ │ │ -}; │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Raster │ │ │ │ │ + * Create a symbolizer for rendering rasters. │ │ │ │ │ + * │ │ │ │ │ + * 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 raster symbolizer. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Raster" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Filter/Spatial.js │ │ │ │ │ + OpenLayers/Style2.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/Filter.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Point.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Line.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Text.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Raster.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Filter.Spatial │ │ │ │ │ - * This class represents a spatial filter. │ │ │ │ │ - * Currently implemented: BBOX, DWithin and Intersects │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Style2 │ │ │ │ │ + * This class represents a collection of rules for rendering features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Filter.Spatial = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ +OpenLayers.Style2 = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {String} Type of spatial filter. │ │ │ │ │ - * │ │ │ │ │ - * The type should be one of: │ │ │ │ │ - * - OpenLayers.Filter.Spatial.BBOX │ │ │ │ │ - * - OpenLayers.Filter.Spatial.INTERSECTS │ │ │ │ │ - * - OpenLayers.Filter.Spatial.DWITHIN │ │ │ │ │ - * - OpenLayers.Filter.Spatial.WITHIN │ │ │ │ │ - * - OpenLayers.Filter.Spatial.CONTAINS │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - type: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: property │ │ │ │ │ - * {String} Name of the context property to compare. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} Style identifier. │ │ │ │ │ */ │ │ │ │ │ - property: null, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: value │ │ │ │ │ - * { || } The bounds or geometry │ │ │ │ │ - * to be used by the filter. Use bounds for BBOX filters and geometry │ │ │ │ │ - * for INTERSECTS or DWITHIN filters. │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {String} Title of this style. │ │ │ │ │ */ │ │ │ │ │ - value: null, │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: distance │ │ │ │ │ - * {Number} The distance to use in a DWithin spatial filter. │ │ │ │ │ + * APIProperty: description │ │ │ │ │ + * {String} Description of this style. │ │ │ │ │ */ │ │ │ │ │ - distance: null, │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: distanceUnits │ │ │ │ │ - * {String} The units to use for the distance, e.g. 'm'. │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {} Name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ */ │ │ │ │ │ - distanceUnits: null, │ │ │ │ │ + layerName: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isDefault │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isDefault: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Filter.Spatial │ │ │ │ │ - * Creates a spatial filter. │ │ │ │ │ + * APIProperty: rules │ │ │ │ │ + * {Array()} Collection of rendering rules. │ │ │ │ │ + */ │ │ │ │ │ + rules: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Style2 │ │ │ │ │ + * Creates a style representing a collection of rendering rules. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * filter. │ │ │ │ │ - * │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * style. Any documented properties may be set at construction. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} A new style object. │ │ │ │ │ */ │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: evaluate │ │ │ │ │ - * Evaluates this filter for a specific feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} feature to apply the filter to. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The feature meets filter criteria. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - evaluate: function(feature) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - switch (this.type) { │ │ │ │ │ - case OpenLayers.Filter.Spatial.BBOX: │ │ │ │ │ - case OpenLayers.Filter.Spatial.INTERSECTS: │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - var geom = this.value; │ │ │ │ │ - if (this.value.CLASS_NAME == "OpenLayers.Bounds") { │ │ │ │ │ - geom = this.value.toGeometry(); │ │ │ │ │ - } │ │ │ │ │ - if (feature.geometry.intersects(geom)) { │ │ │ │ │ - intersect = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - throw new Error('evaluate is not implemented for this filter type.'); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ + this.rules[i].destroy(); │ │ │ │ │ } │ │ │ │ │ - return intersect; │ │ │ │ │ + delete this.rules; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: clone │ │ │ │ │ - * Clones this filter. │ │ │ │ │ + * Clones this style. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ + * {} Clone of this style. │ │ │ │ │ */ │ │ │ │ │ clone: function() { │ │ │ │ │ - var options = OpenLayers.Util.applyDefaults({ │ │ │ │ │ - value: this.value && this.value.clone && this.value.clone() │ │ │ │ │ - }, this); │ │ │ │ │ - return new OpenLayers.Filter.Spatial(options); │ │ │ │ │ + var config = OpenLayers.Util.extend({}, this); │ │ │ │ │ + // clone rules │ │ │ │ │ + if (this.rules) { │ │ │ │ │ + config.rules = []; │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ + config.rules.push(this.rules[i].clone()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Style2(config); │ │ │ │ │ }, │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter.Spatial" │ │ │ │ │ -}); │ │ │ │ │ │ │ │ │ │ -OpenLayers.Filter.Spatial.BBOX = "BBOX"; │ │ │ │ │ -OpenLayers.Filter.Spatial.INTERSECTS = "INTERSECTS"; │ │ │ │ │ -OpenLayers.Filter.Spatial.DWITHIN = "DWITHIN"; │ │ │ │ │ -OpenLayers.Filter.Spatial.WITHIN = "WITHIN"; │ │ │ │ │ -OpenLayers.Filter.Spatial.CONTAINS = "CONTAINS"; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Filter/FeatureId.js │ │ │ │ │ + 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/Filter.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Filter.FeatureId │ │ │ │ │ - * This class represents a ogc:FeatureId Filter, as being used for rule-based SLD │ │ │ │ │ - * styling │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Filter │ │ │ │ │ + * This class represents an OGC Filter. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Filter.FeatureId = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fids │ │ │ │ │ - * {Array(String)} Feature Ids to evaluate this rule against. │ │ │ │ │ - * To be passed inside the params object. │ │ │ │ │ - */ │ │ │ │ │ - fids: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {String} Type to identify this filter. │ │ │ │ │ - */ │ │ │ │ │ - type: "FID", │ │ │ │ │ +OpenLayers.Filter = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Filter.FeatureId │ │ │ │ │ - * Creates an ogc:FeatureId rule. │ │ │ │ │ + * Constructor: OpenLayers.Filter │ │ │ │ │ + * This class represents a generic filter. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - this.fids = []; │ │ │ │ │ - OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Remove reference to anything added. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ * APIMethod: evaluate │ │ │ │ │ - * evaluates this rule for a specific feature │ │ │ │ │ + * Evaluates this filter in a specific context. Instances or subclasses │ │ │ │ │ + * are supposed to override this method. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} feature to apply the rule to. │ │ │ │ │ - * For vector features, the check is run against the fid, │ │ │ │ │ - * for plain features against the id. │ │ │ │ │ + * 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} true if the rule applies, false if it does not │ │ │ │ │ + * {Boolean} The filter applies. │ │ │ │ │ */ │ │ │ │ │ - evaluate: function(feature) { │ │ │ │ │ - for (var i = 0, len = this.fids.length; i < len; i++) { │ │ │ │ │ - var fid = feature.fid || feature.id; │ │ │ │ │ - if (fid == this.fids[i]) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ + evaluate: function(context) { │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: clone │ │ │ │ │ - * Clones this filter. │ │ │ │ │ + * Clones this filter. Should be implemented by subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ */ │ │ │ │ │ clone: function() { │ │ │ │ │ - var filter = new OpenLayers.Filter.FeatureId(); │ │ │ │ │ - OpenLayers.Util.extend(filter, this); │ │ │ │ │ - filter.fids = this.fids.slice(); │ │ │ │ │ - return filter; │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter.FeatureId" │ │ │ │ │ + /** │ │ │ │ │ + * 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/Format/WFST/v1.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/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Format/WFST.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ - * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WFST.v1 │ │ │ │ │ - * Superclass for WFST parsers. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance", │ │ │ │ │ - wfs: "http://www.opengis.net/wfs", │ │ │ │ │ - gml: "http://www.opengis.net/gml", │ │ │ │ │ - ogc: "http://www.opengis.net/ogc", │ │ │ │ │ - ows: "http://www.opengis.net/ows" │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Handler = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - defaultPrefix: "wfs", │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} WFS version number. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - version: null, │ │ │ │ │ + control: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - schemaLocations: null, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: srsName │ │ │ │ │ - * {String} URI for spatial reference system. │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - srsName: null, │ │ │ │ │ + keyMask: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: extractAttributes │ │ │ │ │ - * {Boolean} Extract attributes from GML. Default is true. │ │ │ │ │ + * Property: active │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - extractAttributes: true, │ │ │ │ │ + active: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: xy │ │ │ │ │ - * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ - * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - xy: true, │ │ │ │ │ + evt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stateName │ │ │ │ │ - * {Object} Maps feature states to node names. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - stateName: null, │ │ │ │ │ + touch: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WFST.v1 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * or │ │ │ │ │ - * constructor instead. │ │ │ │ │ + * 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 │ │ │ │ │ - * this instance. │ │ │ │ │ + * the handler. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - // set state name mapping │ │ │ │ │ - this.stateName = {}; │ │ │ │ │ - this.stateName[OpenLayers.State.INSERT] = "wfs:Insert"; │ │ │ │ │ - this.stateName[OpenLayers.State.UPDATE] = "wfs:Update"; │ │ │ │ │ - this.stateName[OpenLayers.State.DELETE] = "wfs:Delete"; │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + 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: getSrsName │ │ │ │ │ + * Method: setMap │ │ │ │ │ */ │ │ │ │ │ - getSrsName: function(feature, options) { │ │ │ │ │ - var srsName = options && options.srsName; │ │ │ │ │ - if (!srsName) { │ │ │ │ │ - if (feature && feature.layer) { │ │ │ │ │ - srsName = feature.layer.projection.getCode(); │ │ │ │ │ - } else { │ │ │ │ │ - srsName = this.srsName; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return srsName; │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Parse the response from a transaction. Because WFS is split into │ │ │ │ │ - * Transaction requests (create, update, and delete) and GetFeature │ │ │ │ │ - * requests (read), this method handles parsing of both types of │ │ │ │ │ - * responses. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String | Document} The WFST document to read │ │ │ │ │ - * options - {Object} Options for the reader │ │ │ │ │ - * │ │ │ │ │ - * Valid options properties: │ │ │ │ │ - * output - {String} either "features" or "object". The default is │ │ │ │ │ - * "features", which means that the method will return an array of │ │ │ │ │ - * features. If set to "object", an object with a "features" property │ │ │ │ │ - * and other properties read by the parser will be returned. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Array | Object} Output depending on the output option. │ │ │ │ │ + * {Boolean} The keyMask matches the keys down on an event. │ │ │ │ │ */ │ │ │ │ │ - read: function(data, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ - output: "features" │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - if (data && data.nodeType == 9) { │ │ │ │ │ - data = data.documentElement; │ │ │ │ │ - } │ │ │ │ │ - var obj = {}; │ │ │ │ │ - if (data) { │ │ │ │ │ - this.readNode(data, obj, true); │ │ │ │ │ - } │ │ │ │ │ - if (obj.features && options.output === "features") { │ │ │ │ │ - obj = obj.features; │ │ │ │ │ + checkModifiers: function(evt) { │ │ │ │ │ + if (this.keyMask == null) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - return obj; │ │ │ │ │ + /* 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was activated. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "wfs": { │ │ │ │ │ - "FeatureCollection": function(node, obj) { │ │ │ │ │ - obj.features = []; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ - * Given an array of features, write a WFS transaction. This assumes │ │ │ │ │ - * the features have a state property that determines the operation │ │ │ │ │ - * type - insert, update, or delete. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array()} A list of features. See │ │ │ │ │ - * below for a more detailed description of the influence of the │ │ │ │ │ - * feature's *modified* property. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * feature.modified rules: │ │ │ │ │ - * If a feature has a modified property set, the following checks will be │ │ │ │ │ - * made before a feature's geometry or attribute is included in an Update │ │ │ │ │ - * transaction: │ │ │ │ │ - * - *modified* is not set at all: The geometry and all attributes will be │ │ │ │ │ - * included. │ │ │ │ │ - * - *modified.geometry* is set (null or a geometry): The geometry will be │ │ │ │ │ - * included. If *modified.attributes* is not set, all attributes will │ │ │ │ │ - * be included. │ │ │ │ │ - * - *modified.attributes* is set: Only the attributes set (i.e. to null or │ │ │ │ │ - * a value) in *modified.attributes* will be included. │ │ │ │ │ - * If *modified.geometry* is not set, the geometry will not be included. │ │ │ │ │ - * │ │ │ │ │ - * Valid options include: │ │ │ │ │ - * - *multi* {Boolean} If set to true, geometries will be casted to │ │ │ │ │ - * Multi geometries before writing. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Turn off the handler. Returns false if the handler was already inactive. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A serialized WFS transaction. │ │ │ │ │ + * {Boolean} The handler was deactivated. │ │ │ │ │ */ │ │ │ │ │ - write: function(features, options) { │ │ │ │ │ - var node = this.writeNode("wfs:Transaction", { │ │ │ │ │ - features: features, │ │ │ │ │ - options: options │ │ │ │ │ - }); │ │ │ │ │ - var value = this.schemaLocationAttr(); │ │ │ │ │ - if (value) { │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - node, this.namespaces["xsi"], "xsi:schemaLocation", value │ │ │ │ │ - ); │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "wfs": { │ │ │ │ │ - "GetFeature": function(options) { │ │ │ │ │ - var node = this.createElementNSPlus("wfs:GetFeature", { │ │ │ │ │ - attributes: { │ │ │ │ │ - service: "WFS", │ │ │ │ │ - version: this.version, │ │ │ │ │ - handle: options && options.handle, │ │ │ │ │ - outputFormat: options && options.outputFormat, │ │ │ │ │ - maxFeatures: options && options.maxFeatures, │ │ │ │ │ - "xsi:schemaLocation": this.schemaLocationAttr(options) │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (typeof this.featureType == "string") { │ │ │ │ │ - this.writeNode("Query", options, node); │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = 0, len = this.featureType.length; i < len; i++) { │ │ │ │ │ - options.featureType = this.featureType[i]; │ │ │ │ │ - this.writeNode("Query", options, node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Transaction": function(obj) { │ │ │ │ │ - obj = obj || {}; │ │ │ │ │ - var options = obj.options || {}; │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Transaction", { │ │ │ │ │ - attributes: { │ │ │ │ │ - service: "WFS", │ │ │ │ │ - version: this.version, │ │ │ │ │ - handle: options.handle │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - var i, len; │ │ │ │ │ - var features = obj.features; │ │ │ │ │ - if (features) { │ │ │ │ │ - // temporarily re-assigning geometry types │ │ │ │ │ - if (options.multi === true) { │ │ │ │ │ - OpenLayers.Util.extend(this.geometryTypes, { │ │ │ │ │ - "OpenLayers.Geometry.Point": "MultiPoint", │ │ │ │ │ - "OpenLayers.Geometry.LineString": (this.multiCurve === true) ? "MultiCurve" : "MultiLineString", │ │ │ │ │ - "OpenLayers.Geometry.Polygon": (this.multiSurface === true) ? "MultiSurface" : "MultiPolygon" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - var name, feature; │ │ │ │ │ - for (i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - name = this.stateName[feature.state]; │ │ │ │ │ - if (name) { │ │ │ │ │ - this.writeNode(name, { │ │ │ │ │ - feature: feature, │ │ │ │ │ - options: options │ │ │ │ │ - }, node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // switch back to original geometry types assignment │ │ │ │ │ - if (options.multi === true) { │ │ │ │ │ - this.setGeometryTypes(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (options.nativeElements) { │ │ │ │ │ - for (i = 0, len = options.nativeElements.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("wfs:Native", │ │ │ │ │ - options.nativeElements[i], node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Native": function(nativeElement) { │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Native", { │ │ │ │ │ - attributes: { │ │ │ │ │ - vendorId: nativeElement.vendorId, │ │ │ │ │ - safeToIgnore: nativeElement.safeToIgnore │ │ │ │ │ - }, │ │ │ │ │ - value: nativeElement.value │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Insert": function(obj) { │ │ │ │ │ - var feature = obj.feature; │ │ │ │ │ - var options = obj.options; │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Insert", { │ │ │ │ │ - attributes: { │ │ │ │ │ - handle: options && options.handle │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.srsName = this.getSrsName(feature); │ │ │ │ │ - this.writeNode("feature:_typeName", feature, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Update": function(obj) { │ │ │ │ │ - var feature = obj.feature; │ │ │ │ │ - var options = obj.options; │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Update", { │ │ │ │ │ - attributes: { │ │ │ │ │ - handle: options && options.handle, │ │ │ │ │ - typeName: (this.featureNS ? this.featurePrefix + ":" : "") + │ │ │ │ │ - this.featureType │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (this.featureNS) { │ │ │ │ │ - node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add in geometry │ │ │ │ │ - var modified = feature.modified; │ │ │ │ │ - if (this.geometryName !== null && (!modified || modified.geometry !== undefined)) { │ │ │ │ │ - this.srsName = this.getSrsName(feature); │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "Property", { │ │ │ │ │ - name: this.geometryName, │ │ │ │ │ - value: feature.geometry │ │ │ │ │ - }, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add in attributes │ │ │ │ │ - for (var key in feature.attributes) { │ │ │ │ │ - if (feature.attributes[key] !== undefined && │ │ │ │ │ - (!modified || !modified.attributes || │ │ │ │ │ - (modified.attributes && modified.attributes[key] !== undefined))) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "Property", { │ │ │ │ │ - name: key, │ │ │ │ │ - value: feature.attributes[key] │ │ │ │ │ - }, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add feature id filter │ │ │ │ │ - this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ │ │ │ │ │ - fids: [feature.fid] │ │ │ │ │ - }), node); │ │ │ │ │ - │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Property": function(obj) { │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Property"); │ │ │ │ │ - this.writeNode("Name", obj.name, node); │ │ │ │ │ - if (obj.value !== null) { │ │ │ │ │ - this.writeNode("Value", obj.value, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Name": function(name) { │ │ │ │ │ - return this.createElementNSPlus("wfs:Name", { │ │ │ │ │ - value: name │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Value": function(obj) { │ │ │ │ │ - var node; │ │ │ │ │ - if (obj instanceof OpenLayers.Geometry) { │ │ │ │ │ - node = this.createElementNSPlus("wfs:Value"); │ │ │ │ │ - var geom = this.writeNode("feature:_geometry", obj).firstChild; │ │ │ │ │ - node.appendChild(geom); │ │ │ │ │ - } else { │ │ │ │ │ - node = this.createElementNSPlus("wfs:Value", { │ │ │ │ │ - value: obj │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Delete": function(obj) { │ │ │ │ │ - var feature = obj.feature; │ │ │ │ │ - var options = obj.options; │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Delete", { │ │ │ │ │ - attributes: { │ │ │ │ │ - handle: options && options.handle, │ │ │ │ │ - typeName: (this.featureNS ? this.featurePrefix + ":" : "") + │ │ │ │ │ - this.featureType │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (this.featureNS) { │ │ │ │ │ - node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); │ │ │ │ │ - } │ │ │ │ │ - this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ │ │ │ │ │ - fids: [feature.fid] │ │ │ │ │ - }), node); │ │ │ │ │ - return node; │ │ │ │ │ + // 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: schemaLocationAttr │ │ │ │ │ - * Generate the xsi:schemaLocation attribute value. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The xsi:schemaLocation attribute or undefined if none. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - schemaLocationAttr: function(options) { │ │ │ │ │ - options = OpenLayers.Util.extend({ │ │ │ │ │ - featurePrefix: this.featurePrefix, │ │ │ │ │ - schema: this.schema │ │ │ │ │ - }, options); │ │ │ │ │ - var schemaLocations = OpenLayers.Util.extend({}, this.schemaLocations); │ │ │ │ │ - if (options.schema) { │ │ │ │ │ - schemaLocations[options.featurePrefix] = options.schema; │ │ │ │ │ - } │ │ │ │ │ - var parts = []; │ │ │ │ │ - var uri; │ │ │ │ │ - for (var key in schemaLocations) { │ │ │ │ │ - uri = this.namespaces[key]; │ │ │ │ │ - if (uri) { │ │ │ │ │ - parts.push(uri + " " + schemaLocations[key]); │ │ │ │ │ + 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]]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - var value = parts.join(" ") || undefined; │ │ │ │ │ - return value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setFilterProperty │ │ │ │ │ - * Set the property of each spatial filter. │ │ │ │ │ + * Method: callback │ │ │ │ │ + * Trigger the control's named callback with the given arguments │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * filter - {} │ │ │ │ │ + * 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). │ │ │ │ │ */ │ │ │ │ │ - setFilterProperty: function(filter) { │ │ │ │ │ - if (filter.filters) { │ │ │ │ │ - for (var i = 0, len = filter.filters.length; i < len; ++i) { │ │ │ │ │ - OpenLayers.Format.WFST.v1.prototype.setFilterProperty.call(this, filter.filters[i]); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - if (filter instanceof OpenLayers.Filter.Spatial && !filter.property) { │ │ │ │ │ - // got a spatial filter without property, so set it │ │ │ │ │ - filter.property = this.geometryName; │ │ │ │ │ - } │ │ │ │ │ + callback: function(name, args) { │ │ │ │ │ + if (name && this.callbacks[name]) { │ │ │ │ │ + this.callbacks[name].apply(this.control, args); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WFST.v1" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Filter/Logical.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/Filter.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Filter.Logical │ │ │ │ │ - * This class represents ogc:And, ogc:Or and ogc:Not rules. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: filters │ │ │ │ │ - * {Array()} Child filters for this filter. │ │ │ │ │ + * Method: register │ │ │ │ │ + * register an event on the map │ │ │ │ │ */ │ │ │ │ │ - filters: 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {String} type of logical operator. Available types are: │ │ │ │ │ - * - OpenLayers.Filter.Logical.AND = "&&"; │ │ │ │ │ - * - OpenLayers.Filter.Logical.OR = "||"; │ │ │ │ │ - * - OpenLayers.Filter.Logical.NOT = "!"; │ │ │ │ │ + * Method: unregister │ │ │ │ │ + * unregister an event from the map │ │ │ │ │ */ │ │ │ │ │ - type: null, │ │ │ │ │ + unregister: function(name, method) { │ │ │ │ │ + this.map.events.unregister(name, this, method); │ │ │ │ │ + this.map.events.unregister(name, this, this.setEvent); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Filter.Logical │ │ │ │ │ - * Creates a logical filter (And, Or, Not). │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * filter. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * evt - {Event} The browser event. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.filters = []; │ │ │ │ │ - OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ + setEvent: function(evt) { │ │ │ │ │ + this.evt = evt; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Remove reference to child filters. │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Deconstruct the handler. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - this.filters = null; │ │ │ │ │ - OpenLayers.Filter.prototype.destroy.apply(this); │ │ │ │ │ + // unregister event listeners │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + // eliminate circular references │ │ │ │ │ + this.control = this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * Evaluates this filter in a specific context. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * context - {Object} Context to use in evaluating the filter. A vector │ │ │ │ │ - * feature may also be provided to evaluate feature attributes in │ │ │ │ │ - * comparison filters or geometries in spatial filters. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The filter applies. │ │ │ │ │ - */ │ │ │ │ │ - evaluate: function(context) { │ │ │ │ │ - var i, len; │ │ │ │ │ - switch (this.type) { │ │ │ │ │ - case OpenLayers.Filter.Logical.AND: │ │ │ │ │ - for (i = 0, len = this.filters.length; i < len; i++) { │ │ │ │ │ - if (this.filters[i].evaluate(context) == false) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - case OpenLayers.Filter.Logical.OR: │ │ │ │ │ - for (i = 0, len = this.filters.length; i < len; i++) { │ │ │ │ │ - if (this.filters[i].evaluate(context) == true) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_NONE │ │ │ │ │ + * If set as the , returns false if any key is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_NONE = 0; │ │ │ │ │ │ │ │ │ │ - case OpenLayers.Filter.Logical.NOT: │ │ │ │ │ - return (!this.filters[0].evaluate(context)); │ │ │ │ │ - } │ │ │ │ │ - return undefined; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_SHIFT │ │ │ │ │ + * If set as the , returns false if Shift is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_SHIFT = 1; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this filter. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var filters = []; │ │ │ │ │ - for (var i = 0, len = this.filters.length; i < len; ++i) { │ │ │ │ │ - filters.push(this.filters[i].clone()); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: this.type, │ │ │ │ │ - filters: filters │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_CTRL │ │ │ │ │ + * If set as the , returns false if Ctrl is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_CTRL = 2; │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter.Logical" │ │ │ │ │ -}); │ │ │ │ │ +/** │ │ │ │ │ + * 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.Filter.Logical.AND = "&&"; │ │ │ │ │ -OpenLayers.Filter.Logical.OR = "||"; │ │ │ │ │ -OpenLayers.Filter.Logical.NOT = "!"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Filter/Comparison.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/Filter.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Filter.Comparison │ │ │ │ │ - * This class represents a comparison filter. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ +OpenLayers.Geometry = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {String} type: type of the comparison. This is one of │ │ │ │ │ - * - OpenLayers.Filter.Comparison.EQUAL_TO = "=="; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.NOT_EQUAL_TO = "!="; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.LESS_THAN = "<"; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.GREATER_THAN = ">"; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.BETWEEN = ".."; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.LIKE = "~"; │ │ │ │ │ - * - OpenLayers.Filter.Comparison.IS_NULL = "NULL"; │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique identifier for this geometry. │ │ │ │ │ */ │ │ │ │ │ - type: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: property │ │ │ │ │ - * {String} │ │ │ │ │ - * name of the context property to compare │ │ │ │ │ + * Property: parent │ │ │ │ │ + * {}This is set when a Geometry is added as component │ │ │ │ │ + * of another geometry │ │ │ │ │ */ │ │ │ │ │ - property: null, │ │ │ │ │ + parent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: value │ │ │ │ │ - * {Number} or {String} │ │ │ │ │ - * comparison value for binary comparisons. In the case of a String, this │ │ │ │ │ - * can be a combination of text and propertyNames in the form │ │ │ │ │ - * "literal ${propertyName}" │ │ │ │ │ + * Property: bounds │ │ │ │ │ + * {} The bounds of this geometry │ │ │ │ │ */ │ │ │ │ │ - value: null, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: matchCase │ │ │ │ │ - * {Boolean} Force case sensitive searches for EQUAL_TO and NOT_EQUAL_TO │ │ │ │ │ - * comparisons. The Filter Encoding 1.1 specification added a matchCase │ │ │ │ │ - * attribute to ogc:PropertyIsEqualTo and ogc:PropertyIsNotEqualTo │ │ │ │ │ - * elements. This property will be serialized with those elements only │ │ │ │ │ - * if using the v1.1.0 filter format. However, when evaluating filters │ │ │ │ │ - * here, the matchCase property will always be respected (for EQUAL_TO │ │ │ │ │ - * and NOT_EQUAL_TO). Default is true. │ │ │ │ │ + * Constructor: OpenLayers.Geometry │ │ │ │ │ + * Creates a geometry object. │ │ │ │ │ */ │ │ │ │ │ - matchCase: true, │ │ │ │ │ + initialize: function() { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: lowerBoundary │ │ │ │ │ - * {Number} or {String} │ │ │ │ │ - * lower boundary for between comparisons. In the case of a String, this │ │ │ │ │ - * can be a combination of text and propertyNames in the form │ │ │ │ │ - * "literal ${propertyName}" │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - lowerBoundary: null, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: upperBoundary │ │ │ │ │ - * {Number} or {String} │ │ │ │ │ - * upper boundary for between comparisons. In the case of a String, this │ │ │ │ │ - * can be a combination of text and propertyNames in the form │ │ │ │ │ - * "literal ${propertyName}" │ │ │ │ │ - */ │ │ │ │ │ - upperBoundary: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Filter.Comparison │ │ │ │ │ - * Creates a comparison rule. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ - // since matchCase on PropertyIsLike is not schema compliant, we only │ │ │ │ │ - // want to use this if explicitly asked for │ │ │ │ │ - if (this.type === OpenLayers.Filter.Comparison.LIKE && │ │ │ │ │ - options.matchCase === undefined) { │ │ │ │ │ - this.matchCase = null; │ │ │ │ │ - } │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Geometry(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * Evaluates this filter in a specific context. │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Set the bounds for this Geometry. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - evaluate: function(context) { │ │ │ │ │ - if (context instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - context = context.attributes; │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + if (bounds) { │ │ │ │ │ + this.bounds = bounds.clone(); │ │ │ │ │ } │ │ │ │ │ - var result = false; │ │ │ │ │ - var got = context[this.property]; │ │ │ │ │ - var exp; │ │ │ │ │ - switch (this.type) { │ │ │ │ │ - case OpenLayers.Filter.Comparison.EQUAL_TO: │ │ │ │ │ - exp = this.value; │ │ │ │ │ - if (!this.matchCase && │ │ │ │ │ - typeof got == "string" && typeof exp == "string") { │ │ │ │ │ - result = (got.toUpperCase() == exp.toUpperCase()); │ │ │ │ │ - } else { │ │ │ │ │ - result = (got == exp); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.NOT_EQUAL_TO: │ │ │ │ │ - exp = this.value; │ │ │ │ │ - if (!this.matchCase && │ │ │ │ │ - typeof got == "string" && typeof exp == "string") { │ │ │ │ │ - result = (got.toUpperCase() != exp.toUpperCase()); │ │ │ │ │ - } else { │ │ │ │ │ - result = (got != exp); │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.LESS_THAN: │ │ │ │ │ - result = got < this.value; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.GREATER_THAN: │ │ │ │ │ - result = got > this.value; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO: │ │ │ │ │ - result = got <= this.value; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO: │ │ │ │ │ - result = got >= this.value; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.BETWEEN: │ │ │ │ │ - result = (got >= this.lowerBoundary) && │ │ │ │ │ - (got <= this.upperBoundary); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.LIKE: │ │ │ │ │ - var regexp = new RegExp(this.value, "gi"); │ │ │ │ │ - result = regexp.test(got); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Filter.Comparison.IS_NULL: │ │ │ │ │ - result = (got === null); │ │ │ │ │ - break; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearBounds │ │ │ │ │ + * Nullify this components bounds and that of its parent as well. │ │ │ │ │ + */ │ │ │ │ │ + clearBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + if (this.parent) { │ │ │ │ │ + this.parent.clearBounds(); │ │ │ │ │ } │ │ │ │ │ - return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: value2regex │ │ │ │ │ - * Converts the value of this rule into a regular expression string, │ │ │ │ │ - * according to the wildcard characters specified. This method has to │ │ │ │ │ - * be called after instantiation of this class, if the value is not a │ │ │ │ │ - * regular expression already. │ │ │ │ │ + * 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: │ │ │ │ │ - * wildCard - {Char} wildcard character in the above value, default │ │ │ │ │ - * is "*" │ │ │ │ │ - * singleChar - {Char} single-character wildcard in the above value │ │ │ │ │ - * default is "." │ │ │ │ │ - * escapeChar - {Char} escape character in the above value, default is │ │ │ │ │ - * "!" │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} regular expression string │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - value2regex: function(wildCard, singleChar, escapeChar) { │ │ │ │ │ - if (wildCard == ".") { │ │ │ │ │ - throw new Error("'.' is an unsupported wildCard character for " + │ │ │ │ │ - "OpenLayers.Filter.Comparison"); │ │ │ │ │ + getBounds: function() { │ │ │ │ │ + if (this.bounds == null) { │ │ │ │ │ + this.calculateBounds(); │ │ │ │ │ } │ │ │ │ │ + return this.bounds; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - // set UMN MapServer defaults for unspecified parameters │ │ │ │ │ - wildCard = wildCard ? wildCard : "*"; │ │ │ │ │ - singleChar = singleChar ? singleChar : "."; │ │ │ │ │ - escapeChar = escapeChar ? escapeChar : "!"; │ │ │ │ │ - │ │ │ │ │ - this.value = this.value.replace( │ │ │ │ │ - new RegExp("\\" + escapeChar + "(.|$)", "g"), "\\$1"); │ │ │ │ │ - this.value = this.value.replace( │ │ │ │ │ - new RegExp("\\" + singleChar, "g"), "."); │ │ │ │ │ - this.value = this.value.replace( │ │ │ │ │ - new RegExp("\\" + wildCard, "g"), ".*"); │ │ │ │ │ - this.value = this.value.replace( │ │ │ │ │ - new RegExp("\\\\.\\*", "g"), "\\" + wildCard); │ │ │ │ │ - this.value = this.value.replace( │ │ │ │ │ - new RegExp("\\\\\\.", "g"), "\\" + singleChar); │ │ │ │ │ - │ │ │ │ │ - return this.value; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds for the geometry. │ │ │ │ │ + */ │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + // │ │ │ │ │ + // This should be overridden by subclasses. │ │ │ │ │ + // │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: regex2value │ │ │ │ │ - * Convert the value of this rule from a regular expression string into an │ │ │ │ │ - * ogc literal string using a wildCard of *, a singleChar of ., and an │ │ │ │ │ - * escape of !. Leaves the property unmodified. │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} A string value. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - regex2value: function() { │ │ │ │ │ - │ │ │ │ │ - var value = this.value; │ │ │ │ │ - │ │ │ │ │ - // replace ! with !! │ │ │ │ │ - value = value.replace(/!/g, "!!"); │ │ │ │ │ + distanceTo: function(geometry, options) {}, │ │ │ │ │ │ │ │ │ │ - // replace \. with !. (watching out for \\.) │ │ │ │ │ - value = value.replace(/(\\)?\\\./g, function($0, $1) { │ │ │ │ │ - return $1 ? $0 : "!."; │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * 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) {}, │ │ │ │ │ │ │ │ │ │ - // replace \* with #* (watching out for \\*) │ │ │ │ │ - value = value.replace(/(\\)?\\\*/g, function($0, $1) { │ │ │ │ │ - return $1 ? $0 : "!*"; │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * 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)) { │ │ │ │ │ │ │ │ │ │ - // replace \\ with \ │ │ │ │ │ - value = value.replace(/\\\\/g, "\\"); │ │ │ │ │ + var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ + var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ │ │ │ │ │ - // convert .* to * (the sequence #.* is not allowed) │ │ │ │ │ - value = value.replace(/\.\*/g, "*"); │ │ │ │ │ + var toleranceBounds = │ │ │ │ │ + new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ + this.bounds.bottom - dY, │ │ │ │ │ + this.bounds.right + dX, │ │ │ │ │ + this.bounds.top + dY); │ │ │ │ │ │ │ │ │ │ - return value; │ │ │ │ │ + atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ + } │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this filter. │ │ │ │ │ + * Method: getLength │ │ │ │ │ + * Calculate the length of this geometry. This method is defined in │ │ │ │ │ + * subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ + * {Float} The length of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return OpenLayers.Util.extend(new OpenLayers.Filter.Comparison(), this); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + //to be overridden by geometries that actually have a length │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter.Comparison" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Filter.Comparison.EQUAL_TO = "=="; │ │ │ │ │ -OpenLayers.Filter.Comparison.NOT_EQUAL_TO = "!="; │ │ │ │ │ -OpenLayers.Filter.Comparison.LESS_THAN = "<"; │ │ │ │ │ -OpenLayers.Filter.Comparison.GREATER_THAN = ">"; │ │ │ │ │ -OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; │ │ │ │ │ -OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; │ │ │ │ │ -OpenLayers.Filter.Comparison.BETWEEN = ".."; │ │ │ │ │ -OpenLayers.Filter.Comparison.LIKE = "~"; │ │ │ │ │ -OpenLayers.Filter.Comparison.IS_NULL = "NULL"; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/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/Format/XML/VersionedOGC.js │ │ │ │ │ - * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ - * @requires OpenLayers/Filter/Logical.js │ │ │ │ │ - * @requires OpenLayers/Filter/Comparison.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.Filter │ │ │ │ │ - * Read/Write ogc:Filter. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.Filter = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: defaultVersion │ │ │ │ │ - * {String} Version number to assume if none found. Default is "1.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 │ │ │ │ │ */ │ │ │ │ │ - defaultVersion: "1.0.0", │ │ │ │ │ + getArea: function() { │ │ │ │ │ + //to be overridden by geometries that actually have an area │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Write an ogc:Filter given a filter object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} An filter. │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Elment} An ogc:Filter element node. │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read and Filter doc and return an object representing the Filter. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String | DOMElement} Data to read. │ │ │ │ │ + * 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: │ │ │ │ │ - * {} A filter object. │ │ │ │ │ + * {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.Format.Filter" │ │ │ │ │ + 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/Filter/Function.js │ │ │ │ │ + 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/Filter.js │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Filter.Function │ │ │ │ │ - * This class represents a filter function. │ │ │ │ │ - * We are using this class for creation of complex │ │ │ │ │ - * filters that can contain filter functions as values. │ │ │ │ │ - * Nesting function as other functions parameter is supported. │ │ │ │ │ + * Class: OpenLayers.Geometry.Point │ │ │ │ │ + * Point geometry class. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Filter.Function = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ +OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} Name of the function. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: x │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - name: null, │ │ │ │ │ + x: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: params │ │ │ │ │ - * {Array( || String || Number)} Function parameters │ │ │ │ │ - * For now support only other Functions, String or Number │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: y │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + y: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Filter.Function │ │ │ │ │ - * Creates a filter function. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ + * Construct a point geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * function. │ │ │ │ │ + * x - {float} │ │ │ │ │ + * y - {float} │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ */ │ │ │ │ │ + initialize: function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter.Function" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/BaseTypes/Date.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + this.x = parseFloat(x); │ │ │ │ │ + this.y = parseFloat(y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Date │ │ │ │ │ - * Contains implementations of Date.parse and date.toISOString that match the │ │ │ │ │ - * ECMAScript 5 specification for parsing RFC 3339 dates. │ │ │ │ │ - * http://tools.ietf.org/html/rfc3339 │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Date = { │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dateRegEx │ │ │ │ │ - * The regex to be used for validating dates. You can provide your own │ │ │ │ │ - * regex for instance for adding support for years before BC. Default │ │ │ │ │ - * value is: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/ │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * Create a new Bounds based on the lon/lat │ │ │ │ │ */ │ │ │ │ │ - dateRegEx: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/, │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ + this.x, this.y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: toISOString │ │ │ │ │ - * Generates a string representing a date. The format of the string follows │ │ │ │ │ - * the profile of ISO 8601 for date and time on the Internet (see │ │ │ │ │ - * http://tools.ietf.org/html/rfc3339). If the toISOString method is │ │ │ │ │ - * available on the Date prototype, that is used. The toISOString │ │ │ │ │ - * method for Date instances is defined in ECMA-262. │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * date - {Date} A date object. │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} A string representing the date (e.g. │ │ │ │ │ - * "2010-08-07T16:58:23.123Z"). If the date does not have a valid time │ │ │ │ │ - * (i.e. isNaN(date.getTime())) this method returns the string "Invalid │ │ │ │ │ - * Date". The ECMA standard says the toISOString method should throw │ │ │ │ │ - * RangeError in this case, but Firefox returns a string instead. For │ │ │ │ │ - * best results, use isNaN(date.getTime()) to determine date validity │ │ │ │ │ - * before generating date strings. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - toISOString: (function() { │ │ │ │ │ - if ("toISOString" in Date.prototype) { │ │ │ │ │ - return function(date) { │ │ │ │ │ - return date.toISOString(); │ │ │ │ │ - }; │ │ │ │ │ + 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 { │ │ │ │ │ - return function(date) { │ │ │ │ │ - var str; │ │ │ │ │ - if (isNaN(date.getTime())) { │ │ │ │ │ - // ECMA-262 says throw RangeError, Firefox returns │ │ │ │ │ - // "Invalid Date" │ │ │ │ │ - str = "Invalid Date"; │ │ │ │ │ - } else { │ │ │ │ │ - str = │ │ │ │ │ - date.getUTCFullYear() + "-" + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCMonth() + 1, 2) + "-" + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCDate(), 2) + "T" + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCHours(), 2) + ":" + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCMinutes(), 2) + ":" + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCSeconds(), 2) + "." + │ │ │ │ │ - OpenLayers.Number.zeroPad(date.getUTCMilliseconds(), 3) + "Z"; │ │ │ │ │ - } │ │ │ │ │ - return str; │ │ │ │ │ - }; │ │ │ │ │ + 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: parse │ │ │ │ │ - * Generate a date object from a string. The format for the string follows │ │ │ │ │ - * the profile of ISO 8601 for date and time on the Internet (see │ │ │ │ │ - * http://tools.ietf.org/html/rfc3339). We don't call the native │ │ │ │ │ - * Date.parse because of inconsistency between implmentations. In │ │ │ │ │ - * Chrome, calling Date.parse with a string that doesn't contain any │ │ │ │ │ - * indication of the timezone (e.g. "2011"), the date is interpreted │ │ │ │ │ - * in local time. On Firefox, the assumption is UTC. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * str - {String} A string representing the date (e.g. │ │ │ │ │ - * "2010", "2010-08", "2010-08-07", "2010-08-07T16:58:23.123Z", │ │ │ │ │ - * "2010-08-07T11:58:23.123-06"). │ │ │ │ │ + * geom - {} The geometry to test. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Date} A date object. If the string could not be parsed, an invalid │ │ │ │ │ - * date is returned (i.e. isNaN(date.getTime())). │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - parse: function(str) { │ │ │ │ │ - var date; │ │ │ │ │ - var match = str.match(this.dateRegEx); │ │ │ │ │ - if (match && (match[1] || match[7])) { // must have at least year or time │ │ │ │ │ - var year = parseInt(match[1], 10) || 0; │ │ │ │ │ - var month = (parseInt(match[2], 10) - 1) || 0; │ │ │ │ │ - var day = parseInt(match[3], 10) || 1; │ │ │ │ │ - date = new Date(Date.UTC(year, month, day)); │ │ │ │ │ - // optional time │ │ │ │ │ - var type = match[7]; │ │ │ │ │ - if (type) { │ │ │ │ │ - var hours = parseInt(match[4], 10); │ │ │ │ │ - var minutes = parseInt(match[5], 10); │ │ │ │ │ - var secFrac = parseFloat(match[6]); │ │ │ │ │ - var seconds = secFrac | 0; │ │ │ │ │ - var milliseconds = Math.round(1000 * (secFrac - seconds)); │ │ │ │ │ - date.setUTCHours(hours, minutes, seconds, milliseconds); │ │ │ │ │ - // check offset │ │ │ │ │ - if (type !== "Z") { │ │ │ │ │ - var hoursOffset = parseInt(type, 10); │ │ │ │ │ - var minutesOffset = parseInt(match[8], 10) || 0; │ │ │ │ │ - var offset = -1000 * (60 * (hoursOffset * 60) + minutesOffset * 60); │ │ │ │ │ - date = new Date(date.getTime() + offset); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - date = new Date("invalid"); │ │ │ │ │ + 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 date; │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/Filter/v1.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/Filter.js │ │ │ │ │ - * @requires OpenLayers/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Filter/Function.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Date.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.Filter.v1 │ │ │ │ │ - * Superclass for Filter version 1 parsers. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ogc: "http://www.opengis.net/ogc", │ │ │ │ │ - gml: "http://www.opengis.net/gml", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - */ │ │ │ │ │ - defaultPrefix: "ogc", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. │ │ │ │ │ + * Method: toShortString │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Shortened String representation of Point object. │ │ │ │ │ + * (ex. "5, 42") │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: null, │ │ │ │ │ + toShortString: function() { │ │ │ │ │ + return (this.x + ", " + this.y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.Filter.v1 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * constructor instead. │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ + * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + this.x = this.x + x; │ │ │ │ │ + this.y = this.y + y; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a point around another. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {DOMElement} A Filter document element. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A filter object. │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readers.ogc["Filter"].apply(this, [data, obj]); │ │ │ │ │ - return obj.filter; │ │ │ │ │ + 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(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "ogc": { │ │ │ │ │ - "_expression": function(node) { │ │ │ │ │ - // only the simplest of ogc:expression handled │ │ │ │ │ - // "some text and an attribute"} │ │ │ │ │ - var obj, value = ""; │ │ │ │ │ - for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - switch (child.nodeType) { │ │ │ │ │ - case 1: │ │ │ │ │ - obj = this.readNode(child); │ │ │ │ │ - if (obj.property) { │ │ │ │ │ - value += "${" + obj.property + "}"; │ │ │ │ │ - } else if (obj.value !== undefined) { │ │ │ │ │ - value += obj.value; │ │ │ │ │ - } │ │ │ │ │ - break; │ │ │ │ │ - case 3: // text node │ │ │ │ │ - case 4: // cdata section │ │ │ │ │ - value += child.nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return value; │ │ │ │ │ - }, │ │ │ │ │ - "Filter": function(node, parent) { │ │ │ │ │ - // Filters correspond to subclasses of OpenLayers.Filter. │ │ │ │ │ - // Since they contain information we don't persist, we │ │ │ │ │ - // create a temporary object and then pass on the filter │ │ │ │ │ - // (ogc:Filter) to the parent obj. │ │ │ │ │ - var obj = { │ │ │ │ │ - fids: [], │ │ │ │ │ - filters: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (obj.fids.length > 0) { │ │ │ │ │ - parent.filter = new OpenLayers.Filter.FeatureId({ │ │ │ │ │ - fids: obj.fids │ │ │ │ │ - }); │ │ │ │ │ - } else if (obj.filters.length > 0) { │ │ │ │ │ - parent.filter = obj.filters[0]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "FeatureId": function(node, obj) { │ │ │ │ │ - var fid = node.getAttribute("fid"); │ │ │ │ │ - if (fid) { │ │ │ │ │ - obj.fids.push(fid); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "And": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.AND │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "Or": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.OR │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "Not": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.NOT │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLessThan": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.LESS_THAN │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsGreaterThan": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.GREATER_THAN │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLessThanOrEqualTo": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsGreaterThanOrEqualTo": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsBetween": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.BETWEEN │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "Literal": function(node, obj) { │ │ │ │ │ - obj.value = OpenLayers.String.numericIf( │ │ │ │ │ - this.getChildValue(node), true); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyName": function(node, filter) { │ │ │ │ │ - filter.property = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "LowerBoundary": function(node, filter) { │ │ │ │ │ - filter.lowerBoundary = OpenLayers.String.numericIf( │ │ │ │ │ - this.readers.ogc._expression.call(this, node), true); │ │ │ │ │ - }, │ │ │ │ │ - "UpperBoundary": function(node, filter) { │ │ │ │ │ - filter.upperBoundary = OpenLayers.String.numericIf( │ │ │ │ │ - this.readers.ogc._expression.call(this, node), true); │ │ │ │ │ - }, │ │ │ │ │ - "Intersects": function(node, obj) { │ │ │ │ │ - this.readSpatial(node, obj, OpenLayers.Filter.Spatial.INTERSECTS); │ │ │ │ │ - }, │ │ │ │ │ - "Within": function(node, obj) { │ │ │ │ │ - this.readSpatial(node, obj, OpenLayers.Filter.Spatial.WITHIN); │ │ │ │ │ - }, │ │ │ │ │ - "Contains": function(node, obj) { │ │ │ │ │ - this.readSpatial(node, obj, OpenLayers.Filter.Spatial.CONTAINS); │ │ │ │ │ - }, │ │ │ │ │ - "DWithin": function(node, obj) { │ │ │ │ │ - this.readSpatial(node, obj, OpenLayers.Filter.Spatial.DWITHIN); │ │ │ │ │ - }, │ │ │ │ │ - "Distance": function(node, obj) { │ │ │ │ │ - obj.distance = parseInt(this.getChildValue(node)); │ │ │ │ │ - obj.distanceUnits = node.getAttribute("units"); │ │ │ │ │ - }, │ │ │ │ │ - "Function": function(node, obj) { │ │ │ │ │ - //TODO write decoder for it │ │ │ │ │ - return; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNull": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.IS_NULL │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: readSpatial │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Read a {} filter. │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {DOMElement} A DOM element that contains an ogc:expression. │ │ │ │ │ - * obj - {Object} The target object. │ │ │ │ │ - * type - {String} One of the OpenLayers.Filter.Spatial.* constants. │ │ │ │ │ - * │ │ │ │ │ + * 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 created filter. │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - readSpatial: function(node, obj, type) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: type │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - filter.value = filter.components[0]; │ │ │ │ │ - delete filter.components; │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ + 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: encodeLiteral │ │ │ │ │ - * Generates the string representation of a value for use in │ │ │ │ │ - * elements. The default encoder writes Date values as ISO 8601 │ │ │ │ │ - * strings. │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * value - {Object} Literal value to encode │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} String representation of the provided value. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - encodeLiteral: function(value) { │ │ │ │ │ - if (value instanceof Date) { │ │ │ │ │ - value = OpenLayers.Date.toISOString(value); │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + intersect = this.equals(geometry); │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ } │ │ │ │ │ - return value; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeOgcExpression │ │ │ │ │ - * Limited support for writing OGC expressions. Currently it supports │ │ │ │ │ - * ( || String || Number) │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Translate the x,y properties of the point from source to dest. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * value - ( || String || Number) │ │ │ │ │ - * node - {DOMElement} A parent DOM element │ │ │ │ │ - * │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} Updated node element. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - writeOgcExpression: function(value, node) { │ │ │ │ │ - if (value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ - this.writeNode("Function", value, node); │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("Literal", value, node); │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if ((source && dest)) { │ │ │ │ │ + OpenLayers.Projection.transform( │ │ │ │ │ + this, source, dest); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * filter - {} A filter 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: │ │ │ │ │ - * {DOMElement} An ogc:Filter element. │ │ │ │ │ - */ │ │ │ │ │ - write: function(filter) { │ │ │ │ │ - return this.writers.ogc["Filter"].apply(this, [filter]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ogc": { │ │ │ │ │ - "Filter": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:Filter"); │ │ │ │ │ - this.writeNode(this.getFilterType(filter), filter, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "_featureIds": function(filter) { │ │ │ │ │ - var node = this.createDocumentFragment(); │ │ │ │ │ - for (var i = 0, ii = filter.fids.length; i < ii; ++i) { │ │ │ │ │ - this.writeNode("ogc:FeatureId", filter.fids[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "FeatureId": function(fid) { │ │ │ │ │ - return this.createElementNSPlus("ogc:FeatureId", { │ │ │ │ │ - attributes: { │ │ │ │ │ - fid: fid │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "And": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:And"); │ │ │ │ │ - var childFilter; │ │ │ │ │ - for (var i = 0, ii = filter.filters.length; i < ii; ++i) { │ │ │ │ │ - childFilter = filter.filters[i]; │ │ │ │ │ - this.writeNode( │ │ │ │ │ - this.getFilterType(childFilter), childFilter, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Or": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:Or"); │ │ │ │ │ - var childFilter; │ │ │ │ │ - for (var i = 0, ii = filter.filters.length; i < ii; ++i) { │ │ │ │ │ - childFilter = filter.filters[i]; │ │ │ │ │ - this.writeNode( │ │ │ │ │ - this.getFilterType(childFilter), childFilter, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Not": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:Not"); │ │ │ │ │ - var childFilter = filter.filters[0]; │ │ │ │ │ - this.writeNode( │ │ │ │ │ - this.getFilterType(childFilter), childFilter, node │ │ │ │ │ - ); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLessThan": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsLessThan"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsGreaterThan": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsGreaterThan"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLessThanOrEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsLessThanOrEqualTo"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsGreaterThanOrEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsGreaterThanOrEqualTo"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsBetween": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsBetween"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - this.writeNode("LowerBoundary", filter, node); │ │ │ │ │ - this.writeNode("UpperBoundary", filter, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyName": function(filter) { │ │ │ │ │ - // no ogc:expression handling for now │ │ │ │ │ - return this.createElementNSPlus("ogc:PropertyName", { │ │ │ │ │ - value: filter.property │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Literal": function(value) { │ │ │ │ │ - var encode = this.encodeLiteral || │ │ │ │ │ - OpenLayers.Format.Filter.v1.prototype.encodeLiteral; │ │ │ │ │ - return this.createElementNSPlus("ogc:Literal", { │ │ │ │ │ - value: encode(value) │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "LowerBoundary": function(filter) { │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - var node = this.createElementNSPlus("ogc:LowerBoundary"); │ │ │ │ │ - this.writeOgcExpression(filter.lowerBoundary, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "UpperBoundary": function(filter) { │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - var node = this.createElementNSPlus("ogc:UpperBoundary"); │ │ │ │ │ - this.writeNode("Literal", filter.upperBoundary, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "INTERSECTS": function(filter) { │ │ │ │ │ - return this.writeSpatial(filter, "Intersects"); │ │ │ │ │ - }, │ │ │ │ │ - "WITHIN": function(filter) { │ │ │ │ │ - return this.writeSpatial(filter, "Within"); │ │ │ │ │ - }, │ │ │ │ │ - "CONTAINS": function(filter) { │ │ │ │ │ - return this.writeSpatial(filter, "Contains"); │ │ │ │ │ - }, │ │ │ │ │ - "DWITHIN": function(filter) { │ │ │ │ │ - var node = this.writeSpatial(filter, "DWithin"); │ │ │ │ │ - this.writeNode("Distance", filter, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Distance": function(filter) { │ │ │ │ │ - return this.createElementNSPlus("ogc:Distance", { │ │ │ │ │ - attributes: { │ │ │ │ │ - units: filter.distanceUnits │ │ │ │ │ - }, │ │ │ │ │ - value: filter.distance │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Function": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:Function", { │ │ │ │ │ - attributes: { │ │ │ │ │ - name: filter.name │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - var params = filter.params; │ │ │ │ │ - for (var i = 0, len = params.length; i < len; i++) { │ │ │ │ │ - this.writeOgcExpression(params[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNull": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsNull"); │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - return node; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getFilterType │ │ │ │ │ - */ │ │ │ │ │ - getFilterType: function(filter) { │ │ │ │ │ - var filterType = this.filterMap[filter.type]; │ │ │ │ │ - if (!filterType) { │ │ │ │ │ - throw "Filter writing not supported for rule type: " + filter.type; │ │ │ │ │ - } │ │ │ │ │ - return filterType; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: filterMap │ │ │ │ │ - * {Object} Contains a member for each filter type. Values are node names │ │ │ │ │ - * for corresponding OGC Filter child elements. │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - filterMap: { │ │ │ │ │ - "&&": "And", │ │ │ │ │ - "||": "Or", │ │ │ │ │ - "!": "Not", │ │ │ │ │ - "==": "PropertyIsEqualTo", │ │ │ │ │ - "!=": "PropertyIsNotEqualTo", │ │ │ │ │ - "<": "PropertyIsLessThan", │ │ │ │ │ - ">": "PropertyIsGreaterThan", │ │ │ │ │ - "<=": "PropertyIsLessThanOrEqualTo", │ │ │ │ │ - ">=": "PropertyIsGreaterThanOrEqualTo", │ │ │ │ │ - "..": "PropertyIsBetween", │ │ │ │ │ - "~": "PropertyIsLike", │ │ │ │ │ - "NULL": "PropertyIsNull", │ │ │ │ │ - "BBOX": "BBOX", │ │ │ │ │ - "DWITHIN": "DWITHIN", │ │ │ │ │ - "WITHIN": "WITHIN", │ │ │ │ │ - "CONTAINS": "CONTAINS", │ │ │ │ │ - "INTERSECTS": "INTERSECTS", │ │ │ │ │ - "FID": "_featureIds" │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + return [this]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.Filter.v1" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/GML.js │ │ │ │ │ + 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/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.GML │ │ │ │ │ - * Read/Write GML. Create a new instance with the │ │ │ │ │ - * constructor. Supports the GML simple features profile. │ │ │ │ │ + * 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.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ +OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureNS │ │ │ │ │ - * {String} Namespace used for feature attributes. Default is │ │ │ │ │ - * "http://mapserver.gis.umn.edu/mapserver". │ │ │ │ │ + * APIProperty: components │ │ │ │ │ + * {Array()} The component parts of this geometry │ │ │ │ │ */ │ │ │ │ │ - featureNS: "http://mapserver.gis.umn.edu/mapserver", │ │ │ │ │ + components: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featurePrefix │ │ │ │ │ - * {String} Namespace alias (or prefix) for feature nodes. Default is │ │ │ │ │ - * "feature". │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - featurePrefix: "feature", │ │ │ │ │ + componentTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureName │ │ │ │ │ - * {String} Element name for features. Default is "featureMember". │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ + * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} Optional array of geometries │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - featureName: "featureMember", │ │ │ │ │ + initialize: function(components) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.components = []; │ │ │ │ │ + if (components != null) { │ │ │ │ │ + this.addComponents(components); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {String} Name of data layer. Default is "features". │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - layerName: "features", │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.components.length = 0; │ │ │ │ │ + this.components = null; │ │ │ │ │ + OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geometryName │ │ │ │ │ - * {String} Name of geometry element. Defaults to "geometry". │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clone this geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this collection │ │ │ │ │ */ │ │ │ │ │ - geometryName: "geometry", │ │ │ │ │ + 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()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: collectionName │ │ │ │ │ - * {String} Name of featureCollection element. │ │ │ │ │ - */ │ │ │ │ │ - collectionName: "FeatureCollection", │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: gmlns │ │ │ │ │ - * {String} GML Namespace. │ │ │ │ │ - */ │ │ │ │ │ - gmlns: "http://www.opengis.net/gml", │ │ │ │ │ + return geometry; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: extractAttributes │ │ │ │ │ - * {Boolean} Extract attributes from GML. │ │ │ │ │ + * Method: getComponentsString │ │ │ │ │ + * Get a string representing the components for this collection │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representation of the components of this geometry │ │ │ │ │ */ │ │ │ │ │ - extractAttributes: true, │ │ │ │ │ + getComponentsString: function() { │ │ │ │ │ + var strings = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + strings.push(this.components[i].toShortString()); │ │ │ │ │ + } │ │ │ │ │ + return strings.join(","); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: xy │ │ │ │ │ - * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ - * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds by iterating through the components and │ │ │ │ │ + * calling calling extendBounds() on each item. │ │ │ │ │ */ │ │ │ │ │ - xy: true, │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.GML │ │ │ │ │ - * Create a new parser for GML. │ │ │ │ │ + * APIMethod: addComponents │ │ │ │ │ + * Add components to this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * components - {Array()} An array of geometries to add │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - // compile regular expressions once instead of every time they are used │ │ │ │ │ - this.regExes = { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + 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: read │ │ │ │ │ - * Read data from a string, and return a list of features. │ │ │ │ │ + * 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: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * component - {} A geometry to add │ │ │ │ │ + * index - {int} Optional index into the array to insert the component │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} An array of features. │ │ │ │ │ + * {Boolean} The component geometry was successfully added │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - var featureNodes = this.getElementsByTagNameNS(data.documentElement, │ │ │ │ │ - this.gmlns, │ │ │ │ │ - this.featureName); │ │ │ │ │ - var features = []; │ │ │ │ │ - for (var i = 0; i < featureNodes.length; i++) { │ │ │ │ │ - var feature = this.parseFeature(featureNodes[i]); │ │ │ │ │ - if (feature) { │ │ │ │ │ - features.push(feature); │ │ │ │ │ + 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 features; │ │ │ │ │ + return added; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseFeature │ │ │ │ │ - * This function is the core of the GML parsing code in OpenLayers. │ │ │ │ │ - * It creates the geometries that are then attached to the returned │ │ │ │ │ - * feature, and calls parseAttributes() to get attribute data out. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: removeComponents │ │ │ │ │ + * Remove components from this geometry. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML feature node. │ │ │ │ │ + * components - {Array()} The components to be removed │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A component was removed. │ │ │ │ │ */ │ │ │ │ │ - parseFeature: function(node) { │ │ │ │ │ - // only accept one geometry per feature - look for highest "order" │ │ │ │ │ - var order = ["MultiPolygon", "Polygon", │ │ │ │ │ - "MultiLineString", "LineString", │ │ │ │ │ - "MultiPoint", "Point", "Envelope" │ │ │ │ │ - ]; │ │ │ │ │ - // FIXME: In case we parse a feature with no geometry, but boundedBy an Envelope, │ │ │ │ │ - // this code creates a geometry derived from the Envelope. This is not correct. │ │ │ │ │ - var type, nodeList, geometry, parser; │ │ │ │ │ - for (var i = 0; i < order.length; ++i) { │ │ │ │ │ - type = order[i]; │ │ │ │ │ - nodeList = this.getElementsByTagNameNS(node, this.gmlns, type); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - // only deal with first geometry of this type │ │ │ │ │ - parser = this.parseGeometry[type.toLowerCase()]; │ │ │ │ │ - if (parser) { │ │ │ │ │ - geometry = parser.apply(this, [nodeList[0]]); │ │ │ │ │ - if (this.internalProjection && this.externalProjection) { │ │ │ │ │ - geometry.transform(this.externalProjection, │ │ │ │ │ - this.internalProjection); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - throw new TypeError("Unsupported geometry type: " + type); │ │ │ │ │ - } │ │ │ │ │ - // stop looking for different geometry types │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var bounds; │ │ │ │ │ - var boxNodes = this.getElementsByTagNameNS(node, this.gmlns, "Box"); │ │ │ │ │ - for (i = 0; i < boxNodes.length; ++i) { │ │ │ │ │ - var boxNode = boxNodes[i]; │ │ │ │ │ - var box = this.parseGeometry["box"].apply(this, [boxNode]); │ │ │ │ │ - var parentNode = boxNode.parentNode; │ │ │ │ │ - var parentName = parentNode.localName || │ │ │ │ │ - parentNode.nodeName.split(":").pop(); │ │ │ │ │ - if (parentName === "boundedBy") { │ │ │ │ │ - bounds = box; │ │ │ │ │ - } else { │ │ │ │ │ - geometry = box.toGeometry(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + removeComponents: function(components) { │ │ │ │ │ + var removed = false; │ │ │ │ │ │ │ │ │ │ - // construct feature (optionally with attributes) │ │ │ │ │ - var attributes; │ │ │ │ │ - if (this.extractAttributes) { │ │ │ │ │ - attributes = this.parseAttributes(node); │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ } │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector(geometry, attributes); │ │ │ │ │ - feature.bounds = bounds; │ │ │ │ │ - │ │ │ │ │ - feature.gml = { │ │ │ │ │ - featureType: node.firstChild.nodeName.split(":")[1], │ │ │ │ │ - featureNS: node.firstChild.namespaceURI, │ │ │ │ │ - featureNSPrefix: node.firstChild.prefix │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // assign fid - this can come from a "fid" or "id" attribute │ │ │ │ │ - var childNode = node.firstChild; │ │ │ │ │ - var fid; │ │ │ │ │ - while (childNode) { │ │ │ │ │ - if (childNode.nodeType == 1) { │ │ │ │ │ - fid = childNode.getAttribute("fid") || │ │ │ │ │ - childNode.getAttribute("id"); │ │ │ │ │ - if (fid) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - childNode = childNode.nextSibling; │ │ │ │ │ + for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ + removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ } │ │ │ │ │ - feature.fid = fid; │ │ │ │ │ - return feature; │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: parseGeometry │ │ │ │ │ - * Properties of this object are the functions that parse geometries based │ │ │ │ │ - * on their type. │ │ │ │ │ + * Method: removeComponent │ │ │ │ │ + * Remove a component from this geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * component - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - parseGeometry: { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.point │ │ │ │ │ - * Given a GML node representing a point geometry, create an OpenLayers │ │ │ │ │ - * point geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A point geometry. │ │ │ │ │ - */ │ │ │ │ │ - point: function(node) { │ │ │ │ │ - /** │ │ │ │ │ - * Three coordinate variations to consider: │ │ │ │ │ - * 1) x y z │ │ │ │ │ - * 2) x, y, z │ │ │ │ │ - * 3) xy │ │ │ │ │ - */ │ │ │ │ │ - var nodeList, coordString; │ │ │ │ │ - var coords = []; │ │ │ │ │ - │ │ │ │ │ - // look for │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, "pos"); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ - coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // look for │ │ │ │ │ - if (coords.length == 0) { │ │ │ │ │ - nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "coordinates"); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ - coordString = coordString.replace(this.regExes.removeSpace, │ │ │ │ │ - ""); │ │ │ │ │ - coords = coordString.split(","); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // look for │ │ │ │ │ - if (coords.length == 0) { │ │ │ │ │ - nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "coord"); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - var xList = this.getElementsByTagNameNS(nodeList[0], │ │ │ │ │ - this.gmlns, "X"); │ │ │ │ │ - var yList = this.getElementsByTagNameNS(nodeList[0], │ │ │ │ │ - this.gmlns, "Y"); │ │ │ │ │ - if (xList.length > 0 && yList.length > 0) { │ │ │ │ │ - coords = [xList[0].firstChild.nodeValue, │ │ │ │ │ - yList[0].firstChild.nodeValue │ │ │ │ │ - ]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // preserve third dimension │ │ │ │ │ - if (coords.length == 2) { │ │ │ │ │ - coords[2] = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - return new OpenLayers.Geometry.Point(coords[0], coords[1], │ │ │ │ │ - coords[2]); │ │ │ │ │ - } else { │ │ │ │ │ - return new OpenLayers.Geometry.Point(coords[1], coords[0], │ │ │ │ │ - coords[2]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + removeComponent: function(component) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.multipoint │ │ │ │ │ - * Given a GML node representing a multipoint geometry, create an │ │ │ │ │ - * OpenLayers multipoint geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A multipoint geometry. │ │ │ │ │ - */ │ │ │ │ │ - multipoint: function(node) { │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "Point"); │ │ │ │ │ - var components = []; │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - var point; │ │ │ │ │ - for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ - point = this.parseGeometry.point.apply(this, [nodeList[i]]); │ │ │ │ │ - if (point) { │ │ │ │ │ - components.push(point); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.MultiPoint(components); │ │ │ │ │ - }, │ │ │ │ │ + OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.linestring │ │ │ │ │ - * Given a GML node representing a linestring geometry, create an │ │ │ │ │ - * OpenLayers linestring geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A linestring geometry. │ │ │ │ │ - */ │ │ │ │ │ - linestring: function(node, ring) { │ │ │ │ │ - /** │ │ │ │ │ - * Two coordinate variations to consider: │ │ │ │ │ - * 1) x0 y0 z0 x1 y1 z1 │ │ │ │ │ - * 2) x0, y0, z0 x1, y1, z1 │ │ │ │ │ - */ │ │ │ │ │ - var nodeList, coordString; │ │ │ │ │ - var coords = []; │ │ │ │ │ - var points = []; │ │ │ │ │ + // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ + // to this.getBounds(); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // look for │ │ │ │ │ - nodeList = this.getElementsByTagNameNS(node, this.gmlns, "posList"); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - coordString = this.getChildValue(nodeList[0]); │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ - coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ - var dim = parseInt(nodeList[0].getAttribute("dimension")); │ │ │ │ │ - var j, x, y, z; │ │ │ │ │ - for (var i = 0; i < coords.length / dim; ++i) { │ │ │ │ │ - j = i * dim; │ │ │ │ │ - x = coords[j]; │ │ │ │ │ - y = coords[j + 1]; │ │ │ │ │ - z = (dim == 2) ? null : coords[j + 2]; │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - points.push(new OpenLayers.Geometry.Point(x, y, z)); │ │ │ │ │ - } else { │ │ │ │ │ - points.push(new OpenLayers.Geometry.Point(y, x, z)); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // look for │ │ │ │ │ - if (coords.length == 0) { │ │ │ │ │ - nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "coordinates"); │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - coordString = this.getChildValue(nodeList[0]); │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimSpace, │ │ │ │ │ - ""); │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimComma, │ │ │ │ │ - ","); │ │ │ │ │ - var pointList = coordString.split(this.regExes.splitSpace); │ │ │ │ │ - for (var i = 0; i < pointList.length; ++i) { │ │ │ │ │ - coords = pointList[i].split(","); │ │ │ │ │ - if (coords.length == 2) { │ │ │ │ │ - coords[2] = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - points.push(new OpenLayers.Geometry.Point(coords[0], │ │ │ │ │ - coords[1], │ │ │ │ │ - coords[2])); │ │ │ │ │ - } else { │ │ │ │ │ - points.push(new OpenLayers.Geometry.Point(coords[1], │ │ │ │ │ - coords[0], │ │ │ │ │ - coords[2])); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var line = null; │ │ │ │ │ - if (points.length != 0) { │ │ │ │ │ - if (ring) { │ │ │ │ │ - line = new OpenLayers.Geometry.LinearRing(points); │ │ │ │ │ - } else { │ │ │ │ │ - line = new OpenLayers.Geometry.LineString(points); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return line; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.multilinestring │ │ │ │ │ - * Given a GML node representing a multilinestring geometry, create an │ │ │ │ │ - * OpenLayers multilinestring geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A multilinestring geometry. │ │ │ │ │ - */ │ │ │ │ │ - multilinestring: function(node) { │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "LineString"); │ │ │ │ │ - var components = []; │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - var line; │ │ │ │ │ - for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ - line = this.parseGeometry.linestring.apply(this, │ │ │ │ │ - [nodeList[i]]); │ │ │ │ │ - if (line) { │ │ │ │ │ - components.push(line); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.MultiLineString(components); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.polygon │ │ │ │ │ - * Given a GML node representing a polygon geometry, create an │ │ │ │ │ - * OpenLayers polygon geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A polygon geometry. │ │ │ │ │ - */ │ │ │ │ │ - polygon: function(node) { │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "LinearRing"); │ │ │ │ │ - var components = []; │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - // this assumes exterior ring first, inner rings after │ │ │ │ │ - var ring; │ │ │ │ │ - for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ - ring = this.parseGeometry.linestring.apply(this, │ │ │ │ │ - [nodeList[i], true]); │ │ │ │ │ - if (ring) { │ │ │ │ │ - components.push(ring); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Geometry.Polygon(components); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.multipolygon │ │ │ │ │ - * Given a GML node representing a multipolygon geometry, create an │ │ │ │ │ - * OpenLayers multipolygon geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A multipolygon geometry. │ │ │ │ │ - */ │ │ │ │ │ - multipolygon: function(node) { │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "Polygon"); │ │ │ │ │ - var components = []; │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - var polygon; │ │ │ │ │ - for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ - polygon = this.parseGeometry.polygon.apply(this, │ │ │ │ │ - [nodeList[i]]); │ │ │ │ │ - if (polygon) { │ │ │ │ │ - components.push(polygon); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Geometry.MultiPolygon(components); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - envelope: function(node) { │ │ │ │ │ - var components = []; │ │ │ │ │ - var coordString; │ │ │ │ │ - var envelope; │ │ │ │ │ - │ │ │ │ │ - var lpoint = this.getElementsByTagNameNS(node, this.gmlns, "lowerCorner"); │ │ │ │ │ - if (lpoint.length > 0) { │ │ │ │ │ - var coords = []; │ │ │ │ │ - │ │ │ │ │ - if (lpoint.length > 0) { │ │ │ │ │ - coordString = lpoint[0].firstChild.nodeValue; │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ - coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (coords.length == 2) { │ │ │ │ │ - coords[2] = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - var lowerPoint = new OpenLayers.Geometry.Point(coords[0], coords[1], coords[2]); │ │ │ │ │ - } else { │ │ │ │ │ - var lowerPoint = new OpenLayers.Geometry.Point(coords[1], coords[0], coords[2]); │ │ │ │ │ - } │ │ │ │ │ + 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 upoint = this.getElementsByTagNameNS(node, this.gmlns, "upperCorner"); │ │ │ │ │ - if (upoint.length > 0) { │ │ │ │ │ - var coords = []; │ │ │ │ │ - │ │ │ │ │ - if (upoint.length > 0) { │ │ │ │ │ - coordString = upoint[0].firstChild.nodeValue; │ │ │ │ │ - coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ - coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (coords.length == 2) { │ │ │ │ │ - coords[2] = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - var upperPoint = new OpenLayers.Geometry.Point(coords[0], coords[1], coords[2]); │ │ │ │ │ - } else { │ │ │ │ │ - var upperPoint = new OpenLayers.Geometry.Point(coords[1], coords[0], coords[2]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (lowerPoint && upperPoint) { │ │ │ │ │ - components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y)); │ │ │ │ │ - components.push(new OpenLayers.Geometry.Point(upperPoint.x, lowerPoint.y)); │ │ │ │ │ - components.push(new OpenLayers.Geometry.Point(upperPoint.x, upperPoint.y)); │ │ │ │ │ - components.push(new OpenLayers.Geometry.Point(lowerPoint.x, upperPoint.y)); │ │ │ │ │ - components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y)); │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var ring = new OpenLayers.Geometry.LinearRing(components); │ │ │ │ │ - envelope = new OpenLayers.Geometry.Polygon([ring]); │ │ │ │ │ - } │ │ │ │ │ - return envelope; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseGeometry.box │ │ │ │ │ - * Given a GML node representing a box geometry, create an │ │ │ │ │ - * OpenLayers.Bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} A GML node. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A bounds representing the box. │ │ │ │ │ - */ │ │ │ │ │ - box: function(node) { │ │ │ │ │ - var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ - "coordinates"); │ │ │ │ │ - var coordString; │ │ │ │ │ - var coords, beginPoint = null, │ │ │ │ │ - endPoint = null; │ │ │ │ │ - if (nodeList.length > 0) { │ │ │ │ │ - coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ - coords = coordString.split(" "); │ │ │ │ │ - if (coords.length == 2) { │ │ │ │ │ - beginPoint = coords[0].split(","); │ │ │ │ │ - endPoint = coords[1].split(","); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (beginPoint !== null && endPoint !== null) { │ │ │ │ │ - return new OpenLayers.Bounds(parseFloat(beginPoint[0]), │ │ │ │ │ - parseFloat(beginPoint[1]), │ │ │ │ │ - parseFloat(endPoint[0]), │ │ │ │ │ - parseFloat(endPoint[1])); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseAttributes │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {DOMElement} │ │ │ │ │ + * 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: │ │ │ │ │ - * {Object} An attributes object. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - parseAttributes: function(node) { │ │ │ │ │ - var attributes = {}; │ │ │ │ │ - // assume attributes are children of the first type 1 child │ │ │ │ │ - var childNode = node.firstChild; │ │ │ │ │ - var children, i, child, grandchildren, grandchild, name, value; │ │ │ │ │ - while (childNode) { │ │ │ │ │ - if (childNode.nodeType == 1) { │ │ │ │ │ - // attributes are type 1 children with one type 3 child │ │ │ │ │ - children = childNode.childNodes; │ │ │ │ │ - for (i = 0; i < children.length; ++i) { │ │ │ │ │ - child = children[i]; │ │ │ │ │ - if (child.nodeType == 1) { │ │ │ │ │ - grandchildren = child.childNodes; │ │ │ │ │ - if (grandchildren.length == 1) { │ │ │ │ │ - grandchild = grandchildren[0]; │ │ │ │ │ - if (grandchild.nodeType == 3 || │ │ │ │ │ - grandchild.nodeType == 4) { │ │ │ │ │ - name = (child.prefix) ? │ │ │ │ │ - child.nodeName.split(":")[1] : │ │ │ │ │ - child.nodeName; │ │ │ │ │ - value = grandchild.nodeValue.replace( │ │ │ │ │ - this.regExes.trimSpace, ""); │ │ │ │ │ - attributes[name] = value; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // If child has no childNodes (grandchildren), │ │ │ │ │ - // set an attribute with null value. │ │ │ │ │ - // e.g. becomes │ │ │ │ │ - // {fieldname: null} │ │ │ │ │ - attributes[child.nodeName.split(":").pop()] = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - break; │ │ │ │ │ } │ │ │ │ │ - childNode = childNode.nextSibling; │ │ │ │ │ } │ │ │ │ │ - return attributes; │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Generate a GML document string given a list of features. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} List of features to │ │ │ │ │ - * serialize into a string. │ │ │ │ │ + * geometry - {} The geometry to test. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string representing the GML document. │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - write: function(features) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var gml = this.createElementNS("http://www.opengis.net/wfs", │ │ │ │ │ - "wfs:" + this.collectionName); │ │ │ │ │ - for (var i = 0; i < features.length; i++) { │ │ │ │ │ - gml.appendChild(this.createFeatureXML(features[i])); │ │ │ │ │ + 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 OpenLayers.Format.XML.prototype.write.apply(this, [gml]); │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: createFeatureXML │ │ │ │ │ - * Accept an OpenLayers.Feature.Vector, and build a GML node for it. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} The feature to be built as GML. │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A node reprensting the feature in GML. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - createFeatureXML: function(feature) { │ │ │ │ │ - var geometry = feature.geometry; │ │ │ │ │ - var geometryNode = this.buildGeometryNode(geometry); │ │ │ │ │ - var geomContainer = this.createElementNS(this.featureNS, │ │ │ │ │ - this.featurePrefix + ":" + │ │ │ │ │ - this.geometryName); │ │ │ │ │ - geomContainer.appendChild(geometryNode); │ │ │ │ │ - var featureNode = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:" + this.featureName); │ │ │ │ │ - var featureContainer = this.createElementNS(this.featureNS, │ │ │ │ │ - this.featurePrefix + ":" + │ │ │ │ │ - this.layerName); │ │ │ │ │ - var fid = feature.fid || feature.id; │ │ │ │ │ - featureContainer.setAttribute("fid", fid); │ │ │ │ │ - featureContainer.appendChild(geomContainer); │ │ │ │ │ - for (var attr in feature.attributes) { │ │ │ │ │ - var attrText = this.createTextNode(feature.attributes[attr]); │ │ │ │ │ - var nodename = attr.substring(attr.lastIndexOf(":") + 1); │ │ │ │ │ - var attrContainer = this.createElementNS(this.featureNS, │ │ │ │ │ - this.featurePrefix + ":" + │ │ │ │ │ - nodename); │ │ │ │ │ - attrContainer.appendChild(attrText); │ │ │ │ │ - featureContainer.appendChild(attrContainer); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - featureNode.appendChild(featureContainer); │ │ │ │ │ - return featureNode; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: buildGeometryNode │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - buildGeometryNode: function(geometry) { │ │ │ │ │ - if (this.externalProjection && this.internalProjection) { │ │ │ │ │ - geometry = geometry.clone(); │ │ │ │ │ - geometry.transform(this.internalProjection, │ │ │ │ │ - this.externalProjection); │ │ │ │ │ + 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) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - var className = geometry.CLASS_NAME; │ │ │ │ │ - var type = className.substring(className.lastIndexOf(".") + 1); │ │ │ │ │ - var builder = this.buildGeometry[type.toLowerCase()]; │ │ │ │ │ - return builder.apply(this, [geometry]); │ │ │ │ │ + return vertices; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: buildGeometry │ │ │ │ │ - * Object containing methods to do the actual geometry node building │ │ │ │ │ - * based on geometry type. │ │ │ │ │ - */ │ │ │ │ │ - buildGeometry: { │ │ │ │ │ - // TBD retrieve the srs from layer │ │ │ │ │ - // srsName is non-standard, so not including it until it's right. │ │ │ │ │ - // gml.setAttribute("srsName", │ │ │ │ │ - // "http://www.opengis.net/gml/srs/epsg.xml#4326"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: buildGeometry.point │ │ │ │ │ - * Given an OpenLayers point geometry, create a GML point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A point geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML point node. │ │ │ │ │ - */ │ │ │ │ │ - point: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:Point"); │ │ │ │ │ - gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: buildGeometry.multipoint │ │ │ │ │ - * Given an OpenLayers multipoint geometry, create a GML multipoint. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A multipoint geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML multipoint node. │ │ │ │ │ - */ │ │ │ │ │ - multipoint: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:MultiPoint"); │ │ │ │ │ - var points = geometry.components; │ │ │ │ │ - var pointMember, pointGeom; │ │ │ │ │ - for (var i = 0; i < points.length; i++) { │ │ │ │ │ - pointMember = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:pointMember"); │ │ │ │ │ - pointGeom = this.buildGeometry.point.apply(this, │ │ │ │ │ - [points[i]]); │ │ │ │ │ - pointMember.appendChild(pointGeom); │ │ │ │ │ - gml.appendChild(pointMember); │ │ │ │ │ - } │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ +/* 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: buildGeometry.linestring │ │ │ │ │ - * Given an OpenLayers linestring geometry, create a GML linestring. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A linestring geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML linestring node. │ │ │ │ │ - */ │ │ │ │ │ - linestring: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:LineString"); │ │ │ │ │ - gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: buildGeometry.multilinestring │ │ │ │ │ - * Given an OpenLayers multilinestring geometry, create a GML │ │ │ │ │ - * multilinestring. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A multilinestring │ │ │ │ │ - * geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML multilinestring node. │ │ │ │ │ - */ │ │ │ │ │ - multilinestring: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:MultiLineString"); │ │ │ │ │ - var lines = geometry.components; │ │ │ │ │ - var lineMember, lineGeom; │ │ │ │ │ - for (var i = 0; i < lines.length; ++i) { │ │ │ │ │ - lineMember = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:lineStringMember"); │ │ │ │ │ - lineGeom = this.buildGeometry.linestring.apply(this, │ │ │ │ │ - [lines[i]]); │ │ │ │ │ - lineMember.appendChild(lineGeom); │ │ │ │ │ - gml.appendChild(lineMember); │ │ │ │ │ - } │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * 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, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildGeometry.linearring │ │ │ │ │ - * Given an OpenLayers linearring geometry, create a GML linearring. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A linearring geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML linearring node. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - linearring: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:LinearRing"); │ │ │ │ │ - gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildGeometry.polygon │ │ │ │ │ - * Given an OpenLayers polygon geometry, create a GML polygon. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * Create a new MultiPoint Geometry │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} A polygon geometry. │ │ │ │ │ + * components - {Array()} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A GML polygon node. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - polygon: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:Polygon"); │ │ │ │ │ - var rings = geometry.components; │ │ │ │ │ - var ringMember, ringGeom, type; │ │ │ │ │ - for (var i = 0; i < rings.length; ++i) { │ │ │ │ │ - type = (i == 0) ? "outerBoundaryIs" : "innerBoundaryIs"; │ │ │ │ │ - ringMember = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:" + type); │ │ │ │ │ - ringGeom = this.buildGeometry.linearring.apply(this, │ │ │ │ │ - [rings[i]]); │ │ │ │ │ - ringMember.appendChild(ringGeom); │ │ │ │ │ - gml.appendChild(ringMember); │ │ │ │ │ - } │ │ │ │ │ - return gml; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildGeometry.multipolygon │ │ │ │ │ - * Given an OpenLayers multipolygon geometry, create a GML multipolygon. │ │ │ │ │ + * APIMethod: addPoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} A multipolygon │ │ │ │ │ - * geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML multipolygon node. │ │ │ │ │ + * point - {} Point to be added │ │ │ │ │ + * index - {Integer} Optional index │ │ │ │ │ */ │ │ │ │ │ - multipolygon: function(geometry) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:MultiPolygon"); │ │ │ │ │ - var polys = geometry.components; │ │ │ │ │ - var polyMember, polyGeom; │ │ │ │ │ - for (var i = 0; i < polys.length; ++i) { │ │ │ │ │ - polyMember = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:polygonMember"); │ │ │ │ │ - polyGeom = this.buildGeometry.polygon.apply(this, │ │ │ │ │ - [polys[i]]); │ │ │ │ │ - polyMember.appendChild(polyGeom); │ │ │ │ │ - gml.appendChild(polyMember); │ │ │ │ │ - } │ │ │ │ │ - return gml; │ │ │ │ │ - │ │ │ │ │ + addPoint: function(point, index) { │ │ │ │ │ + this.addComponent(point, index); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildGeometry.bounds │ │ │ │ │ - * Given an OpenLayers bounds, create a GML box. │ │ │ │ │ + * APIMethod: removePoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A GML box node. │ │ │ │ │ + * point - {} Point to be removed │ │ │ │ │ */ │ │ │ │ │ - bounds: function(bounds) { │ │ │ │ │ - var gml = this.createElementNS(this.gmlns, "gml:Box"); │ │ │ │ │ - gml.appendChild(this.buildCoordinatesNode(bounds)); │ │ │ │ │ - return gml; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: buildCoordinates │ │ │ │ │ - * builds the coordinates XmlNode │ │ │ │ │ - * (code) │ │ │ │ │ - * ... │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {XmlNode} created xmlNode │ │ │ │ │ - */ │ │ │ │ │ - buildCoordinatesNode: function(geometry) { │ │ │ │ │ - var coordinatesNode = this.createElementNS(this.gmlns, │ │ │ │ │ - "gml:coordinates"); │ │ │ │ │ - coordinatesNode.setAttribute("decimal", "."); │ │ │ │ │ - coordinatesNode.setAttribute("cs", ","); │ │ │ │ │ - coordinatesNode.setAttribute("ts", " "); │ │ │ │ │ - │ │ │ │ │ - var parts = []; │ │ │ │ │ - │ │ │ │ │ - if (geometry instanceof OpenLayers.Bounds) { │ │ │ │ │ - parts.push(geometry.left + "," + geometry.bottom); │ │ │ │ │ - parts.push(geometry.right + "," + geometry.top); │ │ │ │ │ - } else { │ │ │ │ │ - var points = (geometry.components) ? geometry.components : [geometry]; │ │ │ │ │ - for (var i = 0; i < points.length; i++) { │ │ │ │ │ - parts.push(points[i].x + "," + points[i].y); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var txtNode = this.createTextNode(parts.join(" ")); │ │ │ │ │ - coordinatesNode.appendChild(txtNode); │ │ │ │ │ - │ │ │ │ │ - return coordinatesNode; │ │ │ │ │ - }, │ │ │ │ │ + removePoint: function(point) { │ │ │ │ │ + this.removeComponent(point); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.GML" │ │ │ │ │ -}); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ + }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/GML/Base.js │ │ │ │ │ + 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/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Format/GML.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Though required in the full build, if the GML format is excluded, we set │ │ │ │ │ - * the namespace here. │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ */ │ │ │ │ │ -if (!OpenLayers.Format.GML) { │ │ │ │ │ - OpenLayers.Format.GML = {}; │ │ │ │ │ -} │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.GML.Base │ │ │ │ │ - * Superclass for GML parsers. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - gml: "http://www.opengis.net/gml", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance", │ │ │ │ │ - wfs: "http://www.opengis.net/wfs" // this is a convenience for reading wfs:FeatureCollection │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - */ │ │ │ │ │ - defaultPrefix: "gml", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. │ │ │ │ │ - */ │ │ │ │ │ - schemaLocation: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: featureType │ │ │ │ │ - * {Array(String) or String} The local (without prefix) feature typeName(s). │ │ │ │ │ - */ │ │ │ │ │ - featureType: null, │ │ │ │ │ +OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureNS │ │ │ │ │ - * {String} The feature namespace. Must be set in the options at │ │ │ │ │ - * construction. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - featureNS: null, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geometry │ │ │ │ │ - * {String} Name of geometry element. Defaults to "geometry". If null, it │ │ │ │ │ - * will be set on when the first geometry is parsed. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {Array()} │ │ │ │ │ */ │ │ │ │ │ - geometryName: "geometry", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: extractAttributes │ │ │ │ │ - * {Boolean} Extract attributes from GML. Default is true. │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The length of the curve │ │ │ │ │ */ │ │ │ │ │ - extractAttributes: true, │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: srsName │ │ │ │ │ - * {String} URI for spatial reference system. This is optional for │ │ │ │ │ - * single part geometries and mandatory for collections and multis. │ │ │ │ │ - * If set, the srsName attribute will be written for all geometries. │ │ │ │ │ - * Default is null. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - srsName: null, │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: xy │ │ │ │ │ - * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ - * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ - */ │ │ │ │ │ - xy: true, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/LineString.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: geometryTypes │ │ │ │ │ - * {Object} Maps OpenLayers geometry class names to GML element names. │ │ │ │ │ - * Use before accessing this property. │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: 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: singleFeatureType │ │ │ │ │ - * {Boolean} True if there is only 1 featureType, and not an array │ │ │ │ │ - * of featuretypes. │ │ │ │ │ - */ │ │ │ │ │ - singleFeatureType: null, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: autoConfig │ │ │ │ │ - * {Boolean} Indicates if the format was configured without a , │ │ │ │ │ - * but auto-configured and during read. │ │ │ │ │ - * Subclasses making use of auto-configuration should make │ │ │ │ │ - * the first call to the method (usually in the read method) │ │ │ │ │ - * with true as 3rd argument, so the auto-configured featureType can be │ │ │ │ │ - * reset and the format can be reused for subsequent reads with data from │ │ │ │ │ - * different featureTypes. Set to false after read if you want to keep the │ │ │ │ │ - * auto-configured values. │ │ │ │ │ - */ │ │ │ │ │ +/** │ │ │ │ │ + * 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, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ + * Create a new LineString geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * points - {Array()} An array of points used to │ │ │ │ │ + * generate the linestring │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g), │ │ │ │ │ - featureMember: (/^(.*:)?featureMembers?$/) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.GML.Base │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * or constructor │ │ │ │ │ - * instead. │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} The point to be removed │ │ │ │ │ * │ │ │ │ │ - * Valid options properties: │ │ │ │ │ - * featureType - {Array(String) or String} Local (without prefix) feature │ │ │ │ │ - * typeName(s) (required for write). │ │ │ │ │ - * featureNS - {String} Feature namespace (required for write). │ │ │ │ │ - * geometryName - {String} Geometry element name (required for write). │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.setGeometryTypes(); │ │ │ │ │ - if (options && options.featureNS) { │ │ │ │ │ - this.setNamespace("feature", options.featureNS); │ │ │ │ │ + removeComponent: function(point) { │ │ │ │ │ + var removed = this.components && (this.components.length > 2); │ │ │ │ │ + if (removed) { │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ } │ │ │ │ │ - this.singleFeatureType = !options || (typeof options.featureType === "string"); │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ + * 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: │ │ │ │ │ - * data - {DOMElement} A gml:featureMember element, a gml:featureMembers │ │ │ │ │ - * element, or an element containing either of the above at any level. │ │ │ │ │ + * geometry - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} An array of features. │ │ │ │ │ + * {Boolean} The input geometry intersects this geometry. │ │ │ │ │ */ │ │ │ │ │ - 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 features = []; │ │ │ │ │ - this.readNode(data, { │ │ │ │ │ - features: features │ │ │ │ │ - }, true); │ │ │ │ │ - if (features.length == 0) { │ │ │ │ │ - // look for gml:featureMember elements │ │ │ │ │ - var elements = this.getElementsByTagNameNS( │ │ │ │ │ - data, this.namespaces.gml, "featureMember" │ │ │ │ │ - ); │ │ │ │ │ - if (elements.length) { │ │ │ │ │ - for (var i = 0, len = elements.length; i < len; ++i) { │ │ │ │ │ - this.readNode(elements[i], { │ │ │ │ │ - features: features │ │ │ │ │ - }, true); │ │ │ │ │ - } │ │ │ │ │ + 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 { │ │ │ │ │ - // look for gml:featureMembers elements (this is v3, but does no harm here) │ │ │ │ │ - var elements = this.getElementsByTagNameNS( │ │ │ │ │ - data, this.namespaces.gml, "featureMembers" │ │ │ │ │ - ); │ │ │ │ │ - if (elements.length) { │ │ │ │ │ - // there can be only one │ │ │ │ │ - this.readNode(elements[0], { │ │ │ │ │ - features: features │ │ │ │ │ - }, true); │ │ │ │ │ + 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 features; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: readNode │ │ │ │ │ - * Shorthand for applying one of the named readers given the node │ │ │ │ │ - * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ - * generally extend or modify the second. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} The node to be read (required). │ │ │ │ │ - * obj - {Object} The object to be modified (optional). │ │ │ │ │ - * first - {Boolean} Should be set to true for the first node read. This │ │ │ │ │ - * is usually the readNode call in the read method. Without this being │ │ │ │ │ - * set, auto-configured properties will stick on subsequent reads. │ │ │ │ │ + * Method: getSortedSegments │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - readNode: function(node, obj, first) { │ │ │ │ │ - // on subsequent calls of format.read(), we want to reset auto- │ │ │ │ │ - // configured properties and auto-configure again. │ │ │ │ │ - if (first === true && this.autoConfig === true) { │ │ │ │ │ - this.featureType = null; │ │ │ │ │ - delete this.namespaceAlias[this.featureNS]; │ │ │ │ │ - delete this.namespaces["feature"]; │ │ │ │ │ - this.featureNS = null; │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - // featureType auto-configuration │ │ │ │ │ - if (!this.featureNS && (!(node.prefix in this.namespaces) && │ │ │ │ │ - node.parentNode.namespaceURI == this.namespaces["gml"] && │ │ │ │ │ - this.regExes.featureMember.test(node.parentNode.nodeName))) { │ │ │ │ │ - this.featureType = node.nodeName.split(":").pop(); │ │ │ │ │ - this.setNamespace("feature", node.namespaceURI); │ │ │ │ │ - this.featureNS = node.namespaceURI; │ │ │ │ │ - this.autoConfig = true; │ │ │ │ │ + // more efficient to define this somewhere static │ │ │ │ │ + function byX1(seg1, seg2) { │ │ │ │ │ + return seg1.x1 - seg2.x1; │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Format.XML.prototype.readNode.apply(this, [node, obj]); │ │ │ │ │ + return segments.sort(byX1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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). │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "gml": { │ │ │ │ │ - "_inherit": function(node, obj, container) { │ │ │ │ │ - // To be implemented by version specific parsers │ │ │ │ │ - }, │ │ │ │ │ - "featureMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "featureMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "name": function(node, obj) { │ │ │ │ │ - obj.name = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "boundedBy": function(node, obj) { │ │ │ │ │ - var container = {}; │ │ │ │ │ - this.readChildNodes(node, container); │ │ │ │ │ - if (container.components && container.components.length > 0) { │ │ │ │ │ - obj.bounds = container.components[0]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Point": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - points: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ - } │ │ │ │ │ - container.components.push(obj.points[0]); │ │ │ │ │ - }, │ │ │ │ │ - "coordinates": function(node, obj) { │ │ │ │ │ - var str = this.getChildValue(node).replace( │ │ │ │ │ - this.regExes.trimSpace, "" │ │ │ │ │ - ); │ │ │ │ │ - str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ - var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ - var coords; │ │ │ │ │ - var numPoints = pointList.length; │ │ │ │ │ - var points = new Array(numPoints); │ │ │ │ │ - for (var i = 0; i < numPoints; ++i) { │ │ │ │ │ - coords = pointList[i].split(","); │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - points[i] = new OpenLayers.Geometry.Point( │ │ │ │ │ - coords[0], coords[1], coords[2] │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - points[i] = new OpenLayers.Geometry.Point( │ │ │ │ │ - coords[1], coords[0], coords[2] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - obj.points = points; │ │ │ │ │ - }, │ │ │ │ │ - "coord": function(node, obj) { │ │ │ │ │ - var coord = {}; │ │ │ │ │ - this.readChildNodes(node, coord); │ │ │ │ │ - if (!obj.points) { │ │ │ │ │ - obj.points = []; │ │ │ │ │ - } │ │ │ │ │ - obj.points.push(new OpenLayers.Geometry.Point( │ │ │ │ │ - coord.x, coord.y, coord.z │ │ │ │ │ - )); │ │ │ │ │ - }, │ │ │ │ │ - "X": function(node, coord) { │ │ │ │ │ - coord.x = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Y": function(node, coord) { │ │ │ │ │ - coord.y = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Z": function(node, coord) { │ │ │ │ │ - coord.z = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "MultiPoint": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiPoint(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ - }, │ │ │ │ │ - "pointMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "LineString": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ - } │ │ │ │ │ - container.components.push( │ │ │ │ │ - new OpenLayers.Geometry.LineString(obj.points) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "MultiLineString": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ - }, │ │ │ │ │ - "lineStringMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "Polygon": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - outer: null, │ │ │ │ │ - inner: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - obj.inner.unshift(obj.outer); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - container.components.push( │ │ │ │ │ - new OpenLayers.Geometry.Polygon(obj.inner) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "LinearRing": function(node, obj) { │ │ │ │ │ - var container = {}; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, container]); │ │ │ │ │ - this.readChildNodes(node, container); │ │ │ │ │ - obj.components = [new OpenLayers.Geometry.LinearRing( │ │ │ │ │ - container.points │ │ │ │ │ - )]; │ │ │ │ │ - }, │ │ │ │ │ - "MultiPolygon": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiPolygon(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ - }, │ │ │ │ │ - "polygonMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "GeometryCollection": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.Collection(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ - }, │ │ │ │ │ - "geometryMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "feature": { │ │ │ │ │ - "*": function(node, obj) { │ │ │ │ │ - // The node can either be named like the featureType, or it │ │ │ │ │ - // can be a child of the feature:featureType. Children can be │ │ │ │ │ - // geometry or attributes. │ │ │ │ │ - var name; │ │ │ │ │ - var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ - // Since an attribute can have the same name as the feature type │ │ │ │ │ - // we only want to read the node as a feature if the parent │ │ │ │ │ - // node can have feature nodes as children. In this case, the │ │ │ │ │ - // obj.features property is set. │ │ │ │ │ - if (obj.features) { │ │ │ │ │ - if (!this.singleFeatureType && │ │ │ │ │ - (OpenLayers.Util.indexOf(this.featureType, local) !== -1)) { │ │ │ │ │ - name = "_typeName"; │ │ │ │ │ - } else if (local === this.featureType) { │ │ │ │ │ - name = "_typeName"; │ │ │ │ │ + if (vertex || edge) { │ │ │ │ │ + // push intersections different than the previous │ │ │ │ │ + if (!point.equals(intersections[intersections.length - 1])) { │ │ │ │ │ + intersections.push(point.clone()); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - // Assume attribute elements have one child node and that the child │ │ │ │ │ - // is a text node. Otherwise assume it is a geometry node. │ │ │ │ │ - if (node.childNodes.length == 0 || │ │ │ │ │ - (node.childNodes.length == 1 && node.firstChild.nodeType == 3)) { │ │ │ │ │ - if (this.extractAttributes) { │ │ │ │ │ - name = "_attribute"; │ │ │ │ │ + if (i === 0) { │ │ │ │ │ + if (point.equals(vert1)) { │ │ │ │ │ + continue; │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - name = "_geometry"; │ │ │ │ │ } │ │ │ │ │ + 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 (name) { │ │ │ │ │ - this.readers.feature[name].apply(this, [node, obj]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "_typeName": function(node, obj) { │ │ │ │ │ - var container = { │ │ │ │ │ - components: [], │ │ │ │ │ - attributes: {} │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, container); │ │ │ │ │ - // look for common gml namespaced elements │ │ │ │ │ - if (container.name) { │ │ │ │ │ - container.attributes.name = container.name; │ │ │ │ │ - } │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector( │ │ │ │ │ - container.components[0], container.attributes │ │ │ │ │ - ); │ │ │ │ │ - if (!this.singleFeatureType) { │ │ │ │ │ - feature.type = node.nodeName.split(":").pop(); │ │ │ │ │ - feature.namespace = node.namespaceURI; │ │ │ │ │ - } │ │ │ │ │ - var fid = node.getAttribute("fid") || │ │ │ │ │ - this.getAttributeNS(node, this.namespaces["gml"], "id"); │ │ │ │ │ - if (fid) { │ │ │ │ │ - feature.fid = fid; │ │ │ │ │ - } │ │ │ │ │ - if (this.internalProjection && this.externalProjection && │ │ │ │ │ - feature.geometry) { │ │ │ │ │ - feature.geometry.transform( │ │ │ │ │ - this.externalProjection, this.internalProjection │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (container.bounds) { │ │ │ │ │ - feature.bounds = container.bounds; │ │ │ │ │ - } │ │ │ │ │ - obj.features.push(feature); │ │ │ │ │ - }, │ │ │ │ │ - "_geometry": function(node, obj) { │ │ │ │ │ - if (!this.geometryName) { │ │ │ │ │ - this.geometryName = node.nodeName.split(":").pop(); │ │ │ │ │ - } │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "_attribute": function(node, obj) { │ │ │ │ │ - var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ - var value = this.getChildValue(node); │ │ │ │ │ - obj.attributes[local] = value; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "wfs": { │ │ │ │ │ - "FeatureCollection": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + 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: write │ │ │ │ │ - * │ │ │ │ │ + * Method: split │ │ │ │ │ + * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ - * An array of features or a single feature. │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ - * element will be returned. Given a single feature, a doc with a │ │ │ │ │ - * gml:featureMember element will be returned. │ │ │ │ │ - */ │ │ │ │ │ - write: function(features) { │ │ │ │ │ - var name; │ │ │ │ │ - if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ - name = "featureMembers"; │ │ │ │ │ - } else { │ │ │ │ │ - name = "featureMember"; │ │ │ │ │ - } │ │ │ │ │ - var root = this.writeNode("gml:" + name, features); │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - root, this.namespaces["xsi"], │ │ │ │ │ - "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "gml": { │ │ │ │ │ - "featureMember": function(feature) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:featureMember"); │ │ │ │ │ - this.writeNode("feature:_typeName", feature, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MultiPoint": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:MultiPoint"); │ │ │ │ │ - var components = geometry.components || [geometry]; │ │ │ │ │ - for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ - this.writeNode("pointMember", components[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "pointMember": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:pointMember"); │ │ │ │ │ - this.writeNode("Point", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MultiLineString": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:MultiLineString"); │ │ │ │ │ - var components = geometry.components || [geometry]; │ │ │ │ │ - for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ - this.writeNode("lineStringMember", components[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "lineStringMember": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:lineStringMember"); │ │ │ │ │ - this.writeNode("LineString", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MultiPolygon": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:MultiPolygon"); │ │ │ │ │ - var components = geometry.components || [geometry]; │ │ │ │ │ - for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "polygonMember", components[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "polygonMember": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:polygonMember"); │ │ │ │ │ - this.writeNode("Polygon", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "GeometryCollection": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:GeometryCollection"); │ │ │ │ │ - for (var i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("geometryMember", geometry.components[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "geometryMember": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:geometryMember"); │ │ │ │ │ - var child = this.writeNode("feature:_geometry", geometry); │ │ │ │ │ - node.appendChild(child.firstChild); │ │ │ │ │ - return node; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "feature": { │ │ │ │ │ - "_typeName": function(feature) { │ │ │ │ │ - var node = this.createElementNSPlus("feature:" + this.featureType, { │ │ │ │ │ - attributes: { │ │ │ │ │ - fid: feature.fid │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - this.writeNode("feature:_geometry", feature.geometry, node); │ │ │ │ │ + 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 name in feature.attributes) { │ │ │ │ │ - var value = feature.attributes[name]; │ │ │ │ │ - if (value != null) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "feature:_attribute", { │ │ │ │ │ - name: name, │ │ │ │ │ - value: value │ │ │ │ │ - }, node │ │ │ │ │ - ); │ │ │ │ │ + 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()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "_geometry": function(geometry) { │ │ │ │ │ - if (this.externalProjection && this.internalProjection) { │ │ │ │ │ - geometry = geometry.clone().transform( │ │ │ │ │ - this.internalProjection, this.externalProjection │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - var node = this.createElementNSPlus( │ │ │ │ │ - "feature:" + this.geometryName │ │ │ │ │ - ); │ │ │ │ │ - var type = this.geometryTypes[geometry.CLASS_NAME]; │ │ │ │ │ - var child = this.writeNode("gml:" + type, geometry, node); │ │ │ │ │ - if (this.srsName) { │ │ │ │ │ - child.setAttribute("srsName", this.srsName); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "_attribute": function(obj) { │ │ │ │ │ - return this.createElementNSPlus("feature:" + obj.name, { │ │ │ │ │ - value: obj.value │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - "wfs": { │ │ │ │ │ - "FeatureCollection": function(features) { │ │ │ │ │ - /** │ │ │ │ │ - * This is only here because GML2 only describes abstract │ │ │ │ │ - * feature collections. Typically, you would not be using │ │ │ │ │ - * the GML format to write wfs elements. This just provides │ │ │ │ │ - * some way to write out lists of features. GML3 defines the │ │ │ │ │ - * featureMembers element, so that is used by default instead. │ │ │ │ │ - */ │ │ │ │ │ - var node = this.createElementNSPlus("wfs:FeatureCollection"); │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("gml:featureMember", features[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ + 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: setGeometryTypes │ │ │ │ │ - * Sets the mapping. │ │ │ │ │ - */ │ │ │ │ │ - setGeometryTypes: function() { │ │ │ │ │ - this.geometryTypes = { │ │ │ │ │ - "OpenLayers.Geometry.Point": "Point", │ │ │ │ │ - "OpenLayers.Geometry.MultiPoint": "MultiPoint", │ │ │ │ │ - "OpenLayers.Geometry.LineString": "LineString", │ │ │ │ │ - "OpenLayers.Geometry.MultiLineString": "MultiLineString", │ │ │ │ │ - "OpenLayers.Geometry.Polygon": "Polygon", │ │ │ │ │ - "OpenLayers.Geometry.MultiPolygon": "MultiPolygon", │ │ │ │ │ - "OpenLayers.Geometry.Collection": "GeometryCollection" │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.GML.Base" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/GML/v3.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/GML/Base.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.GML.v3 │ │ │ │ │ - * Parses GML version 3. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. The writers │ │ │ │ │ - * conform with the Simple Features Profile for GML. │ │ │ │ │ - */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: curve │ │ │ │ │ - * {Boolean} Write gml:Curve instead of gml:LineString elements. This also │ │ │ │ │ - * affects the elements in multi-part geometries. Default is false. │ │ │ │ │ - * To write gml:Curve elements instead of gml:LineString, set curve │ │ │ │ │ - * to true in the options to the contstructor (cannot be changed after │ │ │ │ │ - * instantiation). │ │ │ │ │ - */ │ │ │ │ │ - curve: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: multiCurve │ │ │ │ │ - * {Boolean} Write gml:MultiCurve instead of gml:MultiLineString. Since │ │ │ │ │ - * the latter is deprecated in GML 3, the default is true. To write │ │ │ │ │ - * gml:MultiLineString instead of gml:MultiCurve, set multiCurve to │ │ │ │ │ - * false in the options to the constructor (cannot be changed after │ │ │ │ │ - * instantiation). │ │ │ │ │ - */ │ │ │ │ │ - multiCurve: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: surface │ │ │ │ │ - * {Boolean} Write gml:Surface instead of gml:Polygon elements. This also │ │ │ │ │ - * affects the elements in multi-part geometries. Default is false. │ │ │ │ │ - * To write gml:Surface elements instead of gml:Polygon, set surface │ │ │ │ │ - * to true in the options to the contstructor (cannot be changed after │ │ │ │ │ - * instantiation). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - surface: false, │ │ │ │ │ + splitWith: function(geometry, options) { │ │ │ │ │ + return geometry.split(this, options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: multiSurface │ │ │ │ │ - * {Boolean} Write gml:multiSurface instead of gml:MultiPolygon. Since │ │ │ │ │ - * the latter is deprecated in GML 3, the default is true. To write │ │ │ │ │ - * gml:MultiPolygon instead of gml:multiSurface, set multiSurface to │ │ │ │ │ - * false in the options to the constructor (cannot be changed after │ │ │ │ │ - * instantiation). │ │ │ │ │ - */ │ │ │ │ │ - multiSurface: true, │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.GML.v3 │ │ │ │ │ - * Create a parser for GML v3. │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Valid options properties: │ │ │ │ │ - * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ - * featureNS - {String} Feature namespace (required). │ │ │ │ │ - * geometryName - {String} Geometry element name. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "_inherit": function(node, obj, container) { │ │ │ │ │ - // SRSReferenceGroup attributes │ │ │ │ │ - var dim = parseInt(node.getAttribute("srsDimension"), 10) || │ │ │ │ │ - (container && container.srsDimension); │ │ │ │ │ - if (dim) { │ │ │ │ │ - obj.srsDimension = dim; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "featureMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "Curve": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - points: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ - } │ │ │ │ │ - container.components.push( │ │ │ │ │ - new OpenLayers.Geometry.LineString(obj.points) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "segments": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "LineStringSegment": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (obj.points) { │ │ │ │ │ - Array.prototype.push.apply(container.points, obj.points); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "pos": function(node, obj) { │ │ │ │ │ - var str = this.getChildValue(node).replace( │ │ │ │ │ - this.regExes.trimSpace, "" │ │ │ │ │ - ); │ │ │ │ │ - var coords = str.split(this.regExes.splitSpace); │ │ │ │ │ - var point; │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - point = new OpenLayers.Geometry.Point( │ │ │ │ │ - coords[0], coords[1], coords[2] │ │ │ │ │ - ); │ │ │ │ │ + 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 { │ │ │ │ │ - point = new OpenLayers.Geometry.Point( │ │ │ │ │ - coords[1], coords[0], coords[2] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - obj.points = [point]; │ │ │ │ │ - }, │ │ │ │ │ - "posList": function(node, obj) { │ │ │ │ │ - var str = this.getChildValue(node).replace( │ │ │ │ │ - this.regExes.trimSpace, "" │ │ │ │ │ - ); │ │ │ │ │ - var coords = str.split(this.regExes.splitSpace); │ │ │ │ │ - // The "dimension" attribute is from the GML 3.0.1 spec. │ │ │ │ │ - var dim = obj.srsDimension || │ │ │ │ │ - parseInt(node.getAttribute("srsDimension") || node.getAttribute("dimension"), 10) || 2; │ │ │ │ │ - var j, x, y, z; │ │ │ │ │ - var numPoints = coords.length / dim; │ │ │ │ │ - var points = new Array(numPoints); │ │ │ │ │ - for (var i = 0, len = coords.length; i < len; i += dim) { │ │ │ │ │ - x = coords[i]; │ │ │ │ │ - y = coords[i + 1]; │ │ │ │ │ - z = (dim == 2) ? undefined : coords[i + 2]; │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - points[i / dim] = new OpenLayers.Geometry.Point(x, y, z); │ │ │ │ │ - } else { │ │ │ │ │ - points[i / dim] = new OpenLayers.Geometry.Point(y, x, z); │ │ │ │ │ + // 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; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - obj.points = points; │ │ │ │ │ - }, │ │ │ │ │ - "Surface": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "patches": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "PolygonPatch": function(node, obj) { │ │ │ │ │ - this.readers.gml.Polygon.apply(this, [node, obj]); │ │ │ │ │ - }, │ │ │ │ │ - "exterior": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.outer = obj.components[0]; │ │ │ │ │ - }, │ │ │ │ │ - "interior": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.inner.push(obj.components[0]); │ │ │ │ │ - }, │ │ │ │ │ - "MultiCurve": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ + } │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: best.distance, │ │ │ │ │ + x0: best.x, │ │ │ │ │ + y0: best.y, │ │ │ │ │ + x1: x, │ │ │ │ │ + y1: y │ │ │ │ │ }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (obj.components.length > 0) { │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiLineString(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ + } 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 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - "curveMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "MultiSurface": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - components: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (obj.components.length > 0) { │ │ │ │ │ - container.components = [ │ │ │ │ │ - new OpenLayers.Geometry.MultiPolygon(obj.components) │ │ │ │ │ - ]; │ │ │ │ │ + } │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - "surfaceMember": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "surfaceMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "pointMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "lineStringMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "polygonMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "geometryMembers": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "Envelope": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - points: new Array(2) │ │ │ │ │ + } │ │ │ │ │ + } 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 │ │ │ │ │ }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ - } │ │ │ │ │ - var min = obj.points[0]; │ │ │ │ │ - var max = obj.points[1]; │ │ │ │ │ - container.components.push( │ │ │ │ │ - new OpenLayers.Bounds(min.x, min.y, max.x, max.y) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "lowerCorner": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readers.gml.pos.apply(this, [node, obj]); │ │ │ │ │ - container.points[0] = obj.points[0]; │ │ │ │ │ - }, │ │ │ │ │ - "upperCorner": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readers.gml.pos.apply(this, [node, obj]); │ │ │ │ │ - container.points[1] = obj.points[0]; │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.GML.Base.prototype.readers["gml"]), │ │ │ │ │ - "feature": OpenLayers.Format.GML.Base.prototype.readers["feature"], │ │ │ │ │ - "wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"] │ │ │ │ │ + } │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * APIMethod: simplify │ │ │ │ │ + * This function will return a simplified LineString. │ │ │ │ │ + * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ + * │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ - * An array of features or a single feature. │ │ │ │ │ + * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ - * element will be returned. Given a single feature, a doc with a │ │ │ │ │ - * gml:featureMember element will be returned. │ │ │ │ │ + * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ */ │ │ │ │ │ - write: function(features) { │ │ │ │ │ - var name; │ │ │ │ │ - if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ - name = "featureMembers"; │ │ │ │ │ - } else { │ │ │ │ │ - name = "featureMember"; │ │ │ │ │ - } │ │ │ │ │ - var root = this.writeNode("gml:" + name, features); │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - root, this.namespaces["xsi"], │ │ │ │ │ - "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ - ); │ │ │ │ │ + simplify: function(tolerance) { │ │ │ │ │ + if (this && this !== null) { │ │ │ │ │ + var points = this.getVertices(); │ │ │ │ │ + if (points.length < 3) { │ │ │ │ │ + return this; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ - }, │ │ │ │ │ + var compareNumbers = function(a, b) { │ │ │ │ │ + return (a - b); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "featureMembers": function(features) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:featureMembers"); │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("feature:_typeName", features[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Point": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Point"); │ │ │ │ │ - this.writeNode("pos", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "pos": function(point) { │ │ │ │ │ - // only 2d for simple features profile │ │ │ │ │ - var pos = (this.xy) ? │ │ │ │ │ - (point.x + " " + point.y) : (point.y + " " + point.x); │ │ │ │ │ - return this.createElementNSPlus("gml:pos", { │ │ │ │ │ - value: pos │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "LineString": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:LineString"); │ │ │ │ │ - this.writeNode("posList", geometry.components, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Curve": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Curve"); │ │ │ │ │ - this.writeNode("segments", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "segments": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:segments"); │ │ │ │ │ - this.writeNode("LineStringSegment", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LineStringSegment": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:LineStringSegment"); │ │ │ │ │ - this.writeNode("posList", geometry.components, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "posList": function(points) { │ │ │ │ │ - // only 2d for simple features profile │ │ │ │ │ - var len = points.length; │ │ │ │ │ - var parts = new Array(len); │ │ │ │ │ - var point; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - point = points[i]; │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - parts[i] = point.x + " " + point.y; │ │ │ │ │ - } else { │ │ │ │ │ - parts[i] = point.y + " " + point.x; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return this.createElementNSPlus("gml:posList", { │ │ │ │ │ - value: parts.join(" ") │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Surface": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Surface"); │ │ │ │ │ - this.writeNode("patches", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "patches": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:patches"); │ │ │ │ │ - this.writeNode("PolygonPatch", geometry, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PolygonPatch": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:PolygonPatch", { │ │ │ │ │ - attributes: { │ │ │ │ │ - interpolation: "planar" │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("exterior", geometry.components[0], node); │ │ │ │ │ - for (var i = 1, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "interior", geometry.components[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Polygon": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Polygon"); │ │ │ │ │ - this.writeNode("exterior", geometry.components[0], node); │ │ │ │ │ - for (var i = 1, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "interior", geometry.components[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "exterior": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:exterior"); │ │ │ │ │ - this.writeNode("LinearRing", ring, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "interior": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:interior"); │ │ │ │ │ - this.writeNode("LinearRing", ring, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LinearRing": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:LinearRing"); │ │ │ │ │ - this.writeNode("posList", ring.components, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MultiCurve": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:MultiCurve"); │ │ │ │ │ - var components = geometry.components || [geometry]; │ │ │ │ │ - for (var i = 0, len = components.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("curveMember", components[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "curveMember": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:curveMember"); │ │ │ │ │ - if (this.curve) { │ │ │ │ │ - this.writeNode("Curve", geometry, node); │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("LineString", geometry, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "MultiSurface": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:MultiSurface"); │ │ │ │ │ - var components = geometry.components || [geometry]; │ │ │ │ │ - for (var i = 0, len = components.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("surfaceMember", components[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "surfaceMember": function(polygon) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:surfaceMember"); │ │ │ │ │ - if (this.surface) { │ │ │ │ │ - this.writeNode("Surface", polygon, node); │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("Polygon", polygon, node); │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Envelope": function(bounds) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Envelope"); │ │ │ │ │ - this.writeNode("lowerCorner", bounds, node); │ │ │ │ │ - this.writeNode("upperCorner", bounds, node); │ │ │ │ │ - // srsName attribute is required for gml:Envelope │ │ │ │ │ - if (this.srsName) { │ │ │ │ │ - node.setAttribute("srsName", this.srsName); │ │ │ │ │ + │ │ │ │ │ + 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 node; │ │ │ │ │ - }, │ │ │ │ │ - "lowerCorner": function(bounds) { │ │ │ │ │ - // only 2d for simple features profile │ │ │ │ │ - var pos = (this.xy) ? │ │ │ │ │ - (bounds.left + " " + bounds.bottom) : │ │ │ │ │ - (bounds.bottom + " " + bounds.left); │ │ │ │ │ - return this.createElementNSPlus("gml:lowerCorner", { │ │ │ │ │ - value: pos │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "upperCorner": function(bounds) { │ │ │ │ │ - // only 2d for simple features profile │ │ │ │ │ - var pos = (this.xy) ? │ │ │ │ │ - (bounds.right + " " + bounds.top) : │ │ │ │ │ - (bounds.top + " " + bounds.right); │ │ │ │ │ - return this.createElementNSPlus("gml:upperCorner", { │ │ │ │ │ - value: pos │ │ │ │ │ - }); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.GML.Base.prototype.writers["gml"]), │ │ │ │ │ - "feature": OpenLayers.Format.GML.Base.prototype.writers["feature"], │ │ │ │ │ - "wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"] │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setGeometryTypes │ │ │ │ │ - * Sets the mapping. │ │ │ │ │ - */ │ │ │ │ │ - setGeometryTypes: function() { │ │ │ │ │ - this.geometryTypes = { │ │ │ │ │ - "OpenLayers.Geometry.Point": "Point", │ │ │ │ │ - "OpenLayers.Geometry.MultiPoint": "MultiPoint", │ │ │ │ │ - "OpenLayers.Geometry.LineString": (this.curve === true) ? "Curve" : "LineString", │ │ │ │ │ - "OpenLayers.Geometry.MultiLineString": (this.multiCurve === false) ? "MultiLineString" : "MultiCurve", │ │ │ │ │ - "OpenLayers.Geometry.Polygon": (this.surface === true) ? "Surface" : "Polygon", │ │ │ │ │ - "OpenLayers.Geometry.MultiPolygon": (this.multiSurface === false) ? "MultiPolygon" : "MultiSurface", │ │ │ │ │ - "OpenLayers.Geometry.Collection": "GeometryCollection" │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ + 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); │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.GML.v3" │ │ │ │ │ + } else { │ │ │ │ │ + return this; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.LineString" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/Filter/v1_1_0.js │ │ │ │ │ + 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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Format/Filter/v1.js │ │ │ │ │ - * @requires OpenLayers/Format/GML/v3.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.Filter.v1_1_0 │ │ │ │ │ - * Write ogc:Filter version 1.1.0. │ │ │ │ │ - * │ │ │ │ │ - * Differences from the v1.0.0 parser: │ │ │ │ │ - * - uses GML v3 instead of GML v2 │ │ │ │ │ - * - reads matchCase attribute on ogc:PropertyIsEqual and │ │ │ │ │ - * ogc:PropertyIsNotEqual elements. │ │ │ │ │ - * - writes matchCase attribute from comparison filters of type EQUAL_TO, │ │ │ │ │ - * NOT_EQUAL_TO and LIKE. │ │ │ │ │ + * Class: OpenLayers.Geometry.MultiLineString │ │ │ │ │ + * A MultiLineString is a geometry with multiple │ │ │ │ │ + * components. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Format.GML.v3, OpenLayers.Format.Filter.v1, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.1.0 │ │ │ │ │ - */ │ │ │ │ │ - VERSION: "1.1.0", │ │ │ │ │ +OpenLayers.Geometry.MultiLineString = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} http://www.opengis.net/ogc/filter/1.1.0/filter.xsd │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/ogc/filter/1.1.0/filter.xsd", │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.LineString"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.Filter.v1_1_0 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * constructor instead. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiLineString │ │ │ │ │ + * Constructor for a MultiLineString Geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.GML.v3.prototype.initialize.apply( │ │ │ │ │ - this, [options] │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: { │ │ │ │ │ - "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "PropertyIsEqualTo": function(node, obj) { │ │ │ │ │ - var matchCase = node.getAttribute("matchCase"); │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.EQUAL_TO, │ │ │ │ │ - matchCase: !(matchCase === "false" || matchCase === "0") │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNotEqualTo": function(node, obj) { │ │ │ │ │ - var matchCase = node.getAttribute("matchCase"); │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO, │ │ │ │ │ - matchCase: !(matchCase === "false" || matchCase === "0") │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLike": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.LIKE │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - var wildCard = node.getAttribute("wildCard"); │ │ │ │ │ - var singleChar = node.getAttribute("singleChar"); │ │ │ │ │ - var esc = node.getAttribute("escapeChar"); │ │ │ │ │ - filter.value2regex(wildCard, singleChar, esc); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"] │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * Method: split │ │ │ │ │ + * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} 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. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "PropertyIsEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", { │ │ │ │ │ - attributes: { │ │ │ │ │ - matchCase: filter.matchCase │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNotEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", { │ │ │ │ │ - attributes: { │ │ │ │ │ - matchCase: filter.matchCase │ │ │ │ │ + split: function(geometry, options) { │ │ │ │ │ + var results = null; │ │ │ │ │ + var mutual = options && options.mutual; │ │ │ │ │ + var splits, sourceLine, sourceLines, sourceSplit, targetSplit; │ │ │ │ │ + var sourceParts = []; │ │ │ │ │ + var targetParts = [geometry]; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + sourceLine = this.components[i]; │ │ │ │ │ + sourceSplit = false; │ │ │ │ │ + for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ + splits = sourceLine.split(targetParts[j], options); │ │ │ │ │ + if (splits) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + sourceLines = splits[0]; │ │ │ │ │ + for (var k = 0, klen = sourceLines.length; k < klen; ++k) { │ │ │ │ │ + if (k === 0 && sourceParts.length) { │ │ │ │ │ + sourceParts[sourceParts.length - 1].addComponent( │ │ │ │ │ + sourceLines[k] │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + sourceParts.push( │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ + sourceLines[k] │ │ │ │ │ + ]) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + splits = splits[1]; │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLike": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsLike", { │ │ │ │ │ - attributes: { │ │ │ │ │ - matchCase: filter.matchCase, │ │ │ │ │ - wildCard: "*", │ │ │ │ │ - singleChar: ".", │ │ │ │ │ - escapeChar: "!" │ │ │ │ │ + if (splits.length) { │ │ │ │ │ + // splice in new target parts │ │ │ │ │ + splits.unshift(j, 1); │ │ │ │ │ + Array.prototype.splice.apply(targetParts, splits); │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - // no ogc:expression handling for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // convert regex string to ogc string │ │ │ │ │ - this.writeNode("Literal", filter.regex2value(), node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "BBOX": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:BBOX"); │ │ │ │ │ - // PropertyName is optional in 1.1.0 │ │ │ │ │ - filter.property && this.writeNode("PropertyName", filter, node); │ │ │ │ │ - var box = this.writeNode("gml:Envelope", filter.value); │ │ │ │ │ - if (filter.projection) { │ │ │ │ │ - box.setAttribute("srsName", filter.projection); │ │ │ │ │ } │ │ │ │ │ - node.appendChild(box); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "SortBy": function(sortProperties) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:SortBy"); │ │ │ │ │ - for (var i = 0, l = sortProperties.length; i < l; i++) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "ogc:SortProperty", │ │ │ │ │ - sortProperties[i], │ │ │ │ │ - node │ │ │ │ │ + } │ │ │ │ │ + if (!sourceSplit) { │ │ │ │ │ + // source line was not hit │ │ │ │ │ + if (sourceParts.length) { │ │ │ │ │ + // add line to existing multi │ │ │ │ │ + sourceParts[sourceParts.length - 1].addComponent( │ │ │ │ │ + sourceLine.clone() │ │ │ │ │ ); │ │ │ │ │ + } else { │ │ │ │ │ + // create a fresh multi │ │ │ │ │ + sourceParts = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString( │ │ │ │ │ + sourceLine.clone() │ │ │ │ │ + ) │ │ │ │ │ + ]; │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "SortProperty": function(sortProperty) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:SortProperty"); │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "ogc:PropertyName", │ │ │ │ │ - sortProperty, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "ogc:SortOrder", │ │ │ │ │ - (sortProperty.order == 'DESC') ? 'DESC' : 'ASC', │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "SortOrder": function(value) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:SortOrder", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"] │ │ │ │ │ + } │ │ │ │ │ + if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (targetParts && targetParts.length > 1) { │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + targetParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (sourceSplit || targetSplit) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + results = [sourceParts, targetParts]; │ │ │ │ │ + } else { │ │ │ │ │ + results = targetParts; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return results; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: writeSpatial │ │ │ │ │ - * │ │ │ │ │ - * Read a {} filter and converts it into XML. │ │ │ │ │ + * Method: splitWith │ │ │ │ │ + * Split this geometry (the target) with the given geometry (the source). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * filter - {} The filter. │ │ │ │ │ - * name - {String} Name of the generated XML element. │ │ │ │ │ + * 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: │ │ │ │ │ - * {DOMElement} The created XML element. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - writeSpatial: function(filter, name) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:" + name); │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - if (filter.value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ - this.writeNode("Function", filter.value, node); │ │ │ │ │ + splitWith: function(geometry, options) { │ │ │ │ │ + var results = null; │ │ │ │ │ + var mutual = options && options.mutual; │ │ │ │ │ + var splits, targetLine, sourceLines, sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ + if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ + targetParts = []; │ │ │ │ │ + sourceParts = [geometry]; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + targetSplit = false; │ │ │ │ │ + targetLine = this.components[i]; │ │ │ │ │ + for (var j = 0; j < sourceParts.length; ++j) { │ │ │ │ │ + splits = sourceParts[j].split(targetLine, options); │ │ │ │ │ + if (splits) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + sourceLines = splits[0]; │ │ │ │ │ + if (sourceLines.length) { │ │ │ │ │ + // splice in new source parts │ │ │ │ │ + sourceLines.unshift(j, 1); │ │ │ │ │ + Array.prototype.splice.apply(sourceParts, sourceLines); │ │ │ │ │ + j += sourceLines.length - 2; │ │ │ │ │ + } │ │ │ │ │ + splits = splits[1]; │ │ │ │ │ + if (splits.length === 0) { │ │ │ │ │ + splits = [targetLine.clone()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + for (var k = 0, klen = splits.length; k < klen; ++k) { │ │ │ │ │ + if (k === 0 && targetParts.length) { │ │ │ │ │ + targetParts[targetParts.length - 1].addComponent( │ │ │ │ │ + splits[k] │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + targetParts.push( │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ + splits[k] │ │ │ │ │ + ]) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!targetSplit) { │ │ │ │ │ + // target component was not hit │ │ │ │ │ + if (targetParts.length) { │ │ │ │ │ + // add it to any existing multi-line │ │ │ │ │ + targetParts[targetParts.length - 1].addComponent( │ │ │ │ │ + targetLine.clone() │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + // or start with a fresh multi-line │ │ │ │ │ + targetParts = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString([ │ │ │ │ │ + targetLine.clone() │ │ │ │ │ + ]) │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } else { │ │ │ │ │ - var child; │ │ │ │ │ - if (filter.value instanceof OpenLayers.Geometry) { │ │ │ │ │ - child = this.writeNode("feature:_geometry", filter.value).firstChild; │ │ │ │ │ + results = geometry.split(this); │ │ │ │ │ + } │ │ │ │ │ + if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (targetParts && targetParts.length > 1) { │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + targetParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (sourceSplit || targetSplit) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + results = [sourceParts, targetParts]; │ │ │ │ │ } else { │ │ │ │ │ - child = this.writeNode("gml:Envelope", filter.value); │ │ │ │ │ - } │ │ │ │ │ - if (filter.projection) { │ │ │ │ │ - child.setAttribute("srsName", filter.projection); │ │ │ │ │ + results = targetParts; │ │ │ │ │ } │ │ │ │ │ - node.appendChild(child); │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ + return results; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiLineString" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/OWSCommon/v1_0_0.js │ │ │ │ │ + OpenLayers/Geometry/LinearRing.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/OWSCommon/v1.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.OWSCommon.v1_0_0 │ │ │ │ │ - * Parser for OWS Common version 1.0.0. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Geometry.LinearRing │ │ │ │ │ + * │ │ │ │ │ + * A Linear Ring is a special LineString which is closed. It closes itself │ │ │ │ │ + * automatically on every addPoint/removePoint by adding a copy of the first │ │ │ │ │ + * point as the last point. │ │ │ │ │ + * │ │ │ │ │ + * Also, as it is the first in the line family to close itself, a getArea() │ │ │ │ │ + * function is defined to calculate the enclosed area of the linearRing │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.OWSCommon.v1_0_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ows: "http://www.opengis.net/ows", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink" │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Geometry.LinearRing = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.LineString, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: { │ │ │ │ │ - "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "ExceptionReport": function(node, obj) { │ │ │ │ │ - obj.success = false; │ │ │ │ │ - obj.exceptionReport = { │ │ │ │ │ - version: node.getAttribute('version'), │ │ │ │ │ - language: node.getAttribute('language'), │ │ │ │ │ - exceptions: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.OWSCommon.v1.prototype.readers.ows) │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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"], │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1.prototype.writers.ows │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.LinearRing │ │ │ │ │ + * Linear rings are constructed with an array of points. This array │ │ │ │ │ + * can represent a closed or open ring. If the ring is open (the last │ │ │ │ │ + * point does not equal the first point), the constructor will close │ │ │ │ │ + * the ring. If the ring is already closed (the last point does equal │ │ │ │ │ + * the first point), it will be left closed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * points - {Array()} points │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_0_0" │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addComponent │ │ │ │ │ + * Adds a point to geometry components. If the point is to be added to │ │ │ │ │ + * the end of the components array and it is the same as the last point │ │ │ │ │ + * already in that array, the duplicate point is not added. This has │ │ │ │ │ + * the effect of closing the ring if it is not already closed, and │ │ │ │ │ + * doing the right thing if it is already closed. This behavior can │ │ │ │ │ + * be overridden by calling the method with a non-null index as the │ │ │ │ │ + * second argument. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} │ │ │ │ │ + * index - {Integer} Index into the array to insert the component │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Was the Point successfully added? │ │ │ │ │ + */ │ │ │ │ │ + addComponent: function(point, index) { │ │ │ │ │ + var added = false; │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WFST/v1_1_0.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + //remove last point │ │ │ │ │ + var lastPoint = this.components.pop(); │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + // given an index, add the point │ │ │ │ │ + // without an index only add non-duplicate points │ │ │ │ │ + if (index != null || !point.equals(lastPoint)) { │ │ │ │ │ + added = OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Format/WFST/v1.js │ │ │ │ │ - * @requires OpenLayers/Format/Filter/v1_1_0.js │ │ │ │ │ - * @requires OpenLayers/Format/OWSCommon/v1_0_0.js │ │ │ │ │ - */ │ │ │ │ │ + //append copy of first point │ │ │ │ │ + var firstPoint = this.components[0]; │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ + [firstPoint]); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.WFST.v1_1_0 │ │ │ │ │ - * A format for creating WFS v1.1.0 transactions. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Format.Filter.v1_1_0, OpenLayers.Format.WFST.v1, { │ │ │ │ │ + return added; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} WFS version number. │ │ │ │ │ + * APIMethod: removeComponent │ │ │ │ │ + * Removes a point from geometry components. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - version: "1.1.0", │ │ │ │ │ + removeComponent: function(point) { │ │ │ │ │ + var removed = this.components && (this.components.length > 3); │ │ │ │ │ + if (removed) { │ │ │ │ │ + //remove last point │ │ │ │ │ + this.components.pop(); │ │ │ │ │ + │ │ │ │ │ + //remove our point │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + //append copy of first point │ │ │ │ │ + var firstPoint = this.components[0]; │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, │ │ │ │ │ + [firstPoint]); │ │ │ │ │ + } │ │ │ │ │ + return removed; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: schemaLocations │ │ │ │ │ - * {Object} Properties are namespace aliases, values are schema locations. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - schemaLocations: { │ │ │ │ │ - "wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len - 1; i++) { │ │ │ │ │ + this.components[i].move(x, y); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WFST.v1_1_0 │ │ │ │ │ - * A class for parsing and generating WFS v1.1.0 transactions. │ │ │ │ │ - * │ │ │ │ │ - * To read additional information like hit count (numberOfFeatures) from │ │ │ │ │ - * the FeatureCollection, call the method │ │ │ │ │ - * with {output: "object"} as 2nd argument. Note that it is possible to │ │ │ │ │ - * just request the hit count from a WFS 1.1.0 server with the │ │ │ │ │ - * resultType="hits" request parameter. │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a geometry around some origin │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * 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 - 1; ++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. │ │ │ │ │ * │ │ │ │ │ - * Valid options properties: │ │ │ │ │ - * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ - * featureNS - {String} Feature namespace (optional). │ │ │ │ │ - * featurePrefix - {String} Feature namespace alias (optional - only used │ │ │ │ │ - * if featureNS is provided). Default is 'feature'. │ │ │ │ │ - * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.Filter.v1_1_0.prototype.initialize.apply(this, [options]); │ │ │ │ │ - OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]); │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len - 1; ++i) { │ │ │ │ │ + this.components[i].resize(scale, origin, ratio); │ │ │ │ │ + } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: readNode │ │ │ │ │ - * Shorthand for applying one of the named readers given the node │ │ │ │ │ - * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ - * generally extend or modify the second. │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Reproject the components geometry from source to dest. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {DOMElement} The node to be read (required). │ │ │ │ │ - * obj - {Object} The object to be modified (optional). │ │ │ │ │ - * first - {Boolean} Should be set to true for the first node read. This │ │ │ │ │ - * is usually the readNode call in the read method. Without this being │ │ │ │ │ - * set, auto-configured properties will stick on subsequent reads. │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if (source && dest) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len - 1; i++) { │ │ │ │ │ + var component = this.components[i]; │ │ │ │ │ + component.transform(source, dest); │ │ │ │ │ + } │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + } │ │ │ │ │ + return this; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - readNode: function(node, obj, first) { │ │ │ │ │ - // Not the superclass, only the mixin classes inherit from │ │ │ │ │ - // Format.GML.v3. We need this because we don't want to get readNode │ │ │ │ │ - // from the superclass's superclass, which is OpenLayers.Format.XML. │ │ │ │ │ - return OpenLayers.Format.GML.v3.prototype.readNode.apply(this, arguments); │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + if (this.components) { │ │ │ │ │ + var len = this.components.length; │ │ │ │ │ + if (len > 0 && len <= 2) { │ │ │ │ │ + return this.components[0].clone(); │ │ │ │ │ + } else if (len > 2) { │ │ │ │ │ + var sumX = 0.0; │ │ │ │ │ + var sumY = 0.0; │ │ │ │ │ + var x0 = this.components[0].x; │ │ │ │ │ + var y0 = this.components[0].y; │ │ │ │ │ + var area = -1 * this.getArea(); │ │ │ │ │ + if (area != 0) { │ │ │ │ │ + for (var i = 0; i < len - 1; i++) { │ │ │ │ │ + var b = this.components[i]; │ │ │ │ │ + var c = this.components[i + 1]; │ │ │ │ │ + sumX += (b.x + c.x - 2 * x0) * ((b.x - x0) * (c.y - y0) - (c.x - x0) * (b.y - y0)); │ │ │ │ │ + sumY += (b.y + c.y - 2 * y0) * ((b.x - x0) * (c.y - y0) - (c.x - x0) * (b.y - y0)); │ │ │ │ │ + } │ │ │ │ │ + var x = x0 + sumX / (6 * area); │ │ │ │ │ + var y = y0 + sumY / (6 * area); │ │ │ │ │ + } else { │ │ │ │ │ + for (var i = 0; i < len - 1; i++) { │ │ │ │ │ + sumX += this.components[i].x; │ │ │ │ │ + sumY += this.components[i].y; │ │ │ │ │ + } │ │ │ │ │ + var x = sumX / (len - 1); │ │ │ │ │ + var y = sumY / (len - 1); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.Point(x, y); │ │ │ │ │ + } else { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: getArea │ │ │ │ │ + * Note - The area is positive if the ring is oriented CW, otherwise │ │ │ │ │ + * it will be negative. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The signed area for a ring. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "wfs": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "FeatureCollection": function(node, obj) { │ │ │ │ │ - obj.numberOfFeatures = parseInt(node.getAttribute( │ │ │ │ │ - "numberOfFeatures")); │ │ │ │ │ - OpenLayers.Format.WFST.v1.prototype.readers["wfs"]["FeatureCollection"].apply( │ │ │ │ │ - this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - "TransactionResponse": function(node, obj) { │ │ │ │ │ - obj.insertIds = []; │ │ │ │ │ - obj.success = false; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "TransactionSummary": function(node, obj) { │ │ │ │ │ - // this is a limited test of success │ │ │ │ │ - obj.success = true; │ │ │ │ │ - }, │ │ │ │ │ - "InsertResults": function(node, obj) { │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - }, │ │ │ │ │ - "Feature": function(node, container) { │ │ │ │ │ - var obj = { │ │ │ │ │ - fids: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.insertIds.push(obj.fids[0]); │ │ │ │ │ + getArea: function() { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + if (this.components && (this.components.length > 2)) { │ │ │ │ │ + var sum = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len - 1; i++) { │ │ │ │ │ + var b = this.components[i]; │ │ │ │ │ + var c = this.components[i + 1]; │ │ │ │ │ + sum += (b.x + c.x) * (c.y - b.y); │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"], │ │ │ │ │ - "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"], │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"] │ │ │ │ │ + area = -sum / 2.0; │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * APIMethod: getGeodesicArea │ │ │ │ │ + * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ + * the earth. Note that this area will be positive if ring is oriented │ │ │ │ │ + * clockwise, otherwise it will be negative. │ │ │ │ │ + * │ │ │ │ │ + * 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 signed geodesic area of the polygon in square │ │ │ │ │ + * meters. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "wfs": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "GetFeature": function(options) { │ │ │ │ │ - var node = OpenLayers.Format.WFST.v1.prototype.writers["wfs"]["GetFeature"].apply(this, arguments); │ │ │ │ │ - options && this.setAttributes(node, { │ │ │ │ │ - resultType: options.resultType, │ │ │ │ │ - startIndex: options.startIndex, │ │ │ │ │ - count: options.count │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Query": function(options) { │ │ │ │ │ - options = OpenLayers.Util.extend({ │ │ │ │ │ - featureNS: this.featureNS, │ │ │ │ │ - featurePrefix: this.featurePrefix, │ │ │ │ │ - featureType: this.featureType, │ │ │ │ │ - srsName: this.srsName │ │ │ │ │ - }, options); │ │ │ │ │ - var prefix = options.featurePrefix; │ │ │ │ │ - var node = this.createElementNSPlus("wfs:Query", { │ │ │ │ │ - attributes: { │ │ │ │ │ - typeName: (prefix ? prefix + ":" : "") + │ │ │ │ │ - options.featureType, │ │ │ │ │ - srsName: options.srsName │ │ │ │ │ + getGeodesicArea: function(projection) { │ │ │ │ │ + var ring = this; // so we can work with a clone if needed │ │ │ │ │ + if (projection) { │ │ │ │ │ + var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + if (!gg.equals(projection)) { │ │ │ │ │ + ring = this.clone().transform(projection, gg); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + var len = ring.components && ring.components.length; │ │ │ │ │ + if (len > 2) { │ │ │ │ │ + var p1, p2; │ │ │ │ │ + for (var i = 0; i < len - 1; i++) { │ │ │ │ │ + p1 = ring.components[i]; │ │ │ │ │ + p2 = ring.components[i + 1]; │ │ │ │ │ + area += OpenLayers.Util.rad(p2.x - p1.x) * │ │ │ │ │ + (2 + Math.sin(OpenLayers.Util.rad(p1.y)) + │ │ │ │ │ + Math.sin(OpenLayers.Util.rad(p2.y))); │ │ │ │ │ + } │ │ │ │ │ + area = area * 6378137.0 * 6378137.0 / 2.0; │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: containsPoint │ │ │ │ │ + * Test if a point is inside a linear ring. For the case where a point │ │ │ │ │ + * is coincident with a linear ring edge, returns 1. Otherwise, │ │ │ │ │ + * returns boolean. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean | Number} The point is inside the linear ring. Returns 1 if │ │ │ │ │ + * the point is coincident with an edge. Returns boolean otherwise. │ │ │ │ │ + */ │ │ │ │ │ + containsPoint: function(point) { │ │ │ │ │ + var approx = OpenLayers.Number.limitSigDigs; │ │ │ │ │ + var digs = 14; │ │ │ │ │ + var px = approx(point.x, digs); │ │ │ │ │ + var py = approx(point.y, digs); │ │ │ │ │ + │ │ │ │ │ + function getX(y, x1, y1, x2, y2) { │ │ │ │ │ + return (y - y2) * ((x2 - x1) / (y2 - y1)) + x2; │ │ │ │ │ + } │ │ │ │ │ + var numSeg = this.components.length - 1; │ │ │ │ │ + var start, end, x1, y1, x2, y2, cx, cy; │ │ │ │ │ + var crosses = 0; │ │ │ │ │ + for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ + start = this.components[i]; │ │ │ │ │ + x1 = approx(start.x, digs); │ │ │ │ │ + y1 = approx(start.y, digs); │ │ │ │ │ + end = this.components[i + 1]; │ │ │ │ │ + x2 = approx(end.x, digs); │ │ │ │ │ + y2 = approx(end.y, digs); │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * The following conditions enforce five edge-crossing rules: │ │ │ │ │ + * 1. points coincident with edges are considered contained; │ │ │ │ │ + * 2. an upward edge includes its starting endpoint, and │ │ │ │ │ + * excludes its final endpoint; │ │ │ │ │ + * 3. a downward edge excludes its starting endpoint, and │ │ │ │ │ + * includes its final endpoint; │ │ │ │ │ + * 4. horizontal edges are excluded; and │ │ │ │ │ + * 5. the edge-ray intersection point must be strictly right │ │ │ │ │ + * of the point P. │ │ │ │ │ + */ │ │ │ │ │ + if (y1 == y2) { │ │ │ │ │ + // horizontal edge │ │ │ │ │ + if (py == y1) { │ │ │ │ │ + // point on horizontal line │ │ │ │ │ + if (x1 <= x2 && (px >= x1 && px <= x2) || // right or vert │ │ │ │ │ + x1 >= x2 && (px <= x1 && px >= x2)) { // left or vert │ │ │ │ │ + // point on edge │ │ │ │ │ + crosses = -1; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - if (options.featureNS) { │ │ │ │ │ - node.setAttribute("xmlns:" + prefix, options.featureNS); │ │ │ │ │ } │ │ │ │ │ - if (options.propertyNames) { │ │ │ │ │ - for (var i = 0, len = options.propertyNames.length; i < len; i++) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "wfs:PropertyName", { │ │ │ │ │ - property: options.propertyNames[i] │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + // ignore other horizontal edges │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + cx = approx(getX(py, x1, y1, x2, y2), digs); │ │ │ │ │ + if (cx == px) { │ │ │ │ │ + // point on line │ │ │ │ │ + if (y1 < y2 && (py >= y1 && py <= y2) || // upward │ │ │ │ │ + y1 > y2 && (py <= y1 && py >= y2)) { // downward │ │ │ │ │ + // point on edge │ │ │ │ │ + crosses = -1; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - if (options.filter) { │ │ │ │ │ - OpenLayers.Format.WFST.v1_1_0.prototype.setFilterProperty.call(this, options.filter); │ │ │ │ │ - this.writeNode("ogc:Filter", options.filter, node); │ │ │ │ │ + } │ │ │ │ │ + if (cx <= px) { │ │ │ │ │ + // no crossing to the right │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) { │ │ │ │ │ + // no crossing │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (y1 < y2 && (py >= y1 && py < y2) || // upward │ │ │ │ │ + y1 > y2 && (py < y1 && py >= y2)) { // downward │ │ │ │ │ + ++crosses; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var contained = (crosses == -1) ? │ │ │ │ │ + // on edge │ │ │ │ │ + 1 : │ │ │ │ │ + // even (out) or odd (in) │ │ │ │ │ + !!(crosses & 1); │ │ │ │ │ + │ │ │ │ │ + return contained; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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.containsPoint(geometry); │ │ │ │ │ + } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString") { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ + } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ + intersect = OpenLayers.Geometry.LineString.prototype.intersects.apply( │ │ │ │ │ + this, [geometry] │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + // check for component intersections │ │ │ │ │ + for (var i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + intersect = geometry.components[i].intersects(this); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyName": function(obj) { │ │ │ │ │ - return this.createElementNSPlus("wfs:PropertyName", { │ │ │ │ │ - value: obj.property │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"], │ │ │ │ │ - "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"] │ │ │ │ │ + } │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0" │ │ │ │ │ + /** │ │ │ │ │ + * 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 (nodes === true) ? [] : this.components.slice(0, this.components.length - 1); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.LinearRing" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WPSExecute.js │ │ │ │ │ + OpenLayers/Geometry/Polygon.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 │ │ │ │ │ - * @requires OpenLayers/Format/WCSGetCoverage.js │ │ │ │ │ - * @requires OpenLayers/Format/WFST/v1_1_0.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LinearRing.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WPSExecute version 1.0.0 │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Geometry.Polygon │ │ │ │ │ + * Polygon is a collection of Geometry.LinearRings. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, │ │ │ │ │ - OpenLayers.Format.Filter.v1_1_0, { │ │ │ │ │ +OpenLayers.Geometry.Polygon = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ - gml: "http://www.opengis.net/gml", │ │ │ │ │ - wps: "http://www.opengis.net/wps/1.0.0", │ │ │ │ │ - wfs: "http://www.opengis.net/wfs", │ │ │ │ │ - ogc: "http://www.opengis.net/ogc", │ │ │ │ │ - wcs: "http://www.opengis.net/wcs", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ - }, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.LinearRing"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Polygon │ │ │ │ │ + * Constructor for a Polygon geometry. │ │ │ │ │ + * The first ring (this.component[0])is the outer bounds of the polygon and │ │ │ │ │ + * all subsequent rings (this.component[1-n]) are internal holes. │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.0.0 │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getArea │ │ │ │ │ + * Calculated by subtracting the areas of the internal holes from the │ │ │ │ │ + * area of the outer hole. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {float} The area of the geometry │ │ │ │ │ */ │ │ │ │ │ - VERSION: "1.0.0", │ │ │ │ │ + getArea: function() { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + if (this.components && (this.components.length > 0)) { │ │ │ │ │ + area += Math.abs(this.components[0].getArea()); │ │ │ │ │ + for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ + area -= Math.abs(this.components[i].getArea()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location │ │ │ │ │ + /** │ │ │ │ │ + * 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 polygon in square meters. │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd", │ │ │ │ │ - │ │ │ │ │ - schemaLocationAttr: function(options) { │ │ │ │ │ - return undefined; │ │ │ │ │ + getGeodesicArea: function(projection) { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + if (this.components && (this.components.length > 0)) { │ │ │ │ │ + area += Math.abs(this.components[0].getGeodesicArea(projection)); │ │ │ │ │ + for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ + area -= Math.abs(this.components[i].getGeodesicArea(projection)); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WPSExecute │ │ │ │ │ + * Method: containsPoint │ │ │ │ │ + * Test if a point is inside a polygon. Points on a polygon edge are │ │ │ │ │ + * considered inside. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * point - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean | Number} The point is inside the polygon. Returns 1 if the │ │ │ │ │ + * point is on an edge. Returns boolean otherwise. │ │ │ │ │ */ │ │ │ │ │ + containsPoint: function(point) { │ │ │ │ │ + var numRings = this.components.length; │ │ │ │ │ + var contained = false; │ │ │ │ │ + if (numRings > 0) { │ │ │ │ │ + // check exterior ring - 1 means on edge, boolean otherwise │ │ │ │ │ + contained = this.components[0].containsPoint(point); │ │ │ │ │ + if (contained !== 1) { │ │ │ │ │ + if (contained && numRings > 1) { │ │ │ │ │ + // check interior rings │ │ │ │ │ + var hole; │ │ │ │ │ + for (var i = 1; i < numRings; ++i) { │ │ │ │ │ + hole = this.components[i].containsPoint(point); │ │ │ │ │ + if (hole) { │ │ │ │ │ + if (hole === 1) { │ │ │ │ │ + // on edge │ │ │ │ │ + contained = 1; │ │ │ │ │ + } else { │ │ │ │ │ + // in hole │ │ │ │ │ + contained = false; │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return contained; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object. │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} An WPS Execute request XML string. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - write: function(options) { │ │ │ │ │ - var doc; │ │ │ │ │ - if (window.ActiveXObject) { │ │ │ │ │ - doc = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ - this.xmldom = doc; │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + var i, len; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + intersect = this.containsPoint(geometry); │ │ │ │ │ + } else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString" || │ │ │ │ │ + geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ + // check if rings/linestrings intersect │ │ │ │ │ + for (i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + intersect = geometry.intersects(this.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!intersect) { │ │ │ │ │ + // check if this poly contains points of the ring/linestring │ │ │ │ │ + for (i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + intersect = this.containsPoint(geometry.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } else { │ │ │ │ │ - doc = document.implementation.createDocument("", "", null); │ │ │ │ │ + for (i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + intersect = this.intersects(geometry.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var node = this.writeNode("wps:Execute", options, doc); │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - node, this.namespaces.xsi, │ │ │ │ │ - "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ - ); │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ + // check case where this poly is wholly contained by another │ │ │ │ │ + if (!intersect && geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") { │ │ │ │ │ + // exterior ring points will be contained in the other geometry │ │ │ │ │ + var ring = this.components[0]; │ │ │ │ │ + for (i = 0, len = ring.components.length; i < len; ++i) { │ │ │ │ │ + intersect = geometry.containsPoint(ring.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Parse a WPS Execute and return an object with its information. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Object} │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - if (data && data.nodeType == 9) { │ │ │ │ │ - data = data.documentElement; │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var result; │ │ │ │ │ + // this is the case where we might not be looking for distance to edge │ │ │ │ │ + if (!edge && this.intersects(geometry)) { │ │ │ │ │ + result = 0; │ │ │ │ │ + } else { │ │ │ │ │ + result = OpenLayers.Geometry.Collection.prototype.distanceTo.apply( │ │ │ │ │ + this, [geometry, options] │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - var info = {}; │ │ │ │ │ - this.readNode(data, info); │ │ │ │ │ - return info; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "wps": { │ │ │ │ │ - "Execute": function(options) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Execute", { │ │ │ │ │ - attributes: { │ │ │ │ │ - version: this.VERSION, │ │ │ │ │ - service: 'WPS' │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:Identifier", options.identifier, node); │ │ │ │ │ - this.writeNode("wps:DataInputs", options.dataInputs, node); │ │ │ │ │ - this.writeNode("wps:ResponseForm", options.responseForm, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ResponseForm": function(responseForm) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:ResponseForm", {}); │ │ │ │ │ - if (responseForm.rawDataOutput) { │ │ │ │ │ - this.writeNode("wps:RawDataOutput", responseForm.rawDataOutput, node); │ │ │ │ │ - } │ │ │ │ │ - if (responseForm.responseDocument) { │ │ │ │ │ - this.writeNode("wps:ResponseDocument", responseForm.responseDocument, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ResponseDocument": function(responseDocument) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:ResponseDocument", { │ │ │ │ │ - attributes: { │ │ │ │ │ - storeExecuteResponse: responseDocument.storeExecuteResponse, │ │ │ │ │ - lineage: responseDocument.lineage, │ │ │ │ │ - status: responseDocument.status │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (responseDocument.outputs) { │ │ │ │ │ - for (var i = 0, len = responseDocument.outputs.length; i < len; i++) { │ │ │ │ │ - this.writeNode("wps:Output", responseDocument.outputs[i], node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Output": function(output) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Output", { │ │ │ │ │ - attributes: { │ │ │ │ │ - asReference: output.asReference, │ │ │ │ │ - mimeType: output.mimeType, │ │ │ │ │ - encoding: output.encoding, │ │ │ │ │ - schema: output.schema │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:Identifier", output.identifier, node); │ │ │ │ │ - this.writeNode("ows:Title", output.title, node); │ │ │ │ │ - this.writeNode("ows:Abstract", output["abstract"], node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "RawDataOutput": function(rawDataOutput) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:RawDataOutput", { │ │ │ │ │ - attributes: { │ │ │ │ │ - mimeType: rawDataOutput.mimeType, │ │ │ │ │ - encoding: rawDataOutput.encoding, │ │ │ │ │ - schema: rawDataOutput.schema │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.writeNode("ows:Identifier", rawDataOutput.identifier, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "DataInputs": function(dataInputs) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:DataInputs", {}); │ │ │ │ │ - for (var i = 0, ii = dataInputs.length; i < ii; ++i) { │ │ │ │ │ - this.writeNode("wps:Input", dataInputs[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Input": function(input) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Input", {}); │ │ │ │ │ - this.writeNode("ows:Identifier", input.identifier, node); │ │ │ │ │ - if (input.title) { │ │ │ │ │ - this.writeNode("ows:Title", input.title, node); │ │ │ │ │ - } │ │ │ │ │ - if (input.data) { │ │ │ │ │ - this.writeNode("wps:Data", input.data, node); │ │ │ │ │ - } │ │ │ │ │ - if (input.reference) { │ │ │ │ │ - this.writeNode("wps:Reference", input.reference, node); │ │ │ │ │ - } │ │ │ │ │ - if (input.boundingBoxData) { │ │ │ │ │ - this.writeNode("wps:BoundingBoxData", input.boundingBoxData, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Data": function(data) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Data", {}); │ │ │ │ │ - if (data.literalData) { │ │ │ │ │ - this.writeNode("wps:LiteralData", data.literalData, node); │ │ │ │ │ - } else if (data.complexData) { │ │ │ │ │ - this.writeNode("wps:ComplexData", data.complexData, node); │ │ │ │ │ - } else if (data.boundingBoxData) { │ │ │ │ │ - this.writeNode("ows:BoundingBox", data.boundingBoxData, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LiteralData": function(literalData) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:LiteralData", { │ │ │ │ │ - attributes: { │ │ │ │ │ - uom: literalData.uom │ │ │ │ │ - }, │ │ │ │ │ - value: literalData.value │ │ │ │ │ - }); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ComplexData": function(complexData) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:ComplexData", { │ │ │ │ │ - attributes: { │ │ │ │ │ - mimeType: complexData.mimeType, │ │ │ │ │ - encoding: complexData.encoding, │ │ │ │ │ - schema: complexData.schema │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - var data = complexData.value; │ │ │ │ │ - if (typeof data === "string") { │ │ │ │ │ - node.appendChild( │ │ │ │ │ - this.getXMLDoc().createCDATASection(complexData.value) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - node.appendChild(data); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Reference": function(reference) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Reference", { │ │ │ │ │ - attributes: { │ │ │ │ │ - mimeType: reference.mimeType, │ │ │ │ │ - "xlink:href": reference.href, │ │ │ │ │ - method: reference.method, │ │ │ │ │ - encoding: reference.encoding, │ │ │ │ │ - schema: reference.schema │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (reference.body) { │ │ │ │ │ - this.writeNode("wps:Body", reference.body, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "BoundingBoxData": function(node, obj) { │ │ │ │ │ - this.writers['ows']['BoundingBox'].apply(this, [node, obj, "wps:BoundingBoxData"]); │ │ │ │ │ - }, │ │ │ │ │ - "Body": function(body) { │ │ │ │ │ - var node = this.createElementNSPlus("wps:Body", {}); │ │ │ │ │ - if (body.wcs) { │ │ │ │ │ - this.writeNode("wcs:GetCoverage", body.wcs, node); │ │ │ │ │ - } else if (body.wfs) { │ │ │ │ │ - // OpenLayers.Format.WFST expects these to be on the │ │ │ │ │ - // instance and not in the options │ │ │ │ │ - this.featureType = body.wfs.featureType; │ │ │ │ │ - this.version = body.wfs.version; │ │ │ │ │ - this.writeNode("wfs:GetFeature", body.wfs, node); │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("wps:Execute", body, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "wcs": OpenLayers.Format.WCSGetCoverage.prototype.writers.wcs, │ │ │ │ │ - "wfs": OpenLayers.Format.WFST.v1_1_0.prototype.writers.wfs, │ │ │ │ │ - "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers.ogc, │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Polygon" │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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": { │ │ │ │ │ - "ExecuteResponse": function(node, obj) { │ │ │ │ │ - obj.executeResponse = { │ │ │ │ │ - lang: node.getAttribute("lang"), │ │ │ │ │ - statusLocation: node.getAttribute("statusLocation"), │ │ │ │ │ - serviceInstance: node.getAttribute("serviceInstance"), │ │ │ │ │ - service: node.getAttribute("service") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj.executeResponse); │ │ │ │ │ - }, │ │ │ │ │ - "Process": function(node, obj) { │ │ │ │ │ - obj.process = {}; │ │ │ │ │ - this.readChildNodes(node, obj.process); │ │ │ │ │ - }, │ │ │ │ │ - "Status": function(node, obj) { │ │ │ │ │ - obj.status = { │ │ │ │ │ - creationTime: node.getAttribute("creationTime") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj.status); │ │ │ │ │ - }, │ │ │ │ │ - "ProcessSucceeded": function(node, obj) { │ │ │ │ │ - obj.processSucceeded = true; │ │ │ │ │ - }, │ │ │ │ │ - "ProcessOutputs": function(node, processDescription) { │ │ │ │ │ - processDescription.processOutputs = []; │ │ │ │ │ - this.readChildNodes(node, processDescription.processOutputs); │ │ │ │ │ - }, │ │ │ │ │ - "Output": function(node, processOutputs) { │ │ │ │ │ - var output = {}; │ │ │ │ │ - this.readChildNodes(node, output); │ │ │ │ │ - processOutputs.push(output); │ │ │ │ │ - }, │ │ │ │ │ - "Reference": function(node, output) { │ │ │ │ │ - output.reference = { │ │ │ │ │ - href: node.getAttribute("href"), │ │ │ │ │ - mimeType: node.getAttribute("mimeType"), │ │ │ │ │ - encoding: node.getAttribute("encoding"), │ │ │ │ │ - schema: node.getAttribute("schema") │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - "Data": function(node, output) { │ │ │ │ │ - output.data = {}; │ │ │ │ │ - this.readChildNodes(node, output); │ │ │ │ │ - }, │ │ │ │ │ - "LiteralData": function(node, output) { │ │ │ │ │ - output.literalData = { │ │ │ │ │ - dataType: node.getAttribute("dataType"), │ │ │ │ │ - uom: node.getAttribute("uom"), │ │ │ │ │ - value: this.getChildValue(node) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - "ComplexData": function(node, output) { │ │ │ │ │ - output.complexData = { │ │ │ │ │ - mimeType: node.getAttribute("mimeType"), │ │ │ │ │ - schema: node.getAttribute("schema"), │ │ │ │ │ - encoding: node.getAttribute("encoding"), │ │ │ │ │ - value: "" │ │ │ │ │ - }; │ │ │ │ │ +/** │ │ │ │ │ + * APIMethod: createRegularPolygon │ │ │ │ │ + * Create a regular polygon around a radius. Useful for creating circles │ │ │ │ │ + * and the like. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * origin - {} center of polygon. │ │ │ │ │ + * radius - {Float} distance to vertex, in map units. │ │ │ │ │ + * sides - {Integer} Number of sides. 20 approximates a circle. │ │ │ │ │ + * rotation - {Float} original angle of rotation, in degrees. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) { │ │ │ │ │ + var angle = Math.PI * ((1 / sides) - (1 / 2)); │ │ │ │ │ + if (rotation) { │ │ │ │ │ + angle += (rotation / 180) * Math.PI; │ │ │ │ │ + } │ │ │ │ │ + var rotatedAngle, x, y; │ │ │ │ │ + var points = []; │ │ │ │ │ + for (var i = 0; i < sides; ++i) { │ │ │ │ │ + rotatedAngle = angle + (i * 2 * Math.PI / sides); │ │ │ │ │ + x = origin.x + (radius * Math.cos(rotatedAngle)); │ │ │ │ │ + y = origin.y + (radius * Math.sin(rotatedAngle)); │ │ │ │ │ + points.push(new OpenLayers.Geometry.Point(x, y)); │ │ │ │ │ + } │ │ │ │ │ + var ring = new OpenLayers.Geometry.LinearRing(points); │ │ │ │ │ + return new OpenLayers.Geometry.Polygon([ring]); │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // try to get *some* value, ignore the empty text values │ │ │ │ │ - if (this.isSimpleContent(node)) { │ │ │ │ │ - var child; │ │ │ │ │ - for (child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - switch (child.nodeType) { │ │ │ │ │ - case 3: // text node │ │ │ │ │ - case 4: // cdata section │ │ │ │ │ - output.complexData.value += child.nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - for (child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ - if (child.nodeType == 1) { │ │ │ │ │ - output.complexData.value = child; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ - "BoundingBox": function(node, output) { │ │ │ │ │ - output.boundingBoxData = { │ │ │ │ │ - dimensions: node.getAttribute("dimensions"), │ │ │ │ │ - crs: node.getAttribute("crs") │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, output.boundingBoxData); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // TODO: we should add Exception parsing here │ │ │ │ │ - "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.MultiPolygon │ │ │ │ │ + * MultiPolygon is a geometry with multiple │ │ │ │ │ + * components. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.MultiPolygon = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WPSExecute" │ │ │ │ │ + /** │ │ │ │ │ + * 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.Polygon"], │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiPolygon │ │ │ │ │ + * Create a new MultiPolygon geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} An array of polygons │ │ │ │ │ + * used to generate the MultiPolygon │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiPolygon" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/WPSProcess.js │ │ │ │ │ + OpenLayers/Format/WKT.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/Geometry.js │ │ │ │ │ + * @requires OpenLayers/Format.js │ │ │ │ │ * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Format/WKT.js │ │ │ │ │ - * @requires OpenLayers/Format/GeoJSON.js │ │ │ │ │ - * @requires OpenLayers/Format/WPSExecute.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.WPSProcess │ │ │ │ │ - * Representation of a WPS process. Usually instances of │ │ │ │ │ - * are created by calling 'getProcess' on an │ │ │ │ │ - * instance. │ │ │ │ │ - * │ │ │ │ │ - * Currently supports processes that have geometries │ │ │ │ │ - * or features as output, using WKT or GeoJSON as output format. It also │ │ │ │ │ - * supports chaining of processes by using the method to create a │ │ │ │ │ - * handle that is used as process input instead of a static value. │ │ │ │ │ + * Class: OpenLayers.Format.WKT │ │ │ │ │ + * Class for reading and writing Well-Known Text. Create a new instance │ │ │ │ │ + * with the constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.WPSProcess = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: client │ │ │ │ │ - * {} The client that manages this process. │ │ │ │ │ - */ │ │ │ │ │ - client: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: server │ │ │ │ │ - * {String} Local client identifier for this process's server. │ │ │ │ │ - */ │ │ │ │ │ - server: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: identifier │ │ │ │ │ - * {String} Process identifier known to the server. │ │ │ │ │ - */ │ │ │ │ │ - identifier: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {Object} DescribeProcess response for this process. │ │ │ │ │ - */ │ │ │ │ │ - description: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: localWPS │ │ │ │ │ - * {String} Service endpoint for locally chained WPS processes. Default is │ │ │ │ │ - * 'http://geoserver/wps'. │ │ │ │ │ - */ │ │ │ │ │ - localWPS: 'http://geoserver/wps', │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: formats │ │ │ │ │ - * {Object} OpenLayers.Format instances keyed by mimetype. │ │ │ │ │ - */ │ │ │ │ │ - formats: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: chained │ │ │ │ │ - * {Integer} Number of chained processes for pending execute requests that │ │ │ │ │ - * don't have a full configuration yet. │ │ │ │ │ - */ │ │ │ │ │ - chained: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: executeCallbacks │ │ │ │ │ - * {Array} Callbacks waiting to be executed until all chained processes │ │ │ │ │ - * are configured; │ │ │ │ │ - */ │ │ │ │ │ - executeCallbacks: null, │ │ │ │ │ +OpenLayers.Format.WKT = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.WPSProcess │ │ │ │ │ + * Constructor: OpenLayers.Format.WKT │ │ │ │ │ + * Create a new parser for WKT │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance │ │ │ │ │ * │ │ │ │ │ - * Avaliable options: │ │ │ │ │ - * client - {} Mandatory. Client that manages this │ │ │ │ │ - * process. │ │ │ │ │ - * server - {String} Mandatory. Local client identifier of this process's │ │ │ │ │ - * server. │ │ │ │ │ - * identifier - {String} Mandatory. Process identifier known to the server. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A new WKT parser. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.executeCallbacks = []; │ │ │ │ │ - this.formats = { │ │ │ │ │ - 'application/wkt': new OpenLayers.Format.WKT(), │ │ │ │ │ - 'application/json': new OpenLayers.Format.GeoJSON() │ │ │ │ │ + this.regExes = { │ │ │ │ │ + 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/, │ │ │ │ │ + 'spaces': /\s+/, │ │ │ │ │ + 'parenComma': /\)\s*,\s*\(/, │ │ │ │ │ + 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here │ │ │ │ │ + 'trimParens': /^\s*\(?(.*?)\)?\s*$/ │ │ │ │ │ }; │ │ │ │ │ + OpenLayers.Format.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: describe │ │ │ │ │ - * Makes the client issue a DescribeProcess request asynchronously. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Deserialize a WKT string and return a vector feature or an │ │ │ │ │ + * array of vector features. Supports WKT for POINT, MULTIPOINT, │ │ │ │ │ + * LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, and │ │ │ │ │ + * GEOMETRYCOLLECTION. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Configuration for the method call │ │ │ │ │ + * wkt - {String} A WKT string │ │ │ │ │ * │ │ │ │ │ - * Available options: │ │ │ │ │ - * callback - {Function} Callback to execute when the description is │ │ │ │ │ - * available. Will be called with the parsed description as argument. │ │ │ │ │ - * Optional. │ │ │ │ │ - * scope - {Object} The scope in which the callback will be executed. │ │ │ │ │ - * Default is the global object. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {|Array} A feature or array of features for │ │ │ │ │ + * GEOMETRYCOLLECTION WKT. │ │ │ │ │ */ │ │ │ │ │ - describe: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - if (!this.description) { │ │ │ │ │ - this.client.describeProcess(this.server, this.identifier, function(description) { │ │ │ │ │ - if (!this.description) { │ │ │ │ │ - this.parseDescription(description); │ │ │ │ │ - } │ │ │ │ │ - if (options.callback) { │ │ │ │ │ - options.callback.call(options.scope, this.description); │ │ │ │ │ + read: function(wkt) { │ │ │ │ │ + var features, type, str; │ │ │ │ │ + wkt = wkt.replace(/[\n\r]/g, " "); │ │ │ │ │ + var matches = this.regExes.typeStr.exec(wkt); │ │ │ │ │ + if (matches) { │ │ │ │ │ + type = matches[1].toLowerCase(); │ │ │ │ │ + str = matches[2]; │ │ │ │ │ + if (this.parse[type]) { │ │ │ │ │ + features = this.parse[type].apply(this, [str]); │ │ │ │ │ + } │ │ │ │ │ + if (this.internalProjection && this.externalProjection) { │ │ │ │ │ + if (features && │ │ │ │ │ + features.CLASS_NAME == "OpenLayers.Feature.Vector") { │ │ │ │ │ + features.geometry.transform(this.externalProjection, │ │ │ │ │ + this.internalProjection); │ │ │ │ │ + } else if (features && │ │ │ │ │ + type != "geometrycollection" && │ │ │ │ │ + typeof features == "object") { │ │ │ │ │ + for (var i = 0, len = features.length; i < len; i++) { │ │ │ │ │ + var component = features[i]; │ │ │ │ │ + component.geometry.transform(this.externalProjection, │ │ │ │ │ + this.internalProjection); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - }, this); │ │ │ │ │ - } else if (options.callback) { │ │ │ │ │ - var description = this.description; │ │ │ │ │ - window.setTimeout(function() { │ │ │ │ │ - options.callback.call(options.scope, description); │ │ │ │ │ - }, 0); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return features; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: configure │ │ │ │ │ - * Configure the process, but do not execute it. Use this for processes │ │ │ │ │ - * that are chained as input of a different process by means of the │ │ │ │ │ - * method. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Serialize a feature or array of features into a WKT string. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * features - {|Array} A feature or array of │ │ │ │ │ + * features │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} this process. │ │ │ │ │ - * │ │ │ │ │ - * Available options: │ │ │ │ │ - * 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. │ │ │ │ │ - * callback - {Function} Callback to call when the configuration is │ │ │ │ │ - * complete. Optional. │ │ │ │ │ - * scope - {Object} Optional scope for the callback. │ │ │ │ │ + * {String} The WKT string representation of the input geometries │ │ │ │ │ */ │ │ │ │ │ - configure: function(options) { │ │ │ │ │ - this.describe({ │ │ │ │ │ - callback: function() { │ │ │ │ │ - var description = this.description, │ │ │ │ │ - inputs = options.inputs, │ │ │ │ │ - input, i, ii; │ │ │ │ │ - for (i = 0, ii = description.dataInputs.length; i < ii; ++i) { │ │ │ │ │ - input = description.dataInputs[i]; │ │ │ │ │ - this.setInputData(input, inputs[input.identifier]); │ │ │ │ │ - } │ │ │ │ │ - if (options.callback) { │ │ │ │ │ - options.callback.call(options.scope); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - return this; │ │ │ │ │ + write: function(features) { │ │ │ │ │ + var collection, geometry, isCollection; │ │ │ │ │ + if (features.constructor == Array) { │ │ │ │ │ + collection = features; │ │ │ │ │ + isCollection = true; │ │ │ │ │ + } else { │ │ │ │ │ + collection = [features]; │ │ │ │ │ + isCollection = false; │ │ │ │ │ + } │ │ │ │ │ + var pieces = []; │ │ │ │ │ + if (isCollection) { │ │ │ │ │ + pieces.push('GEOMETRYCOLLECTION('); │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = collection.length; i < len; ++i) { │ │ │ │ │ + if (isCollection && i > 0) { │ │ │ │ │ + pieces.push(','); │ │ │ │ │ + } │ │ │ │ │ + geometry = collection[i].geometry; │ │ │ │ │ + pieces.push(this.extractGeometry(geometry)); │ │ │ │ │ + } │ │ │ │ │ + if (isCollection) { │ │ │ │ │ + pieces.push(')'); │ │ │ │ │ + } │ │ │ │ │ + return pieces.join(''); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: execute │ │ │ │ │ - * Configures and executes the process │ │ │ │ │ + * Method: extractGeometry │ │ │ │ │ + * Entry point to construct the WKT for a single Geometry object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * geometry - {} │ │ │ │ │ * │ │ │ │ │ - * Available options: │ │ │ │ │ - * 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 the output to request and parse. │ │ │ │ │ - * Optional. If not provided, the first output will be requested. │ │ │ │ │ - * 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 │ │ │ │ │ - * (or 'result' if output was not configured). For processes that │ │ │ │ │ - * generate spatial output, the value will be an array of │ │ │ │ │ - * instances. │ │ │ │ │ - * scope - {Object} Optional scope for the success callback. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A WKT string of representing the geometry │ │ │ │ │ */ │ │ │ │ │ - execute: function(options) { │ │ │ │ │ - this.configure({ │ │ │ │ │ - inputs: options.inputs, │ │ │ │ │ - callback: function() { │ │ │ │ │ - var me = this; │ │ │ │ │ - //TODO For now we only deal with a single output │ │ │ │ │ - var outputIndex = this.getOutputIndex( │ │ │ │ │ - me.description.processOutputs, options.output │ │ │ │ │ - ); │ │ │ │ │ - me.setResponseForm({ │ │ │ │ │ - outputIndex: outputIndex │ │ │ │ │ - }); │ │ │ │ │ - (function callback() { │ │ │ │ │ - OpenLayers.Util.removeItem(me.executeCallbacks, callback); │ │ │ │ │ - if (me.chained !== 0) { │ │ │ │ │ - // need to wait until chained processes have a │ │ │ │ │ - // description and configuration - see chainProcess │ │ │ │ │ - me.executeCallbacks.push(callback); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - // all chained processes are added as references now, so │ │ │ │ │ - // let's proceed. │ │ │ │ │ - OpenLayers.Request.POST({ │ │ │ │ │ - url: me.client.servers[me.server].url, │ │ │ │ │ - data: new OpenLayers.Format.WPSExecute().write(me.description), │ │ │ │ │ - success: function(response) { │ │ │ │ │ - var output = me.description.processOutputs[outputIndex]; │ │ │ │ │ - var mimeType = me.findMimeType( │ │ │ │ │ - output.complexOutput.supported.formats │ │ │ │ │ - ); │ │ │ │ │ - //TODO For now we assume a spatial output │ │ │ │ │ - var features = me.formats[mimeType].read(response.responseText); │ │ │ │ │ - if (features instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - features = [features]; │ │ │ │ │ - } │ │ │ │ │ - if (options.success) { │ │ │ │ │ - var outputs = {}; │ │ │ │ │ - outputs[options.output || 'result'] = features; │ │ │ │ │ - options.success.call(options.scope, outputs); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - scope: me │ │ │ │ │ - }); │ │ │ │ │ - })(); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + extractGeometry: function(geometry) { │ │ │ │ │ + var type = geometry.CLASS_NAME.split('.')[2].toLowerCase(); │ │ │ │ │ + if (!this.extract[type]) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + if (this.internalProjection && this.externalProjection) { │ │ │ │ │ + geometry = geometry.clone(); │ │ │ │ │ + geometry.transform(this.internalProjection, this.externalProjection); │ │ │ │ │ + } │ │ │ │ │ + var wktType = type == 'collection' ? 'GEOMETRYCOLLECTION' : type.toUpperCase(); │ │ │ │ │ + var data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')'; │ │ │ │ │ + return data; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: output │ │ │ │ │ - * Chain an output of a configured process (see ) as input to │ │ │ │ │ - * another process. │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * intersect = client.getProcess('opengeo', 'JTS:intersection'); │ │ │ │ │ - * intersect.configure({ │ │ │ │ │ - * // ... │ │ │ │ │ - * }); │ │ │ │ │ - * buffer = client.getProcess('opengeo', 'JTS:buffer'); │ │ │ │ │ - * buffer.execute({ │ │ │ │ │ - * inputs: { │ │ │ │ │ - * geom: intersect.output('result'), // <-- here we're chaining │ │ │ │ │ - * distance: 1 │ │ │ │ │ - * }, │ │ │ │ │ - * // ... │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * identifier - {String} Identifier of the output that we're chaining. If │ │ │ │ │ - * not provided, the first output will be used. │ │ │ │ │ + * Object with properties corresponding to the geometry types. │ │ │ │ │ + * Property values are functions that do the actual data extraction. │ │ │ │ │ */ │ │ │ │ │ - output: function(identifier) { │ │ │ │ │ - return new OpenLayers.WPSProcess.ChainLink({ │ │ │ │ │ - process: this, │ │ │ │ │ - output: identifier │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + extract: { │ │ │ │ │ + /** │ │ │ │ │ + * Return a space delimited string of point coordinates. │ │ │ │ │ + * @param {OpenLayers.Geometry.Point} point │ │ │ │ │ + * @returns {String} A string of coordinates representing the point │ │ │ │ │ + */ │ │ │ │ │ + 'point': function(point) { │ │ │ │ │ + return point.x + ' ' + point.y; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseDescription │ │ │ │ │ - * Parses the DescribeProcess response │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * description - {Object} │ │ │ │ │ - */ │ │ │ │ │ - parseDescription: function(description) { │ │ │ │ │ - var server = this.client.servers[this.server]; │ │ │ │ │ - this.description = new OpenLayers.Format.WPSDescribeProcess() │ │ │ │ │ - .read(server.processDescription[this.identifier]) │ │ │ │ │ - .processDescriptions[this.identifier]; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Return a comma delimited string of point coordinates from a multipoint. │ │ │ │ │ + * @param {OpenLayers.Geometry.MultiPoint} multipoint │ │ │ │ │ + * @returns {String} A string of point coordinate strings representing │ │ │ │ │ + * the multipoint │ │ │ │ │ + */ │ │ │ │ │ + 'multipoint': function(multipoint) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multipoint.components.length; i < len; ++i) { │ │ │ │ │ + array.push('(' + │ │ │ │ │ + this.extract.point.apply(this, [multipoint.components[i]]) + │ │ │ │ │ + ')'); │ │ │ │ │ + } │ │ │ │ │ + return array.join(','); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setInputData │ │ │ │ │ - * Sets the data for a single input │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * input - {Object} An entry from the dataInputs array of the process │ │ │ │ │ - * description. │ │ │ │ │ - * data - {Mixed} For spatial data inputs, this is usually an │ │ │ │ │ - * , an or an array of │ │ │ │ │ - * geometries or features. │ │ │ │ │ - */ │ │ │ │ │ - setInputData: function(input, data) { │ │ │ │ │ - // clear any previous data │ │ │ │ │ - delete input.data; │ │ │ │ │ - delete input.reference; │ │ │ │ │ - if (data instanceof OpenLayers.WPSProcess.ChainLink) { │ │ │ │ │ - ++this.chained; │ │ │ │ │ - input.reference = { │ │ │ │ │ - method: 'POST', │ │ │ │ │ - href: data.process.server === this.server ? │ │ │ │ │ - this.localWPS : this.client.servers[data.process.server].url │ │ │ │ │ - }; │ │ │ │ │ - data.process.describe({ │ │ │ │ │ - callback: function() { │ │ │ │ │ - --this.chained; │ │ │ │ │ - this.chainProcess(input, data); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - input.data = {}; │ │ │ │ │ - var complexData = input.complexData; │ │ │ │ │ - if (complexData) { │ │ │ │ │ - var format = this.findMimeType(complexData.supported.formats); │ │ │ │ │ - input.data.complexData = { │ │ │ │ │ - mimeType: format, │ │ │ │ │ - value: this.formats[format].write(this.toFeatures(data)) │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - input.data.literalData = { │ │ │ │ │ - value: data │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Return a comma delimited string of point coordinates from a line. │ │ │ │ │ + * @param {OpenLayers.Geometry.LineString} linestring │ │ │ │ │ + * @returns {String} A string of point coordinate strings representing │ │ │ │ │ + * the linestring │ │ │ │ │ + */ │ │ │ │ │ + 'linestring': function(linestring) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = linestring.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.point.apply(this, [linestring.components[i]])); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + return array.join(','); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setResponseForm │ │ │ │ │ - * Sets the responseForm property of the payload. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} See below. │ │ │ │ │ - * │ │ │ │ │ - * Available options: │ │ │ │ │ - * outputIndex - {Integer} The index of the output to use. Optional. │ │ │ │ │ - * supportedFormats - {Object} Object with supported mime types as key, │ │ │ │ │ - * and true as value for supported types. Optional. │ │ │ │ │ - */ │ │ │ │ │ - setResponseForm: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - var output = this.description.processOutputs[options.outputIndex || 0]; │ │ │ │ │ - this.description.responseForm = { │ │ │ │ │ - rawDataOutput: { │ │ │ │ │ - identifier: output.identifier, │ │ │ │ │ - mimeType: this.findMimeType(output.complexOutput.supported.formats, options.supportedFormats) │ │ │ │ │ + /** │ │ │ │ │ + * Return a comma delimited string of linestring strings from a multilinestring. │ │ │ │ │ + * @param {OpenLayers.Geometry.MultiLineString} multilinestring │ │ │ │ │ + * @returns {String} A string of of linestring strings representing │ │ │ │ │ + * the multilinestring │ │ │ │ │ + */ │ │ │ │ │ + 'multilinestring': function(multilinestring) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multilinestring.components.length; i < len; ++i) { │ │ │ │ │ + array.push('(' + │ │ │ │ │ + this.extract.linestring.apply(this, [multilinestring.components[i]]) + │ │ │ │ │ + ')'); │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ + return array.join(','); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Return a comma delimited string of linear ring arrays from a polygon. │ │ │ │ │ + * @param {OpenLayers.Geometry.Polygon} polygon │ │ │ │ │ + * @returns {String} An array of linear ring arrays representing the polygon │ │ │ │ │ + */ │ │ │ │ │ + 'polygon': function(polygon) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = polygon.components.length; i < len; ++i) { │ │ │ │ │ + array.push('(' + │ │ │ │ │ + this.extract.linestring.apply(this, [polygon.components[i]]) + │ │ │ │ │ + ')'); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - output = 0; │ │ │ │ │ - } │ │ │ │ │ - return output; │ │ │ │ │ - }, │ │ │ │ │ + return array.join(','); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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](); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Return an array of polygon arrays from a multipolygon. │ │ │ │ │ + * @param {OpenLayers.Geometry.MultiPolygon} multipolygon │ │ │ │ │ + * @returns {String} An array of polygon arrays representing │ │ │ │ │ + * the multipolygon │ │ │ │ │ + */ │ │ │ │ │ + 'multipolygon': function(multipolygon) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multipolygon.components.length; i < len; ++i) { │ │ │ │ │ + array.push('(' + │ │ │ │ │ + this.extract.polygon.apply(this, [multipolygon.components[i]]) + │ │ │ │ │ + ')'); │ │ │ │ │ + } │ │ │ │ │ + return array.join(','); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an │ │ │ │ │ + * @param {OpenLayers.Geometry.Collection} collection │ │ │ │ │ + * @returns {String} internal WKT representation of the collection │ │ │ │ │ + */ │ │ │ │ │ + 'collection': function(collection) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = collection.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extractGeometry.apply(this, [collection.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array.join(','); │ │ │ │ │ } │ │ │ │ │ - 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. │ │ │ │ │ + * Object with properties corresponding to the geometry types. │ │ │ │ │ + * Property values are functions that do the actual parsing. │ │ │ │ │ */ │ │ │ │ │ - findMimeType: function(sourceFormats, targetFormats) { │ │ │ │ │ - targetFormats = targetFormats || this.formats; │ │ │ │ │ - for (var f in sourceFormats) { │ │ │ │ │ - if (f in targetFormats) { │ │ │ │ │ - return f; │ │ │ │ │ + parse: { │ │ │ │ │ + /** │ │ │ │ │ + * Return point feature given a point WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the point │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A point feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'point': function(str) { │ │ │ │ │ + var coords = OpenLayers.String.trim(str).split(this.regExes.spaces); │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Point(coords[0], coords[1]) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Return a multipoint feature given a multipoint WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the multipoint │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A multipoint feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'multipoint': function(str) { │ │ │ │ │ + var point; │ │ │ │ │ + var points = OpenLayers.String.trim(str).split(','); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = points.length; i < len; ++i) { │ │ │ │ │ + point = points[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ + components.push(this.parse.point.apply(this, [point]).geometry); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.MultiPoint(components) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.WPSProcess" │ │ │ │ │ + /** │ │ │ │ │ + * Return a linestring feature given a linestring WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the linestring │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A linestring feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'linestring': function(str) { │ │ │ │ │ + var points = OpenLayers.String.trim(str).split(','); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = points.length; i < len; ++i) { │ │ │ │ │ + components.push(this.parse.point.apply(this, [points[i]]).geometry); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.LineString(components) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ + /** │ │ │ │ │ + * Return a multilinestring feature given a multilinestring WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the multilinestring │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A multilinestring feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'multilinestring': function(str) { │ │ │ │ │ + var line; │ │ │ │ │ + var lines = OpenLayers.String.trim(str).split(this.regExes.parenComma); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = lines.length; i < len; ++i) { │ │ │ │ │ + line = lines[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ + components.push(this.parse.linestring.apply(this, [line]).geometry); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString(components) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ - * Type for chaining processes. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.WPSProcess.ChainLink = OpenLayers.Class({ │ │ │ │ │ + /** │ │ │ │ │ + * Return a polygon feature given a polygon WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the polygon │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A polygon feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'polygon': function(str) { │ │ │ │ │ + var ring, linestring, linearring; │ │ │ │ │ + var rings = OpenLayers.String.trim(str).split(this.regExes.parenComma); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = rings.length; i < len; ++i) { │ │ │ │ │ + ring = rings[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ + linestring = this.parse.linestring.apply(this, [ring]).geometry; │ │ │ │ │ + linearring = new OpenLayers.Geometry.LinearRing(linestring.components); │ │ │ │ │ + components.push(linearring); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Polygon(components) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: process │ │ │ │ │ - * {} The process to chain │ │ │ │ │ - */ │ │ │ │ │ - process: null, │ │ │ │ │ + /** │ │ │ │ │ + * Return a multipolygon feature given a multipolygon WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the multipolygon │ │ │ │ │ + * @returns {OpenLayers.Feature.Vector} A multipolygon feature │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'multipolygon': function(str) { │ │ │ │ │ + var polygon; │ │ │ │ │ + var polygons = OpenLayers.String.trim(str).split(this.regExes.doubleParenComma); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = polygons.length; i < len; ++i) { │ │ │ │ │ + polygon = polygons[i].replace(this.regExes.trimParens, '$1'); │ │ │ │ │ + components.push(this.parse.polygon.apply(this, [polygon]).geometry); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.MultiPolygon(components) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: output │ │ │ │ │ - * {String} The output identifier of the output we are going to use as │ │ │ │ │ - * input for another process. │ │ │ │ │ - */ │ │ │ │ │ - output: null, │ │ │ │ │ + /** │ │ │ │ │ + * Return an array of features given a geometrycollection WKT fragment. │ │ │ │ │ + * @param {String} str A WKT fragment representing the geometrycollection │ │ │ │ │ + * @returns {Array} An array of OpenLayers.Feature.Vector │ │ │ │ │ + * @private │ │ │ │ │ + */ │ │ │ │ │ + 'geometrycollection': function(str) { │ │ │ │ │ + // separate components of the collection with | │ │ │ │ │ + str = str.replace(/,\s*([A-Za-z])/g, '|$1'); │ │ │ │ │ + var wktArray = OpenLayers.String.trim(str).split('|'); │ │ │ │ │ + var components = []; │ │ │ │ │ + for (var i = 0, len = wktArray.length; i < len; ++i) { │ │ │ │ │ + components.push(OpenLayers.Format.WKT.prototype.read.apply(this, [wktArray[i]])); │ │ │ │ │ + } │ │ │ │ │ + return components; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WKT" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Popup.js │ │ │ │ │ + OpenLayers/Format/JSON.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 │ │ │ │ │ + * Note: │ │ │ │ │ + * This work draws heavily from the public domain JSON serializer/deserializer │ │ │ │ │ + * at http://www.json.org/json.js. Rewritten so that it doesn't modify │ │ │ │ │ + * basic data prototypes. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format.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. │ │ │ │ │ + * Class: OpenLayers.Format.JSON │ │ │ │ │ + * A parser to read/write JSON safely. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * popup = new OpenLayers.Popup("chicken", │ │ │ │ │ - * new OpenLayers.LonLat(5,40), │ │ │ │ │ - * new OpenLayers.Size(200,200), │ │ │ │ │ - * "example popup", │ │ │ │ │ - * true); │ │ │ │ │ - * │ │ │ │ │ - * map.addPopup(popup); │ │ │ │ │ - * (end) │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ +OpenLayers.Format.JSON = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minSize │ │ │ │ │ - * {} Minimum size allowed for the popup's contents. │ │ │ │ │ + * APIProperty: indent │ │ │ │ │ + * {String} For "pretty" printing, the indent string will be used once for │ │ │ │ │ + * each indentation level. │ │ │ │ │ */ │ │ │ │ │ - minSize: null, │ │ │ │ │ + indent: " ", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: space │ │ │ │ │ + * {String} For "pretty" printing, the space string will be used after │ │ │ │ │ + * the ":" separating a name/value pair. │ │ │ │ │ */ │ │ │ │ │ - disableFirefoxOverflowHack: false, │ │ │ │ │ + space: " ", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: newline │ │ │ │ │ + * {String} For "pretty" printing, the newline string will be used at the │ │ │ │ │ + * end of each name/value pair or array item. │ │ │ │ │ */ │ │ │ │ │ - fixPadding: function() { │ │ │ │ │ - if (typeof this.padding == "number") { │ │ │ │ │ - this.padding = new OpenLayers.Bounds( │ │ │ │ │ - this.padding, this.padding, this.padding, this.padding │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + newline: "\n", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: panMapIfOutOfView │ │ │ │ │ - * {Boolean} When drawn, pan map such that the entire popup is visible in │ │ │ │ │ - * the current viewport (if necessary). │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: level │ │ │ │ │ + * {Integer} For "pretty" printing, this is incremented/decremented during │ │ │ │ │ + * serialization. │ │ │ │ │ */ │ │ │ │ │ - panMapIfOutOfView: false, │ │ │ │ │ + level: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: pretty │ │ │ │ │ + * {Boolean} Serialize with extra whitespace for structure. This is set │ │ │ │ │ + * by the method. │ │ │ │ │ */ │ │ │ │ │ - keepInMap: false, │ │ │ │ │ + pretty: 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. │ │ │ │ │ + * Property: nativeJSON │ │ │ │ │ + * {Boolean} Does the browser support native json? │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ - }, │ │ │ │ │ + nativeJSON: (function() { │ │ │ │ │ + return !!(window.JSON && typeof JSON.parse == "function" && typeof JSON.stringify == "function"); │ │ │ │ │ + })(), │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.JSON │ │ │ │ │ + * Create a new parser for JSON. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - this.closeDiv = null; │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.groupDiv); │ │ │ │ │ - this.groupDiv = null; │ │ │ │ │ - │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.removePopup(this); │ │ │ │ │ - } │ │ │ │ │ - this.map = null; │ │ │ │ │ - this.div = null; │ │ │ │ │ - │ │ │ │ │ - this.autoSize = null; │ │ │ │ │ - this.minSize = null; │ │ │ │ │ - this.maxSize = null; │ │ │ │ │ - this.padding = null; │ │ │ │ │ - this.panMapIfOutOfView = null; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Constructs the elements that make up the popup. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Deserialize a json string. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} the position the popup in pixels. │ │ │ │ │ - * │ │ │ │ │ + * json - {String} A JSON string │ │ │ │ │ + * filter - {Function} A function which will be called for every key and │ │ │ │ │ + * value at every level of the final result. Each value will be │ │ │ │ │ + * replaced by the result of the filter function. This can be used to │ │ │ │ │ + * reform generic objects into instances of classes, or to transform │ │ │ │ │ + * date strings into Date objects. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} Reference to a div that contains the drawn popup │ │ │ │ │ + * {Object} An object, array, string, or number . │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - if (px == null) { │ │ │ │ │ - if ((this.lonlat != null) && (this.map != null)) { │ │ │ │ │ - px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + read: function(json, filter) { │ │ │ │ │ + var object; │ │ │ │ │ + if (this.nativeJSON) { │ │ │ │ │ + object = JSON.parse(json, filter); │ │ │ │ │ + } else try { │ │ │ │ │ + /** │ │ │ │ │ + * Parsing happens in three stages. In the first stage, we run the │ │ │ │ │ + * text against a regular expression which looks for non-JSON │ │ │ │ │ + * characters. We are especially concerned with '()' and 'new' │ │ │ │ │ + * because they can cause invocation, and '=' because it can │ │ │ │ │ + * cause mutation. But just to be safe, we will reject all │ │ │ │ │ + * unexpected characters. │ │ │ │ │ + */ │ │ │ │ │ + if (/^[\],:{}\s]*$/.test(json.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * In the second stage we use the eval function to compile the │ │ │ │ │ + * text into a JavaScript structure. The '{' operator is │ │ │ │ │ + * subject to a syntactic ambiguity in JavaScript - it can │ │ │ │ │ + * begin a block or an object literal. We wrap the text in │ │ │ │ │ + * parens to eliminate the ambiguity. │ │ │ │ │ + */ │ │ │ │ │ + object = eval('(' + json + ')'); │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ + /** │ │ │ │ │ + * In the optional third stage, we recursively walk the new │ │ │ │ │ + * structure, passing each name/value pair to a filter │ │ │ │ │ + * function for possible transformation. │ │ │ │ │ + */ │ │ │ │ │ + if (typeof filter === 'function') { │ │ │ │ │ + function walk(k, v) { │ │ │ │ │ + if (v && typeof v === 'object') { │ │ │ │ │ + for (var i in v) { │ │ │ │ │ + if (v.hasOwnProperty(i)) { │ │ │ │ │ + v[i] = walk(i, v[i]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return filter(k, v); │ │ │ │ │ + } │ │ │ │ │ + object = walk('', object); │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - if (!this.autoSize && !this.size) { │ │ │ │ │ - this.setSize(this.contentSize); │ │ │ │ │ + } │ │ │ │ │ + } catch (e) { │ │ │ │ │ + // Fall through if the regexp test fails. │ │ │ │ │ } │ │ │ │ │ - this.setBackgroundColor(); │ │ │ │ │ - this.setOpacity(); │ │ │ │ │ - this.setBorder(); │ │ │ │ │ - this.setContentHTML(); │ │ │ │ │ │ │ │ │ │ - if (this.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ + if (this.keepData) { │ │ │ │ │ + this.data = object; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + return object; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Serialize an object into a JSON string. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} the top and left position of the popup div. │ │ │ │ │ + * value - {String} The object, array, string, number, boolean or date │ │ │ │ │ + * to be serialized. │ │ │ │ │ + * pretty - {Boolean} Structure the output with newlines and indentation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The JSON string representation of the input value. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ + write: function(value, pretty) { │ │ │ │ │ + this.pretty = !!pretty; │ │ │ │ │ + var json = null; │ │ │ │ │ + var type = typeof value; │ │ │ │ │ + if (this.serialize[type]) { │ │ │ │ │ + try { │ │ │ │ │ + json = (!this.pretty && this.nativeJSON) ? │ │ │ │ │ + JSON.stringify(value) : │ │ │ │ │ + this.serialize[type].apply(this, [value]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + OpenLayers.Console.error("Trouble serializing: " + err); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return json; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: visible │ │ │ │ │ + * Method: writeIndent │ │ │ │ │ + * Output an indentation string depending on the indentation level. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An appropriate indentation string. │ │ │ │ │ */ │ │ │ │ │ - toggle: function() { │ │ │ │ │ - if (this.visible()) { │ │ │ │ │ - this.hide(); │ │ │ │ │ - } else { │ │ │ │ │ - this.show(); │ │ │ │ │ + writeIndent: function() { │ │ │ │ │ + var pieces = []; │ │ │ │ │ + if (this.pretty) { │ │ │ │ │ + for (var i = 0; i < this.level; ++i) { │ │ │ │ │ + pieces.push(this.indent); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return pieces.join(''); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: show │ │ │ │ │ - * Makes the popup visible. │ │ │ │ │ + * Method: writeNewline │ │ │ │ │ + * Output a string representing a newline if in pretty printing mode. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representing a new line. │ │ │ │ │ */ │ │ │ │ │ - show: function() { │ │ │ │ │ - this.div.style.display = ''; │ │ │ │ │ - │ │ │ │ │ - if (this.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ - } │ │ │ │ │ + writeNewline: function() { │ │ │ │ │ + return (this.pretty) ? this.newline : ''; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: hide │ │ │ │ │ - * Makes the popup invisible. │ │ │ │ │ + * Method: writeSpace │ │ │ │ │ + * Output a string representing a space if in pretty printing mode. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A space. │ │ │ │ │ */ │ │ │ │ │ - hide: function() { │ │ │ │ │ - this.div.style.display = 'none'; │ │ │ │ │ + writeSpace: function() { │ │ │ │ │ + return (this.pretty) ? this.space : ''; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * Used to adjust the size of the popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * contentSize - {} the new size for the popup's │ │ │ │ │ - * contents div (in pixels). │ │ │ │ │ + * Property: serialize │ │ │ │ │ + * Object with properties corresponding to the serializable data types. │ │ │ │ │ + * Property values are functions that do the actual serializing. │ │ │ │ │ */ │ │ │ │ │ - setSize: function(contentSize) { │ │ │ │ │ - this.size = contentSize.clone(); │ │ │ │ │ + serialize: { │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.object │ │ │ │ │ + * Transform an object into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} The object to be serialized. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the object. │ │ │ │ │ + */ │ │ │ │ │ + 'object': function(object) { │ │ │ │ │ + // three special objects that we want to treat differently │ │ │ │ │ + if (object == null) { │ │ │ │ │ + return "null"; │ │ │ │ │ + } │ │ │ │ │ + if (object.constructor == Date) { │ │ │ │ │ + return this.serialize.date.apply(this, [object]); │ │ │ │ │ + } │ │ │ │ │ + if (object.constructor == Array) { │ │ │ │ │ + return this.serialize.array.apply(this, [object]); │ │ │ │ │ + } │ │ │ │ │ + var pieces = ['{']; │ │ │ │ │ + this.level += 1; │ │ │ │ │ + var key, keyJSON, valueJSON; │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ + var addComma = false; │ │ │ │ │ + for (key in object) { │ │ │ │ │ + if (object.hasOwnProperty(key)) { │ │ │ │ │ + // recursive calls need to allow for sub-classing │ │ │ │ │ + keyJSON = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ + [key, this.pretty]); │ │ │ │ │ + valueJSON = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ + [object[key], this.pretty]); │ │ │ │ │ + if (keyJSON != null && valueJSON != null) { │ │ │ │ │ + if (addComma) { │ │ │ │ │ + pieces.push(','); │ │ │ │ │ + } │ │ │ │ │ + pieces.push(this.writeNewline(), this.writeIndent(), │ │ │ │ │ + keyJSON, ':', this.writeSpace(), valueJSON); │ │ │ │ │ + addComma = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // take into account the popup's 'padding' property │ │ │ │ │ - this.fixPadding(); │ │ │ │ │ - wPadding += this.padding.left + this.padding.right; │ │ │ │ │ - hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ + this.level -= 1; │ │ │ │ │ + pieces.push(this.writeNewline(), this.writeIndent(), '}'); │ │ │ │ │ + return pieces.join(''); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // make extra space for the close div │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ - wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.array │ │ │ │ │ + * Transform an array into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Array} The array to be serialized │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the array. │ │ │ │ │ + */ │ │ │ │ │ + 'array': function(array) { │ │ │ │ │ + var json; │ │ │ │ │ + var pieces = ['[']; │ │ │ │ │ + this.level += 1; │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + // recursive calls need to allow for sub-classing │ │ │ │ │ + json = OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ + [array[i], this.pretty]); │ │ │ │ │ + if (json != null) { │ │ │ │ │ + if (i > 0) { │ │ │ │ │ + pieces.push(','); │ │ │ │ │ + } │ │ │ │ │ + pieces.push(this.writeNewline(), this.writeIndent(), json); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ - } │ │ │ │ │ + this.level -= 1; │ │ │ │ │ + pieces.push(this.writeNewline(), this.writeIndent(), ']'); │ │ │ │ │ + return pieces.join(''); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.string │ │ │ │ │ + * Transform a string into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * string - {String} The string to be serialized │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the string. │ │ │ │ │ + */ │ │ │ │ │ + 'string': function(string) { │ │ │ │ │ + // If the string contains no control characters, no quote characters, and no │ │ │ │ │ + // backslash characters, then we can simply slap some quotes around it. │ │ │ │ │ + // Otherwise we must also replace the offending characters with safe │ │ │ │ │ + // sequences. │ │ │ │ │ + var m = { │ │ │ │ │ + '\b': '\\b', │ │ │ │ │ + '\t': '\\t', │ │ │ │ │ + '\n': '\\n', │ │ │ │ │ + '\f': '\\f', │ │ │ │ │ + '\r': '\\r', │ │ │ │ │ + '"': '\\"', │ │ │ │ │ + '\\': '\\\\' │ │ │ │ │ + }; │ │ │ │ │ + if (/["\\\x00-\x1f]/.test(string)) { │ │ │ │ │ + return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) { │ │ │ │ │ + var c = m[b]; │ │ │ │ │ + if (c) { │ │ │ │ │ + return c; │ │ │ │ │ + } │ │ │ │ │ + c = b.charCodeAt(); │ │ │ │ │ + return '\\u00' + │ │ │ │ │ + Math.floor(c / 16).toString(16) + │ │ │ │ │ + (c % 16).toString(16); │ │ │ │ │ + }) + '"'; │ │ │ │ │ + } │ │ │ │ │ + return '"' + string + '"'; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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() { │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.number │ │ │ │ │ + * Transform a number into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * number - {Number} The number to be serialized. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the number. │ │ │ │ │ + */ │ │ │ │ │ + 'number': function(number) { │ │ │ │ │ + return isFinite(number) ? String(number) : "null"; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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 + │ │ │ │ │ - "
"; │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.boolean │ │ │ │ │ + * Transform a boolean into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bool - {Boolean} The boolean to be serialized. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the boolean. │ │ │ │ │ + */ │ │ │ │ │ + 'boolean': function(bool) { │ │ │ │ │ + return String(bool); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var containerElement = (this.map) ? this.map.div : document.body; │ │ │ │ │ - var realSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ - preparedHTML, null, { │ │ │ │ │ - displayClass: this.displayClass, │ │ │ │ │ - containerElement: containerElement │ │ │ │ │ + /** │ │ │ │ │ + * Method: serialize.object │ │ │ │ │ + * Transform a date into a JSON string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * date - {Date} The date to be serialized. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A JSON string representing the date. │ │ │ │ │ + */ │ │ │ │ │ + 'date': function(date) { │ │ │ │ │ + function format(number) { │ │ │ │ │ + // Format integers to have at least two digits. │ │ │ │ │ + return (number < 10) ? '0' + number : number; │ │ │ │ │ } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // is the "real" size of the div is safe to display in our map? │ │ │ │ │ - var safeSize = this.getSafeContentSize(realSize); │ │ │ │ │ + return '"' + date.getFullYear() + '-' + │ │ │ │ │ + format(date.getMonth() + 1) + '-' + │ │ │ │ │ + format(date.getDate()) + 'T' + │ │ │ │ │ + format(date.getHours()) + ':' + │ │ │ │ │ + format(date.getMinutes()) + ':' + │ │ │ │ │ + format(date.getSeconds()) + '"'; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.JSON" │ │ │ │ │ │ │ │ │ │ - } else { │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/GeoJSON.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // 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 │ │ │ │ │ - }; │ │ │ │ │ +/* 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 (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 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/JSON.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ + * @requires OpenLayers/Console.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.GeoJSON │ │ │ │ │ + * Read and write GeoJSON. Create a new parser with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { │ │ │ │ │ │ │ │ │ │ - newSize = this.getSafeContentSize(clippedSize); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.setSize(newSize); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: ignoreExtraDims │ │ │ │ │ + * {Boolean} Ignore dimensions higher than 2 when reading geometry │ │ │ │ │ + * coordinates. │ │ │ │ │ + */ │ │ │ │ │ + ignoreExtraDims: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setBackgroundColor │ │ │ │ │ - * Sets the background color of the popup. │ │ │ │ │ + * Constructor: OpenLayers.Format.GeoJSON │ │ │ │ │ + * Create a new parser for GeoJSON. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * color - {String} the background color. eg "#FFBBBB" │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - setBackgroundColor: function(color) { │ │ │ │ │ - if (color != undefined) { │ │ │ │ │ - this.backgroundColor = color; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.backgroundColor = this.backgroundColor; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Sets the opacity of the popup. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Deserialize a GeoJSON string. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ + * json - {String} A GeoJSON string │ │ │ │ │ + * type - {String} Optional string that determines the structure of │ │ │ │ │ + * the output. Supported values are "Geometry", "Feature", and │ │ │ │ │ + * "FeatureCollection". If absent or null, a default of │ │ │ │ │ + * "FeatureCollection" is assumed. │ │ │ │ │ + * filter - {Function} A function which will be called for every key and │ │ │ │ │ + * value at every level of the final result. Each value will be │ │ │ │ │ + * replaced by the result of the filter function. This can be used to │ │ │ │ │ + * reform generic objects into instances of classes, or to transform │ │ │ │ │ + * date strings into Date objects. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} The return depends on the value of the type argument. If type │ │ │ │ │ + * is "FeatureCollection" (the default), the return will be an array │ │ │ │ │ + * of . If type is "Geometry", the input json │ │ │ │ │ + * must represent a single geometry, and the return will be an │ │ │ │ │ + * . If type is "Feature", the input json must │ │ │ │ │ + * represent a single feature, and the return will be an │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - if (opacity != undefined) { │ │ │ │ │ - this.opacity = opacity; │ │ │ │ │ + read: function(json, type, filter) { │ │ │ │ │ + type = (type) ? type : "FeatureCollection"; │ │ │ │ │ + var results = null; │ │ │ │ │ + var obj = null; │ │ │ │ │ + if (typeof json == "string") { │ │ │ │ │ + obj = OpenLayers.Format.JSON.prototype.read.apply(this, │ │ │ │ │ + [json, filter]); │ │ │ │ │ + } else { │ │ │ │ │ + obj = json; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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 + ')'; │ │ │ │ │ + if (!obj) { │ │ │ │ │ + OpenLayers.Console.error("Bad JSON: " + json); │ │ │ │ │ + } else if (typeof(obj.type) != "string") { │ │ │ │ │ + OpenLayers.Console.error("Bad GeoJSON - no type: " + json); │ │ │ │ │ + } else if (this.isValidType(obj, type)) { │ │ │ │ │ + switch (type) { │ │ │ │ │ + case "Geometry": │ │ │ │ │ + try { │ │ │ │ │ + results = this.parseGeometry(obj); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + OpenLayers.Console.error(err); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case "Feature": │ │ │ │ │ + try { │ │ │ │ │ + results = this.parseFeature(obj); │ │ │ │ │ + results.type = "Feature"; │ │ │ │ │ + } catch (err) { │ │ │ │ │ + OpenLayers.Console.error(err); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case "FeatureCollection": │ │ │ │ │ + // for type FeatureCollection, we allow input to be any type │ │ │ │ │ + results = []; │ │ │ │ │ + switch (obj.type) { │ │ │ │ │ + case "Feature": │ │ │ │ │ + try { │ │ │ │ │ + results.push(this.parseFeature(obj)); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + results = null; │ │ │ │ │ + OpenLayers.Console.error(err); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case "FeatureCollection": │ │ │ │ │ + for (var i = 0, len = obj.features.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + results.push(this.parseFeature(obj.features[i])); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + results = null; │ │ │ │ │ + OpenLayers.Console.error(err); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + try { │ │ │ │ │ + var geom = this.parseGeometry(obj); │ │ │ │ │ + results.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + results = null; │ │ │ │ │ + OpenLayers.Console.error(err); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return results; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setBorder │ │ │ │ │ - * Sets the border style of the popup. │ │ │ │ │ + * Method: isValidType │ │ │ │ │ + * Check if a GeoJSON object is a valid representative of the given type. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * border - {String} The border style value. eg 2px │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The object is valid GeoJSON object of the given type. │ │ │ │ │ */ │ │ │ │ │ - setBorder: function(border) { │ │ │ │ │ - if (border != undefined) { │ │ │ │ │ - this.border = border; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.border = this.border; │ │ │ │ │ + isValidType: function(obj, type) { │ │ │ │ │ + var valid = false; │ │ │ │ │ + switch (type) { │ │ │ │ │ + case "Geometry": │ │ │ │ │ + if (OpenLayers.Util.indexOf( │ │ │ │ │ + ["Point", "MultiPoint", "LineString", "MultiLineString", │ │ │ │ │ + "Polygon", "MultiPolygon", "Box", "GeometryCollection" │ │ │ │ │ + ], │ │ │ │ │ + obj.type) == -1) { │ │ │ │ │ + // unsupported geometry type │ │ │ │ │ + OpenLayers.Console.error("Unsupported geometry type: " + │ │ │ │ │ + obj.type); │ │ │ │ │ + } else { │ │ │ │ │ + valid = true; │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case "FeatureCollection": │ │ │ │ │ + // allow for any type to be converted to a feature collection │ │ │ │ │ + valid = true; │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + // for Feature types must match │ │ │ │ │ + if (obj.type == type) { │ │ │ │ │ + valid = true; │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Console.error("Cannot convert types from " + │ │ │ │ │ + obj.type + " to " + type); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return valid; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setContentHTML │ │ │ │ │ - * Allows the user to set the HTML content of the popup. │ │ │ │ │ + * Method: parseFeature │ │ │ │ │ + * Convert a feature object from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * contentHTML - {String} HTML for the div. │ │ │ │ │ + * obj - {Object} An object created from a GeoJSON object │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A feature. │ │ │ │ │ */ │ │ │ │ │ - setContentHTML: function(contentHTML) { │ │ │ │ │ - │ │ │ │ │ - if (contentHTML != null) { │ │ │ │ │ - this.contentHTML = contentHTML; │ │ │ │ │ + parseFeature: function(obj) { │ │ │ │ │ + var feature, geometry, attributes, bbox; │ │ │ │ │ + attributes = (obj.properties) ? obj.properties : {}; │ │ │ │ │ + bbox = (obj.geometry && obj.geometry.bbox) || obj.bbox; │ │ │ │ │ + try { │ │ │ │ │ + geometry = this.parseGeometry(obj.geometry); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + // deal with bad geometries │ │ │ │ │ + throw err; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ + feature = new OpenLayers.Feature.Vector(geometry, attributes); │ │ │ │ │ + if (bbox) { │ │ │ │ │ + feature.bounds = OpenLayers.Bounds.fromArray(bbox); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ + if (obj.id) { │ │ │ │ │ + feature.fid = obj.id; │ │ │ │ │ + } │ │ │ │ │ + return feature; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: registerImageListeners │ │ │ │ │ - * Called when an image contained by the popup loaded. this function │ │ │ │ │ - * updates the popup size, then unregisters the image load listener. │ │ │ │ │ + * Method: parseGeometry │ │ │ │ │ + * Convert a geometry object from GeoJSON into an . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} An object created from a GeoJSON object │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + parseGeometry: function(obj) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + var geometry, collection = false; │ │ │ │ │ + if (obj.type == "GeometryCollection") { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(obj.geometries))) { │ │ │ │ │ + throw "GeometryCollection must have geometries array: " + obj; │ │ │ │ │ } │ │ │ │ │ - this.popup.updateSize(); │ │ │ │ │ - │ │ │ │ │ - if (this.popup.visible() && this.popup.panMapIfOutOfView) { │ │ │ │ │ - this.popup.panIntoView(); │ │ │ │ │ + var numGeom = obj.geometries.length; │ │ │ │ │ + var components = new Array(numGeom); │ │ │ │ │ + for (var i = 0; i < numGeom; ++i) { │ │ │ │ │ + components[i] = this.parseGeometry.apply( │ │ │ │ │ + this, [obj.geometries[i]] │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Event.observe(img, 'load', img._onImgLoad); │ │ │ │ │ + geometry = new OpenLayers.Geometry.Collection(components); │ │ │ │ │ + collection = true; │ │ │ │ │ + } else { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(obj.coordinates))) { │ │ │ │ │ + throw "Geometry must have coordinates array: " + obj; │ │ │ │ │ + } │ │ │ │ │ + if (!this.parseCoords[obj.type.toLowerCase()]) { │ │ │ │ │ + throw "Unsupported geometry type: " + obj.type; │ │ │ │ │ + } │ │ │ │ │ + try { │ │ │ │ │ + geometry = this.parseCoords[obj.type.toLowerCase()].apply( │ │ │ │ │ + this, [obj.coordinates] │ │ │ │ │ + ); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + // deal with bad coordinates │ │ │ │ │ + throw err; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + // We don't reproject collections because the children are reprojected │ │ │ │ │ + // for us when they are created. │ │ │ │ │ + if (this.internalProjection && this.externalProjection && !collection) { │ │ │ │ │ + geometry.transform(this.externalProjection, │ │ │ │ │ + this.internalProjection); │ │ │ │ │ + } │ │ │ │ │ + return geometry; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getSafeContentSize │ │ │ │ │ - * │ │ │ │ │ - * 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). │ │ │ │ │ + * Property: parseCoords │ │ │ │ │ + * Object with properties corresponding to the GeoJSON geometry types. │ │ │ │ │ + * Property values are functions that do the actual parsing. │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + parseCoords: { │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.point │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "point": function(array) { │ │ │ │ │ + if (this.ignoreExtraDims == false && │ │ │ │ │ + array.length != 2) { │ │ │ │ │ + throw "Only 2D points are supported: " + array; │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.Point(array[0], array[1]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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)); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.multipoint │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "multipoint": function(array) { │ │ │ │ │ + var points = []; │ │ │ │ │ + var p = null; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + p = this.parseCoords["point"].apply(this, [array[i]]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + throw err; │ │ │ │ │ + } │ │ │ │ │ + points.push(p); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.MultiPoint(points); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //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) { │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.linestring │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "linestring": function(array) { │ │ │ │ │ + var points = []; │ │ │ │ │ + var p = null; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + p = this.parseCoords["point"].apply(this, [array[i]]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + throw err; │ │ │ │ │ + } │ │ │ │ │ + points.push(p); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.LineString(points); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.multilinestring │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "multilinestring": function(array) { │ │ │ │ │ + var lines = []; │ │ │ │ │ + var l = null; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + l = this.parseCoords["linestring"].apply(this, [array[i]]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + throw err; │ │ │ │ │ } │ │ │ │ │ + lines.push(l); │ │ │ │ │ } │ │ │ │ │ + return new OpenLayers.Geometry.MultiLineString(lines); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var maxY = this.map.size.h - │ │ │ │ │ - this.map.paddingForPopups.top - │ │ │ │ │ - this.map.paddingForPopups.bottom - │ │ │ │ │ - hPadding - extraY; │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.polygon │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "polygon": function(array) { │ │ │ │ │ + var rings = []; │ │ │ │ │ + var r, l; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + l = this.parseCoords["linestring"].apply(this, [array[i]]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + throw err; │ │ │ │ │ + } │ │ │ │ │ + r = new OpenLayers.Geometry.LinearRing(l.components); │ │ │ │ │ + rings.push(r); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.Polygon(rings); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var maxX = this.map.size.w - │ │ │ │ │ - this.map.paddingForPopups.left - │ │ │ │ │ - this.map.paddingForPopups.right - │ │ │ │ │ - wPadding - extraX; │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.multipolygon │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "multipolygon": function(array) { │ │ │ │ │ + var polys = []; │ │ │ │ │ + var p = null; │ │ │ │ │ + for (var i = 0, len = array.length; i < len; ++i) { │ │ │ │ │ + try { │ │ │ │ │ + p = this.parseCoords["polygon"].apply(this, [array[i]]); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + throw err; │ │ │ │ │ + } │ │ │ │ │ + polys.push(p); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.MultiPolygon(polys); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - safeContentSize.w = Math.min(safeContentSize.w, maxX); │ │ │ │ │ - safeContentSize.h = Math.min(safeContentSize.h, maxY); │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseCoords.box │ │ │ │ │ + * Convert a coordinate array from GeoJSON into an │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * array - {Object} The coordinates array from the GeoJSON fragment. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + "box": function(array) { │ │ │ │ │ + if (array.length != 2) { │ │ │ │ │ + throw "GeoJSON box coordinates must have 2 elements"; │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.Polygon([ │ │ │ │ │ + new OpenLayers.Geometry.LinearRing([ │ │ │ │ │ + new OpenLayers.Geometry.Point(array[0][0], array[0][1]), │ │ │ │ │ + new OpenLayers.Geometry.Point(array[1][0], array[0][1]), │ │ │ │ │ + new OpenLayers.Geometry.Point(array[1][0], array[1][1]), │ │ │ │ │ + new OpenLayers.Geometry.Point(array[0][0], array[1][1]), │ │ │ │ │ + new OpenLayers.Geometry.Point(array[0][0], array[0][1]) │ │ │ │ │ + ]) │ │ │ │ │ + ]); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Serialize a feature, geometry, array of features into a GeoJSON string. │ │ │ │ │ * │ │ │ │ │ - * 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) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} An , , │ │ │ │ │ + * or an array of features. │ │ │ │ │ + * pretty - {Boolean} Structure the output with newlines and indentation. │ │ │ │ │ + * Default is false. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {String} The GeoJSON string representation of the input geometry, │ │ │ │ │ + * features, or array of features. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + write: function(obj, pretty) { │ │ │ │ │ + var geojson = { │ │ │ │ │ + "type": null │ │ │ │ │ + }; │ │ │ │ │ + if (OpenLayers.Util.isArray(obj)) { │ │ │ │ │ + geojson.type = "FeatureCollection"; │ │ │ │ │ + var numFeatures = obj.length; │ │ │ │ │ + geojson.features = new Array(numFeatures); │ │ │ │ │ + for (var i = 0; i < numFeatures; ++i) { │ │ │ │ │ + var element = obj[i]; │ │ │ │ │ + if (!element instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ + var msg = "FeatureCollection only supports collections " + │ │ │ │ │ + "of features: " + element; │ │ │ │ │ + throw msg; │ │ │ │ │ + } │ │ │ │ │ + geojson.features[i] = this.extract.feature.apply( │ │ │ │ │ + this, [element] │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //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 = ""; │ │ │ │ │ + } else if (obj.CLASS_NAME.indexOf("OpenLayers.Geometry") == 0) { │ │ │ │ │ + geojson = this.extract.geometry.apply(this, [obj]); │ │ │ │ │ + } else if (obj instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ + geojson = this.extract.feature.apply(this, [obj]); │ │ │ │ │ + if (obj.layer && obj.layer.projection) { │ │ │ │ │ + geojson.crs = this.createCRSObject(obj); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return contentDivPadding; │ │ │ │ │ + return OpenLayers.Format.JSON.prototype.write.apply(this, │ │ │ │ │ + [geojson, pretty]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addCloseBox │ │ │ │ │ - * │ │ │ │ │ + * Method: createCRSObject │ │ │ │ │ + * Create the CRS object for an object. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * callback - {Function} The callback to be called when the close button │ │ │ │ │ - * is clicked. │ │ │ │ │ + * object - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object which can be assigned to the crs property │ │ │ │ │ + * of a GeoJSON object. │ │ │ │ │ */ │ │ │ │ │ - addCloseBox: function(callback) { │ │ │ │ │ - │ │ │ │ │ - this.closeDiv = OpenLayers.Util.createDiv( │ │ │ │ │ - this.id + "_close", null, { │ │ │ │ │ - w: 17, │ │ │ │ │ - h: 17 │ │ │ │ │ + createCRSObject: function(object) { │ │ │ │ │ + var proj = object.layer.projection.toString(); │ │ │ │ │ + var crs = {}; │ │ │ │ │ + if (proj.match(/epsg:/i)) { │ │ │ │ │ + var code = parseInt(proj.substring(proj.indexOf(":") + 1)); │ │ │ │ │ + if (code == 4326) { │ │ │ │ │ + crs = { │ │ │ │ │ + "type": "name", │ │ │ │ │ + "properties": { │ │ │ │ │ + "name": "urn:ogc:def:crs:OGC:1.3:CRS84" │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + crs = { │ │ │ │ │ + "type": "name", │ │ │ │ │ + "properties": { │ │ │ │ │ + "name": "EPSG:" + code │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ - ); │ │ │ │ │ - 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)); │ │ │ │ │ + } │ │ │ │ │ + return crs; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panIntoView │ │ │ │ │ - * Pans the map such that the popup is totaly viewable (if necessary) │ │ │ │ │ + * Property: extract │ │ │ │ │ + * Object with properties corresponding to the GeoJSON types. │ │ │ │ │ + * Property values are functions that do the actual value extraction. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + extract: { │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.feature │ │ │ │ │ + * Return a partial GeoJSON object representing a single feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the point. │ │ │ │ │ + */ │ │ │ │ │ + 'feature': function(feature) { │ │ │ │ │ + var geom = this.extract.geometry.apply(this, [feature.geometry]); │ │ │ │ │ + var json = { │ │ │ │ │ + "type": "Feature", │ │ │ │ │ + "properties": feature.attributes, │ │ │ │ │ + "geometry": geom │ │ │ │ │ + }; │ │ │ │ │ + if (feature.fid != null) { │ │ │ │ │ + json.id = feature.fid; │ │ │ │ │ + } │ │ │ │ │ + return json; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.geometry │ │ │ │ │ + * Return a GeoJSON object representing a single geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the geometry. │ │ │ │ │ + */ │ │ │ │ │ + 'geometry': function(geometry) { │ │ │ │ │ + if (geometry == null) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + if (this.internalProjection && this.externalProjection) { │ │ │ │ │ + geometry = geometry.clone(); │ │ │ │ │ + geometry.transform(this.internalProjection, │ │ │ │ │ + this.externalProjection); │ │ │ │ │ + } │ │ │ │ │ + var geometryType = geometry.CLASS_NAME.split('.')[2]; │ │ │ │ │ + var data = this.extract[geometryType.toLowerCase()].apply(this, [geometry]); │ │ │ │ │ + var json; │ │ │ │ │ + if (geometryType == "Collection") { │ │ │ │ │ + json = { │ │ │ │ │ + "type": "GeometryCollection", │ │ │ │ │ + "geometries": data │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + json = { │ │ │ │ │ + "type": geometryType, │ │ │ │ │ + "coordinates": data │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var dx = origTL.x - newTL.x; │ │ │ │ │ - var dy = origTL.y - newTL.y; │ │ │ │ │ + return json; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.map.pan(dx, dy); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.point │ │ │ │ │ + * Return an array of coordinates from a point. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of coordinates representing the point. │ │ │ │ │ + */ │ │ │ │ │ + 'point': function(point) { │ │ │ │ │ + return [point.x, point.y]; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: registerEvents │ │ │ │ │ - * Registers events on the popup. │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - registerEvents: function() { │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div, null, true); │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.multipoint │ │ │ │ │ + * Return an array of point coordinates from a multipoint. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * multipoint - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of point coordinate arrays representing │ │ │ │ │ + * the multipoint. │ │ │ │ │ + */ │ │ │ │ │ + 'multipoint': function(multipoint) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multipoint.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.point.apply(this, [multipoint.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.linestring │ │ │ │ │ + * Return an array of coordinate arrays from a linestring. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * linestring - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of coordinate arrays representing │ │ │ │ │ + * the linestring. │ │ │ │ │ + */ │ │ │ │ │ + 'linestring': function(linestring) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = linestring.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.point.apply(this, [linestring.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.multilinestring │ │ │ │ │ + * Return an array of linestring arrays from a linestring. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * multilinestring - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of linestring arrays representing │ │ │ │ │ + * the multilinestring. │ │ │ │ │ + */ │ │ │ │ │ + 'multilinestring': function(multilinestring) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multilinestring.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.linestring.apply(this, [multilinestring.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onmousedown: function(evt) { │ │ │ │ │ - this.mousedown = true; │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.polygon │ │ │ │ │ + * Return an array of linear ring arrays from a polygon. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * polygon - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of linear ring arrays representing the polygon. │ │ │ │ │ + */ │ │ │ │ │ + 'polygon': function(polygon) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = polygon.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.linestring.apply(this, [polygon.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.multipolygon │ │ │ │ │ + * Return an array of polygon arrays from a multipolygon. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * multipolygon - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of polygon arrays representing │ │ │ │ │ + * the multipolygon │ │ │ │ │ + */ │ │ │ │ │ + 'multipolygon': function(multipolygon) { │ │ │ │ │ + var array = []; │ │ │ │ │ + for (var i = 0, len = multipolygon.components.length; i < len; ++i) { │ │ │ │ │ + array.push(this.extract.polygon.apply(this, [multipolygon.components[i]])); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ + /** │ │ │ │ │ + * Method: extract.collection │ │ │ │ │ + * Return an array of geometries from a geometry collection. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * collection - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of geometry objects representing the geometry │ │ │ │ │ + * collection. │ │ │ │ │ + */ │ │ │ │ │ + 'collection': function(collection) { │ │ │ │ │ + var len = collection.components.length; │ │ │ │ │ + var array = new Array(len); │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + array[i] = this.extract.geometry.apply( │ │ │ │ │ + this, [collection.components[i]] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return array; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onclick │ │ │ │ │ - * Ignore clicks, but allowing default browser handling │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onmouseout: function(evt) { │ │ │ │ │ - this.mousedown = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: ondblclick │ │ │ │ │ - * Ignore double-clicks, but allowing default browser handling │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - ondblclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.GeoJSON" │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ -OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ -OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ -OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ -OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control.js │ │ │ │ │ + OpenLayers/Format/XML.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/Format.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: │ │ │ │ │ + * Class: OpenLayers.Format.XML │ │ │ │ │ + * Read and write XML. For cross-browser XML generation, use methods on an │ │ │ │ │ + * instance of the XML format class instead of on document. │ │ │ │ │ + * The DOM creation and traversing methods exposed here all mimic the │ │ │ │ │ + * W3C XML DOM methods. Create a new parser with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ - * > 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); │ │ │ │ │ - * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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: "", │ │ │ │ │ +OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: title │ │ │ │ │ - * {string} This property is used for showing a tooltip over the │ │ │ │ │ - * Control. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. Properties │ │ │ │ │ + * of this object should not be set individually. Read-only. All │ │ │ │ │ + * XML subclasses should have their own namespaces object. Use │ │ │ │ │ + * to add or set a namespace alias after construction. │ │ │ │ │ */ │ │ │ │ │ - title: "", │ │ │ │ │ + namespaces: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: namespaceAlias │ │ │ │ │ + * {Object} Mapping of namespace URI to namespace alias. This object │ │ │ │ │ + * is read-only. Use to add or set a namespace alias. │ │ │ │ │ */ │ │ │ │ │ - active: null, │ │ │ │ │ + namespaceAlias: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + * {String} The default namespace alias for creating element nodes. │ │ │ │ │ */ │ │ │ │ │ - handlerOptions: null, │ │ │ │ │ + defaultPrefix: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {} null │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + readers: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ + writers: {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: xmldom │ │ │ │ │ + * {XMLDom} If this browser uses ActiveX, this will be set to a XMLDOM │ │ │ │ │ + * object. It is not intended to be a browser sniffing property. │ │ │ │ │ + * Instead, the xmldom property is used instead of document │ │ │ │ │ + * where namespaced node creation methods are not supported. In all │ │ │ │ │ + * other browsers, this remains null. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + xmldom: 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}); │ │ │ │ │ + * Constructor: OpenLayers.Format.XML │ │ │ │ │ + * Construct an XML parser. The parser is used to read and write XML. │ │ │ │ │ + * Reading XML from a string returns a DOM element. Writing XML from │ │ │ │ │ + * a DOM element returns a string. │ │ │ │ │ * │ │ │ │ │ - * Overrides the default div attribute value of null. │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on │ │ │ │ │ + * the 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 (window.ActiveXObject) { │ │ │ │ │ + this.xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ } │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + OpenLayers.Format.prototype.initialize.apply(this, [options]); │ │ │ │ │ + // clone the namespace object and set all namespace aliases │ │ │ │ │ + this.namespaces = OpenLayers.Util.extend({}, this.namespaces); │ │ │ │ │ + this.namespaceAlias = {}; │ │ │ │ │ + for (var alias in this.namespaces) { │ │ │ │ │ + this.namespaceAlias[this.namespaces[alias]] = alias; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - if (this.events) { │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ + this.xmldom = null; │ │ │ │ │ + OpenLayers.Format.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // eliminate circular references │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ + /** │ │ │ │ │ + * Method: setNamespace │ │ │ │ │ + * Set a namespace alias and URI for the format. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * alias - {String} The namespace alias (prefix). │ │ │ │ │ + * uri - {String} The namespace URI. │ │ │ │ │ + */ │ │ │ │ │ + setNamespace: function(alias, uri) { │ │ │ │ │ + this.namespaces[alias] = uri; │ │ │ │ │ + this.namespaceAlias[uri] = alias; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Deserialize a XML string and return a DOM node. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * text - {String} A XML string │ │ │ │ │ + │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A DOM node │ │ │ │ │ + */ │ │ │ │ │ + read: function(text) { │ │ │ │ │ + var index = text.indexOf('<'); │ │ │ │ │ + if (index > 0) { │ │ │ │ │ + text = text.substring(index); │ │ │ │ │ } │ │ │ │ │ - if (this.handlers) { │ │ │ │ │ - for (var key in this.handlers) { │ │ │ │ │ - if (this.handlers.hasOwnProperty(key) && │ │ │ │ │ - typeof this.handlers[key].destroy == "function") { │ │ │ │ │ - this.handlers[key].destroy(); │ │ │ │ │ + var node = OpenLayers.Util.Try( │ │ │ │ │ + OpenLayers.Function.bind(( │ │ │ │ │ + function() { │ │ │ │ │ + var xmldom; │ │ │ │ │ + /** │ │ │ │ │ + * Since we want to be able to call this method on the prototype │ │ │ │ │ + * itself, this.xmldom may not exist even if in IE. │ │ │ │ │ + */ │ │ │ │ │ + if (window.ActiveXObject && !this.xmldom) { │ │ │ │ │ + xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ + } else { │ │ │ │ │ + xmldom = this.xmldom; │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ + xmldom.loadXML(text); │ │ │ │ │ + return xmldom; │ │ │ │ │ + } │ │ │ │ │ + ), this), │ │ │ │ │ + function() { │ │ │ │ │ + return new DOMParser().parseFromString(text, 'text/xml'); │ │ │ │ │ + }, │ │ │ │ │ + function() { │ │ │ │ │ + var req = new XMLHttpRequest(); │ │ │ │ │ + req.open("GET", "data:" + "text/xml" + │ │ │ │ │ + ";charset=utf-8," + encodeURIComponent(text), false); │ │ │ │ │ + if (req.overrideMimeType) { │ │ │ │ │ + req.overrideMimeType("text/xml"); │ │ │ │ │ } │ │ │ │ │ + req.send(null); │ │ │ │ │ + return req.responseXML; │ │ │ │ │ } │ │ │ │ │ - this.handlers = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.removeControl(this); │ │ │ │ │ - this.map = null; │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + if (this.keepData) { │ │ │ │ │ + this.data = node; │ │ │ │ │ } │ │ │ │ │ - this.div = null; │ │ │ │ │ + │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Serialize a DOM node into a XML string. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * node - {DOMElement} A DOM node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The XML string representation of the input node. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.setMap(map); │ │ │ │ │ + write: function(node) { │ │ │ │ │ + var data; │ │ │ │ │ + if (this.xmldom) { │ │ │ │ │ + data = node.xml; │ │ │ │ │ + } else { │ │ │ │ │ + var serializer = new XMLSerializer(); │ │ │ │ │ + if (node.nodeType == 1) { │ │ │ │ │ + // Add nodes to a document before serializing. Everything else │ │ │ │ │ + // is serialized as is. This may need more work. See #1218 . │ │ │ │ │ + var doc = document.implementation.createDocument("", "", null); │ │ │ │ │ + if (doc.importNode) { │ │ │ │ │ + node = doc.importNode(node, true); │ │ │ │ │ + } │ │ │ │ │ + doc.appendChild(node); │ │ │ │ │ + data = serializer.serializeToString(doc); │ │ │ │ │ + } else { │ │ │ │ │ + data = serializer.serializeToString(node); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return data; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: createElementNS │ │ │ │ │ + * Create a new element with namespace. This node can be appended to │ │ │ │ │ + * another node with the standard node.appendChild method. For │ │ │ │ │ + * cross-browser support, this method must be used instead of │ │ │ │ │ + * document.createElementNS. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} The top-left pixel position of the control │ │ │ │ │ - * or null. │ │ │ │ │ - * │ │ │ │ │ + * uri - {String} Namespace URI for the element. │ │ │ │ │ + * name - {String} The qualified name of the element (prefix:localname). │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ + * {Element} A DOM element with namespace. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + createElementNS: function(uri, name) { │ │ │ │ │ + var element; │ │ │ │ │ + if (this.xmldom) { │ │ │ │ │ + if (typeof uri == "string") { │ │ │ │ │ + element = this.xmldom.createNode(1, name, uri); │ │ │ │ │ + } else { │ │ │ │ │ + element = this.xmldom.createNode(1, name, ""); │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + element = document.createElementNS(uri, name); │ │ │ │ │ } │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.position = px.clone(); │ │ │ │ │ - } │ │ │ │ │ - this.moveTo(this.position); │ │ │ │ │ - return this.div; │ │ │ │ │ + return element; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ - * coordinates. │ │ │ │ │ + * APIMethod: createDocumentFragment │ │ │ │ │ + * Create a document fragment node that can be appended to another node │ │ │ │ │ + * created by createElementNS. This will call │ │ │ │ │ + * document.createDocumentFragment outside of IE. In IE, the ActiveX │ │ │ │ │ + * object's createDocumentFragment method is used. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Element} A document fragment. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ + createDocumentFragment: function() { │ │ │ │ │ + var element; │ │ │ │ │ + if (this.xmldom) { │ │ │ │ │ + element = this.xmldom.createDocumentFragment(); │ │ │ │ │ + } else { │ │ │ │ │ + element = document.createDocumentFragment(); │ │ │ │ │ } │ │ │ │ │ + return element; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: createTextNode │ │ │ │ │ + * Create a text node. This node can be appended to another node with │ │ │ │ │ + * the standard node.appendChild method. For cross-browser support, │ │ │ │ │ + * this method must be used instead of document.createTextNode. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the control was successfully activated or │ │ │ │ │ - * false if the control was already active. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * text - {String} The text of the node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A DOM text node. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.activate(); │ │ │ │ │ + createTextNode: function(text) { │ │ │ │ │ + var node; │ │ │ │ │ + if (typeof text !== "string") { │ │ │ │ │ + text = String(text); │ │ │ │ │ } │ │ │ │ │ - this.active = true; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, │ │ │ │ │ - this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ - ); │ │ │ │ │ + if (this.xmldom) { │ │ │ │ │ + node = this.xmldom.createTextNode(text); │ │ │ │ │ + } else { │ │ │ │ │ + node = document.createTextNode(text); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("activate"); │ │ │ │ │ - return true; │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivates a control and it's associated handler if any. The exact │ │ │ │ │ - * effect of this depends on the control itself. │ │ │ │ │ + * APIMethod: getElementsByTagNameNS │ │ │ │ │ + * Get a list of elements on a node given the namespace URI and local name. │ │ │ │ │ + * To return all nodes in a given namespace, use '*' for the name │ │ │ │ │ + * argument. To return all nodes of a given (local) name, regardless │ │ │ │ │ + * of namespace, use '*' for the uri argument. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {Element} Node on which to search for other nodes. │ │ │ │ │ + * uri - {String} Namespace URI. │ │ │ │ │ + * name - {String} Local name of the tag (without the prefix). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} True if the control was effectively deactivated or false │ │ │ │ │ - * if the control was already inactive. │ │ │ │ │ + * {NodeList} A node list or array of elements. │ │ │ │ │ */ │ │ │ │ │ - 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" │ │ │ │ │ - ); │ │ │ │ │ + getElementsByTagNameNS: function(node, uri, name) { │ │ │ │ │ + var elements = []; │ │ │ │ │ + if (node.getElementsByTagNameNS) { │ │ │ │ │ + elements = node.getElementsByTagNameNS(uri, name); │ │ │ │ │ + } else { │ │ │ │ │ + // brute force method │ │ │ │ │ + var allNodes = node.getElementsByTagName("*"); │ │ │ │ │ + var potentialNode, fullName; │ │ │ │ │ + for (var i = 0, len = allNodes.length; i < len; ++i) { │ │ │ │ │ + potentialNode = allNodes[i]; │ │ │ │ │ + fullName = (potentialNode.prefix) ? │ │ │ │ │ + (potentialNode.prefix + ":" + name) : name; │ │ │ │ │ + if ((name == "*") || (fullName == potentialNode.nodeName)) { │ │ │ │ │ + if ((uri == "*") || (uri == potentialNode.namespaceURI)) { │ │ │ │ │ + elements.push(potentialNode); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("deactivate"); │ │ │ │ │ - return true; │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ + return elements; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - 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/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({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: container │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - container: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: root │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - root: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: extent │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - extent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} cache of current map resolution │ │ │ │ │ - */ │ │ │ │ │ - resolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Property: featureDx │ │ │ │ │ - * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ - * applied to the current feature while rendering (see │ │ │ │ │ - * ). │ │ │ │ │ + * APIMethod: getAttributeNodeNS │ │ │ │ │ + * Get an attribute node given the namespace URI and local name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {Element} Node on which to search for attribute nodes. │ │ │ │ │ + * uri - {String} Namespace URI. │ │ │ │ │ + * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} An attribute node or null if none found. │ │ │ │ │ */ │ │ │ │ │ - featureDx: 0, │ │ │ │ │ + getAttributeNodeNS: function(node, uri, name) { │ │ │ │ │ + var attributeNode = null; │ │ │ │ │ + if (node.getAttributeNodeNS) { │ │ │ │ │ + attributeNode = node.getAttributeNodeNS(uri, name); │ │ │ │ │ + } else { │ │ │ │ │ + var attributes = node.attributes; │ │ │ │ │ + var potentialNode, fullName; │ │ │ │ │ + for (var i = 0, len = attributes.length; i < len; ++i) { │ │ │ │ │ + potentialNode = attributes[i]; │ │ │ │ │ + if (potentialNode.namespaceURI == uri) { │ │ │ │ │ + fullName = (potentialNode.prefix) ? │ │ │ │ │ + (potentialNode.prefix + ":" + name) : name; │ │ │ │ │ + if (fullName == potentialNode.nodeName) { │ │ │ │ │ + attributeNode = potentialNode; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return attributeNode; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Renderer │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getAttributeNS │ │ │ │ │ + * Get an attribute value given the namespace URI and local name. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * containerID - {} │ │ │ │ │ - * options - {Object} options for this renderer. See sublcasses for │ │ │ │ │ - * supported options. │ │ │ │ │ + * node - {Element} Node on which to search for an attribute. │ │ │ │ │ + * uri - {String} Namespace URI. │ │ │ │ │ + * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An attribute value or and empty string if none found. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(containerID, options) { │ │ │ │ │ - this.container = OpenLayers.Util.getElement(containerID); │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ + getAttributeNS: function(node, uri, name) { │ │ │ │ │ + var attributeValue = ""; │ │ │ │ │ + if (node.getAttributeNS) { │ │ │ │ │ + attributeValue = node.getAttributeNS(uri, name) || ""; │ │ │ │ │ + } else { │ │ │ │ │ + var attributeNode = this.getAttributeNodeNS(node, uri, name); │ │ │ │ │ + if (attributeNode) { │ │ │ │ │ + attributeValue = attributeNode.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return attributeValue; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * APIMethod: getChildValue │ │ │ │ │ + * Get the textual value of the node if it exists, or return an │ │ │ │ │ + * optional default string. Returns an empty string if no first child │ │ │ │ │ + * exists and no default value is supplied. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} The element used to look for a first child value. │ │ │ │ │ + * def - {String} Optional string to return in the event that no │ │ │ │ │ + * first child value exists. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The value of the first child of the given node. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.container = null; │ │ │ │ │ - this.extent = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.resolution = null; │ │ │ │ │ - this.map = null; │ │ │ │ │ + getChildValue: function(node, def) { │ │ │ │ │ + var value = def || ""; │ │ │ │ │ + if (node) { │ │ │ │ │ + for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + switch (child.nodeType) { │ │ │ │ │ + case 3: // text node │ │ │ │ │ + case 4: // cdata section │ │ │ │ │ + value += child.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: supported │ │ │ │ │ - * This should be overridden by specific subclasses │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: isSimpleContent │ │ │ │ │ + * Test if the given node has only simple content (i.e. no child element │ │ │ │ │ + * nodes). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} An element node. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ + * {Boolean} The node has no child element nodes (nodes of type 1). │ │ │ │ │ */ │ │ │ │ │ - supported: function() { │ │ │ │ │ - return false; │ │ │ │ │ + isSimpleContent: function(node) { │ │ │ │ │ + var simple = true; │ │ │ │ │ + for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + if (child.nodeType === 1) { │ │ │ │ │ + simple = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return simple; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: contentType │ │ │ │ │ + * Determine the content type for a given node. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * extent - {} │ │ │ │ │ - * resolutionChanged - {Boolean} │ │ │ │ │ + * node - {DOMElement} │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {Integer} One of OpenLayers.Format.XML.CONTENT_TYPE.{EMPTY,SIMPLE,COMPLEX,MIXED} │ │ │ │ │ + * if the node has no, simple, complex, or mixed content. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + contentType: function(node) { │ │ │ │ │ + var simple = false, │ │ │ │ │ + complex = false; │ │ │ │ │ + │ │ │ │ │ + var type = OpenLayers.Format.XML.CONTENT_TYPE.EMPTY; │ │ │ │ │ + │ │ │ │ │ + for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + switch (child.nodeType) { │ │ │ │ │ + case 1: // element │ │ │ │ │ + complex = true; │ │ │ │ │ + break; │ │ │ │ │ + case 8: // comment │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + simple = true; │ │ │ │ │ + } │ │ │ │ │ + if (complex && simple) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (resolutionChanged) { │ │ │ │ │ - this.resolution = null; │ │ │ │ │ + │ │ │ │ │ + if (complex && simple) { │ │ │ │ │ + type = OpenLayers.Format.XML.CONTENT_TYPE.MIXED; │ │ │ │ │ + } else if (complex) { │ │ │ │ │ + return OpenLayers.Format.XML.CONTENT_TYPE.COMPLEX; │ │ │ │ │ + } else if (simple) { │ │ │ │ │ + return OpenLayers.Format.XML.CONTENT_TYPE.SIMPLE; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return type; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * Sets the size of the drawing surface. │ │ │ │ │ + * APIMethod: hasAttributeNS │ │ │ │ │ + * Determine whether a node has a particular attribute matching the given │ │ │ │ │ + * name and namespace. │ │ │ │ │ * │ │ │ │ │ - * 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 - {} │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(size) { │ │ │ │ │ - this.size = size.clone(); │ │ │ │ │ - this.resolution = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getResolution │ │ │ │ │ - * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ + * node - {Element} Node on which to search for an attribute. │ │ │ │ │ + * uri - {String} Namespace URI. │ │ │ │ │ + * name - {String} Local name of the attribute (without the prefix). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The current map's resolution │ │ │ │ │ + * {Boolean} The node has an attribute matching the name and namespace. │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ - return this.resolution; │ │ │ │ │ + hasAttributeNS: function(node, uri, name) { │ │ │ │ │ + var found = false; │ │ │ │ │ + if (node.hasAttributeNS) { │ │ │ │ │ + found = node.hasAttributeNS(uri, name); │ │ │ │ │ + } else { │ │ │ │ │ + found = !!this.getAttributeNodeNS(node, uri, name); │ │ │ │ │ + } │ │ │ │ │ + return found; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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(). │ │ │ │ │ + * APIMethod: setAttributeNS │ │ │ │ │ + * Adds a new attribute or changes the value of an attribute with the given │ │ │ │ │ + * namespace and name. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * style - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ - * undefined if the feature had no geometry │ │ │ │ │ + * node - {Element} Element node on which to set the attribute. │ │ │ │ │ + * uri - {String} Namespace URI for the attribute. │ │ │ │ │ + * name - {String} Qualified name (prefix:localname) for the attribute. │ │ │ │ │ + * value - {String} Attribute value. │ │ │ │ │ */ │ │ │ │ │ - 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) { │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ + setAttributeNS: function(node, uri, name, value) { │ │ │ │ │ + if (node.setAttributeNS) { │ │ │ │ │ + node.setAttributeNS(uri, name, value); │ │ │ │ │ + } else { │ │ │ │ │ + if (this.xmldom) { │ │ │ │ │ + if (uri) { │ │ │ │ │ + var attribute = node.ownerDocument.createNode( │ │ │ │ │ + 2, name, uri │ │ │ │ │ + ); │ │ │ │ │ + attribute.nodeValue = value; │ │ │ │ │ + node.setAttributeNode(attribute); │ │ │ │ │ } else { │ │ │ │ │ - this.removeText(feature.id); │ │ │ │ │ + node.setAttribute(name, value); │ │ │ │ │ } │ │ │ │ │ - return rendered; │ │ │ │ │ + } else { │ │ │ │ │ + throw "setAttributeNS not implemented"; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: createElementNSPlus │ │ │ │ │ + * Shorthand for creating namespaced elements with optional attributes and │ │ │ │ │ + * child text nodes. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} Bounds of the feature │ │ │ │ │ - * worldBounds - {} Bounds of the world │ │ │ │ │ + * name - {String} The qualified node name. │ │ │ │ │ + * options - {Object} Optional object for node configuration. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * uri - {String} Optional namespace uri for the element - supply a prefix │ │ │ │ │ + * instead if the namespace uri is a property of the format's namespace │ │ │ │ │ + * object. │ │ │ │ │ + * attributes - {Object} Optional attributes to be set using the │ │ │ │ │ + * method. │ │ │ │ │ + * value - {String} Optional text to be appended as a text node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Element} An element node. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + createElementNSPlus: function(name, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + // order of prefix preference │ │ │ │ │ + // 1. in the uri option │ │ │ │ │ + // 2. in the prefix option │ │ │ │ │ + // 3. in the qualified name │ │ │ │ │ + // 4. from the defaultPrefix │ │ │ │ │ + var uri = options.uri || this.namespaces[options.prefix]; │ │ │ │ │ + if (!uri) { │ │ │ │ │ + var loc = name.indexOf(":"); │ │ │ │ │ + uri = this.namespaces[name.substring(0, loc)]; │ │ │ │ │ + } │ │ │ │ │ + if (!uri) { │ │ │ │ │ + uri = this.namespaces[this.defaultPrefix]; │ │ │ │ │ + } │ │ │ │ │ + var node = this.createElementNS(uri, name); │ │ │ │ │ + if (options.attributes) { │ │ │ │ │ + this.setAttributes(node, options.attributes); │ │ │ │ │ } │ │ │ │ │ + var value = options.value; │ │ │ │ │ + if (value != null) { │ │ │ │ │ + node.appendChild(this.createTextNode(value)); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawGeometry │ │ │ │ │ - * │ │ │ │ │ - * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ - * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ - * virtual function │ │ │ │ │ + /** │ │ │ │ │ + * Method: setAttributes │ │ │ │ │ + * Set multiple attributes given key value pairs from an object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * style - {Object} │ │ │ │ │ - * featureId - {} │ │ │ │ │ - */ │ │ │ │ │ - drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeText │ │ │ │ │ - * Function for removing text labels. │ │ │ │ │ - * This method is only called by the renderer itself. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featureId - {String} │ │ │ │ │ + * node - {Element} An element node. │ │ │ │ │ + * obj - {Object || Array} An object whose properties represent attribute │ │ │ │ │ + * names and values represent attribute values. If an attribute name │ │ │ │ │ + * is a qualified name ("prefix:local"), the prefix will be looked up │ │ │ │ │ + * in the parsers {namespaces} object. If the prefix is found, │ │ │ │ │ + * setAttributeNS will be used instead of setAttribute. │ │ │ │ │ */ │ │ │ │ │ - removeText: function(featureId) {}, │ │ │ │ │ + setAttributes: function(node, obj) { │ │ │ │ │ + var value, uri; │ │ │ │ │ + for (var name in obj) { │ │ │ │ │ + if (obj[name] != null && obj[name].toString) { │ │ │ │ │ + value = obj[name].toString(); │ │ │ │ │ + // check for qualified attribute name ("prefix:local") │ │ │ │ │ + uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; │ │ │ │ │ + this.setAttributeNS(node, uri, name, value); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Clear all vectors from the renderer. │ │ │ │ │ - * virtual function. │ │ │ │ │ + * Method: readNode │ │ │ │ │ + * Shorthand for applying one of the named readers given the node │ │ │ │ │ + * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ + * generally extend or modify the second. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} The node to be read (required). │ │ │ │ │ + * obj - {Object} The object to be modified (optional). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ */ │ │ │ │ │ - clear: function() {}, │ │ │ │ │ + readNode: function(node, obj) { │ │ │ │ │ + if (!obj) { │ │ │ │ │ + obj = {}; │ │ │ │ │ + } │ │ │ │ │ + var group = this.readers[node.namespaceURI ? this.namespaceAlias[node.namespaceURI] : this.defaultPrefix]; │ │ │ │ │ + if (group) { │ │ │ │ │ + var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ + var reader = group[local] || group["*"]; │ │ │ │ │ + if (reader) { │ │ │ │ │ + reader.apply(this, [node, obj]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: readChildNodes │ │ │ │ │ + * Shorthand for applying the named readers to all children of a node. │ │ │ │ │ + * For each child of type 1 (element), is called. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * node - {DOMElement} The node to be read (required). │ │ │ │ │ + * obj - {Object} The object to be modified (optional). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A feature id or undefined. │ │ │ │ │ + * {Object} The input object, modified. │ │ │ │ │ */ │ │ │ │ │ - getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ + readChildNodes: function(node, obj) { │ │ │ │ │ + if (!obj) { │ │ │ │ │ + obj = {}; │ │ │ │ │ + } │ │ │ │ │ + var children = node.childNodes; │ │ │ │ │ + var child; │ │ │ │ │ + for (var i = 0, len = children.length; i < len; ++i) { │ │ │ │ │ + child = children[i]; │ │ │ │ │ + if (child.nodeType == 1) { │ │ │ │ │ + this.readNode(child, obj); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: eraseFeatures │ │ │ │ │ - * This is called by the layer to erase features │ │ │ │ │ - * │ │ │ │ │ + * Method: writeNode │ │ │ │ │ + * Shorthand for applying one of the named writers and appending the │ │ │ │ │ + * results to a node. If a qualified name is not provided for the │ │ │ │ │ + * second argument (and a local name is used instead), the namespace │ │ │ │ │ + * of the parent node will be assumed. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ + * name - {String} The name of a node to generate. If a qualified name │ │ │ │ │ + * (e.g. "pre:Name") is used, the namespace prefix is assumed to be │ │ │ │ │ + * in the group. If a local name is used (e.g. "Name") then │ │ │ │ │ + * the namespace of the parent is assumed. If a local name is used │ │ │ │ │ + * and no parent is supplied, then the default namespace is assumed. │ │ │ │ │ + * obj - {Object} Structure containing data for the writer. │ │ │ │ │ + * parent - {DOMElement} Result will be appended to this node. If no parent │ │ │ │ │ + * is supplied, the node will not be appended to anything. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The child node. │ │ │ │ │ */ │ │ │ │ │ - eraseFeatures: function(features) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ + writeNode: function(name, obj, parent) { │ │ │ │ │ + var prefix, local; │ │ │ │ │ + var split = name.indexOf(":"); │ │ │ │ │ + if (split > 0) { │ │ │ │ │ + prefix = name.substring(0, split); │ │ │ │ │ + local = name.substring(split + 1); │ │ │ │ │ + } else { │ │ │ │ │ + if (parent) { │ │ │ │ │ + prefix = this.namespaceAlias[parent.namespaceURI]; │ │ │ │ │ + } else { │ │ │ │ │ + prefix = this.defaultPrefix; │ │ │ │ │ + } │ │ │ │ │ + local = name; │ │ │ │ │ } │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - var feature = features[i]; │ │ │ │ │ - this.eraseGeometry(feature.geometry, feature.id); │ │ │ │ │ - this.removeText(feature.id); │ │ │ │ │ + var child = this.writers[prefix][local].apply(this, [obj]); │ │ │ │ │ + if (parent) { │ │ │ │ │ + parent.appendChild(child); │ │ │ │ │ } │ │ │ │ │ + return child; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: eraseGeometry │ │ │ │ │ - * Remove a geometry from the renderer (by id). │ │ │ │ │ - * virtual function. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getChildEl │ │ │ │ │ + * Get the first child element. Optionally only return the first child │ │ │ │ │ + * if it matches the given name and namespace URI. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * featureId - {String} │ │ │ │ │ + * node - {DOMElement} The parent node. │ │ │ │ │ + * name - {String} Optional node name (local) to search for. │ │ │ │ │ + * uri - {String} Optional namespace URI to search for. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The first child. Returns null if no element is found, if │ │ │ │ │ + * something significant besides an element is found, or if the element │ │ │ │ │ + * found does not match the optional name and uri. │ │ │ │ │ */ │ │ │ │ │ - eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ + getChildEl: function(node, name, uri) { │ │ │ │ │ + return node && this.getThisOrNextEl(node.firstChild, name, uri); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getNextEl │ │ │ │ │ + * Get the next sibling element. Optionally get the first sibling only │ │ │ │ │ + * if it matches the given local name and namespace URI. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * renderer - {} target renderer for the moved root │ │ │ │ │ + * node - {DOMElement} The node. │ │ │ │ │ + * name - {String} Optional local name of the sibling to search for. │ │ │ │ │ + * uri - {String} Optional namespace URI of the sibling to search for. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The next sibling element. Returns null if no element is │ │ │ │ │ + * found, something significant besides an element is found, or the │ │ │ │ │ + * found element does not match the optional name and uri. │ │ │ │ │ */ │ │ │ │ │ - moveRoot: function(renderer) {}, │ │ │ │ │ + getNextEl: function(node, name, uri) { │ │ │ │ │ + return node && this.getThisOrNextEl(node.nextSibling, name, uri); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: getThisOrNextEl │ │ │ │ │ + * Return this node or the next element node. Optionally get the first │ │ │ │ │ + * sibling with the given local name or namespace URI. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} The node. │ │ │ │ │ + * name - {String} Optional local name of the sibling to search for. │ │ │ │ │ + * uri - {String} Optional namespace URI of the sibling to search for. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} the id of the output layer. │ │ │ │ │ + * {DOMElement} The next sibling element. Returns null if no element is │ │ │ │ │ + * found, something significant besides an element is found, or the │ │ │ │ │ + * found element does not match the query. │ │ │ │ │ */ │ │ │ │ │ - getRenderLayerId: function() { │ │ │ │ │ - return this.container.id; │ │ │ │ │ + getThisOrNextEl: function(node, name, uri) { │ │ │ │ │ + outer: for (var sibling = node; sibling; sibling = sibling.nextSibling) { │ │ │ │ │ + switch (sibling.nodeType) { │ │ │ │ │ + case 1: // Element │ │ │ │ │ + if ((!name || name === (sibling.localName || sibling.nodeName.split(":").pop())) && │ │ │ │ │ + (!uri || uri === sibling.namespaceURI)) { │ │ │ │ │ + // matches │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + sibling = null; │ │ │ │ │ + break outer; │ │ │ │ │ + case 3: // Text │ │ │ │ │ + if (/^\s*$/.test(sibling.nodeValue)) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + case 4: // CDATA │ │ │ │ │ + case 6: // ENTITY_NODE │ │ │ │ │ + case 12: // NOTATION_NODE │ │ │ │ │ + case 10: // DOCUMENT_TYPE_NODE │ │ │ │ │ + case 11: // DOCUMENT_FRAGMENT_NODE │ │ │ │ │ + sibling = null; │ │ │ │ │ + break outer; │ │ │ │ │ + } // ignore comments and processing instructions │ │ │ │ │ + } │ │ │ │ │ + return sibling || null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: applyDefaultSymbolizer │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: lookupNamespaceURI │ │ │ │ │ + * Takes a prefix and returns the namespace URI associated with it on the given │ │ │ │ │ + * node if found (and null if not). Supplying null for the prefix will │ │ │ │ │ + * return the default namespace. │ │ │ │ │ + * │ │ │ │ │ + * For browsers that support it, this calls the native lookupNamesapceURI │ │ │ │ │ + * function. In other browsers, this is an implementation of │ │ │ │ │ + * http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI. │ │ │ │ │ + * │ │ │ │ │ + * For browsers that don't support the attribute.ownerElement property, this │ │ │ │ │ + * method cannot be called on attribute nodes. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * symbolizer - {Object} │ │ │ │ │ + * node - {DOMElement} The node from which to start looking. │ │ │ │ │ + * prefix - {String} The prefix to lookup or null to lookup the default namespace. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} │ │ │ │ │ + * {String} The namespace URI for the given prefix. Returns null if the prefix │ │ │ │ │ + * cannot be found or the node is the wrong type. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + lookupNamespaceURI: function(node, prefix) { │ │ │ │ │ + var uri = null; │ │ │ │ │ + if (node) { │ │ │ │ │ + if (node.lookupNamespaceURI) { │ │ │ │ │ + uri = node.lookupNamespaceURI(prefix); │ │ │ │ │ + } else { │ │ │ │ │ + outer: switch (node.nodeType) { │ │ │ │ │ + case 1: // ELEMENT_NODE │ │ │ │ │ + if (node.namespaceURI !== null && node.prefix === prefix) { │ │ │ │ │ + uri = node.namespaceURI; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + var len = node.attributes.length; │ │ │ │ │ + if (len) { │ │ │ │ │ + var attr; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + attr = node.attributes[i]; │ │ │ │ │ + if (attr.prefix === "xmlns" && attr.name === "xmlns:" + prefix) { │ │ │ │ │ + uri = attr.value || null; │ │ │ │ │ + break outer; │ │ │ │ │ + } else if (attr.name === "xmlns" && prefix === null) { │ │ │ │ │ + uri = attr.value || null; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + uri = this.lookupNamespaceURI(node.parentNode, prefix); │ │ │ │ │ + break outer; │ │ │ │ │ + case 2: // ATTRIBUTE_NODE │ │ │ │ │ + uri = this.lookupNamespaceURI(node.ownerElement, prefix); │ │ │ │ │ + break outer; │ │ │ │ │ + case 9: // DOCUMENT_NODE │ │ │ │ │ + uri = this.lookupNamespaceURI(node.documentElement, prefix); │ │ │ │ │ + break outer; │ │ │ │ │ + case 6: // ENTITY_NODE │ │ │ │ │ + case 12: // NOTATION_NODE │ │ │ │ │ + case 10: // DOCUMENT_TYPE_NODE │ │ │ │ │ + case 11: // DOCUMENT_FRAGMENT_NODE │ │ │ │ │ + break outer; │ │ │ │ │ + default: │ │ │ │ │ + // TEXT_NODE (3), CDATA_SECTION_NODE (4), ENTITY_REFERENCE_NODE (5), │ │ │ │ │ + // PROCESSING_INSTRUCTION_NODE (7), COMMENT_NODE (8) │ │ │ │ │ + uri = this.lookupNamespaceURI(node.parentNode, prefix); │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return uri; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Renderer" │ │ │ │ │ + /** │ │ │ │ │ + * Method: getXMLDoc │ │ │ │ │ + * Get an XML document for nodes that are not supported in HTML (e.g. │ │ │ │ │ + * createCDATASection). On IE, this will either return an existing or │ │ │ │ │ + * create a new on the instance. On other browsers, this will │ │ │ │ │ + * either return an existing or create a new shared document (see │ │ │ │ │ + * ). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLDocument} │ │ │ │ │ + */ │ │ │ │ │ + getXMLDoc: function() { │ │ │ │ │ + if (!OpenLayers.Format.XML.document && !this.xmldom) { │ │ │ │ │ + if (document.implementation && document.implementation.createDocument) { │ │ │ │ │ + OpenLayers.Format.XML.document = │ │ │ │ │ + document.implementation.createDocument("", "", null); │ │ │ │ │ + } else if (!this.xmldom && window.ActiveXObject) { │ │ │ │ │ + this.xmldom = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Format.XML.document || this.xmldom; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.XML" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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' │ │ │ │ │ +OpenLayers.Format.XML.CONTENT_TYPE = { │ │ │ │ │ + EMPTY: 0, │ │ │ │ │ + SIMPLE: 1, │ │ │ │ │ + COMPLEX: 2, │ │ │ │ │ + MIXED: 3 │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: OpenLayers.Format.XML.lookupNamespaceURI │ │ │ │ │ + * Takes a prefix and returns the namespace URI associated with it on the given │ │ │ │ │ + * node if found (and null if not). Supplying null for the prefix will │ │ │ │ │ + * return the default namespace. │ │ │ │ │ + * │ │ │ │ │ + * For browsers that support it, this calls the native lookupNamesapceURI │ │ │ │ │ + * function. In other browsers, this is an implementation of │ │ │ │ │ + * http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI. │ │ │ │ │ + * │ │ │ │ │ + * For browsers that don't support the attribute.ownerElement property, this │ │ │ │ │ + * method cannot be called on attribute nodes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} The node from which to start looking. │ │ │ │ │ + * prefix - {String} The prefix to lookup or null to lookup the default namespace. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The namespace URI for the given prefix. Returns null if the prefix │ │ │ │ │ + * cannot be found or the node is the wrong type. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.XML.lookupNamespaceURI = OpenLayers.Function.bind( │ │ │ │ │ + OpenLayers.Format.XML.prototype.lookupNamespaceURI, │ │ │ │ │ + OpenLayers.Format.XML.prototype │ │ │ │ │ +); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: OpenLayers.Renderer.symbol │ │ │ │ │ - * Coordinate arrays for well known (named) symbols. │ │ │ │ │ + * Property: OpenLayers.Format.XML.document │ │ │ │ │ + * {XMLDocument} XML document to reuse for creating non-HTML compliant nodes, │ │ │ │ │ + * like document.createCDATASection. │ │ │ │ │ */ │ │ │ │ │ -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.Format.XML.document = null; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer.js │ │ │ │ │ + OpenLayers/Format/OGCExceptionReport.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/Format/XML.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer │ │ │ │ │ - * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ + * Class: OpenLayers.Format.OGCExceptionReport │ │ │ │ │ + * Class to read exception reports for various OGC services and versions. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Format.OGCExceptionReport = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + ogc: "http://www.opengis.net/ogc" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - zIndex: 0, │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + */ │ │ │ │ │ + defaultPrefix: "ogc", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.OGCExceptionReport │ │ │ │ │ + * Create a new parser for OGC exception reports. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read OGC exception report data from a string, and return an object with │ │ │ │ │ + * information about the exceptions. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new symbolizer. │ │ │ │ │ + * {Object} Information about the exceptions that occurred. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Util.extend(this, config); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + var result; │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + var root = data.documentElement; │ │ │ │ │ + var exceptionInfo = { │ │ │ │ │ + exceptionReport: null │ │ │ │ │ + }; │ │ │ │ │ + if (root) { │ │ │ │ │ + this.readChildNodes(data, exceptionInfo); │ │ │ │ │ + if (exceptionInfo.exceptionReport === null) { │ │ │ │ │ + // fall-back to OWSCommon since this is a common output format for exceptions │ │ │ │ │ + // we cannot easily use the ows readers directly since they differ for 1.0 and 1.1 │ │ │ │ │ + exceptionInfo = new OpenLayers.Format.OWSCommon().read(data); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return exceptionInfo; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a copy of this symbolizer. │ │ │ │ │ - * │ │ │ │ │ - * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var Type = eval(this.CLASS_NAME); │ │ │ │ │ - return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ + readers: { │ │ │ │ │ + "ogc": { │ │ │ │ │ + "ServiceExceptionReport": function(node, obj) { │ │ │ │ │ + obj.exceptionReport = { │ │ │ │ │ + exceptions: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ + }, │ │ │ │ │ + "ServiceException": function(node, exceptionReport) { │ │ │ │ │ + var exception = { │ │ │ │ │ + code: node.getAttribute("code"), │ │ │ │ │ + locator: node.getAttribute("locator"), │ │ │ │ │ + text: this.getChildValue(node) │ │ │ │ │ + }; │ │ │ │ │ + exceptionReport.exceptions.push(exception); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.OGCExceptionReport" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Rule.js │ │ │ │ │ + OpenLayers/Format/XML/VersionedOGC.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 │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Format/OGCExceptionReport.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Rule │ │ │ │ │ - * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ + * Class: OpenLayers.Format.XML.VersionedOGC │ │ │ │ │ + * Base class for versioned formats, i.e. a format which supports multiple │ │ │ │ │ + * versions. │ │ │ │ │ + * │ │ │ │ │ + * To enable checking if parsing succeeded, you will need to define a property │ │ │ │ │ + * called errorProperty on the parser you want to check. The parser will then │ │ │ │ │ + * check the returned object to see if that property is present. If it is, it │ │ │ │ │ + * assumes the parsing was successful. If it is not present (or is null), it will │ │ │ │ │ + * pass the document through an OGCExceptionReport parser. │ │ │ │ │ + * │ │ │ │ │ + * If errorProperty is undefined for the parser, this error checking mechanism │ │ │ │ │ + * will be disabled. │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ +OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ + * APIProperty: defaultVersion │ │ │ │ │ + * {String} Version number to assume if none found. │ │ │ │ │ */ │ │ │ │ │ - description: null, │ │ │ │ │ + defaultVersion: 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. │ │ │ │ │ + * APIProperty: version │ │ │ │ │ + * {String} Specify a version string if one is known. │ │ │ │ │ */ │ │ │ │ │ - context: null, │ │ │ │ │ + version: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} Optional filter for the rule. │ │ │ │ │ + * APIProperty: profile │ │ │ │ │ + * {String} If provided, use a custom profile. │ │ │ │ │ */ │ │ │ │ │ - filter: null, │ │ │ │ │ + profile: 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. │ │ │ │ │ + * APIProperty: allowFallback │ │ │ │ │ + * {Boolean} If a profiled parser cannot be found for the returned version, │ │ │ │ │ + * use a non-profiled parser as the fallback. Application code using this │ │ │ │ │ + * should take into account that the return object structure might be │ │ │ │ │ + * missing the specifics of the profile. Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - elseFilter: false, │ │ │ │ │ + allowFallback: 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. │ │ │ │ │ + * Property: name │ │ │ │ │ + * {String} The name of this parser, this is the part of the CLASS_NAME │ │ │ │ │ + * except for "OpenLayers.Format." │ │ │ │ │ */ │ │ │ │ │ - symbolizer: null, │ │ │ │ │ + name: 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. │ │ │ │ │ + * APIProperty: stringifyOutput │ │ │ │ │ + * {Boolean} If true, write will return a string otherwise a DOMElement. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - symbolizers: null, │ │ │ │ │ + stringifyOutput: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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}" │ │ │ │ │ + * Property: parser │ │ │ │ │ + * {Object} Instance of the versioned parser. Cached for multiple read and │ │ │ │ │ + * write calls of the same version. │ │ │ │ │ */ │ │ │ │ │ - minScaleDenominator: null, │ │ │ │ │ + parser: 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. │ │ │ │ │ + * Constructor: OpenLayers.Format.XML.VersionedOGC. │ │ │ │ │ + * Constructor. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on │ │ │ │ │ + * the object. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - this.symbolizer = {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - delete this.symbolizer; │ │ │ │ │ - } │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + var className = this.CLASS_NAME; │ │ │ │ │ + this.name = className.substring(className.lastIndexOf(".") + 1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * Method: getVersion │ │ │ │ │ + * Returns the version to use. Subclasses can override this function │ │ │ │ │ + * if a different version detection is needed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * root - {DOMElement} │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The version to use. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i in this.symbolizer) { │ │ │ │ │ - this.symbolizer[i] = null; │ │ │ │ │ + getVersion: function(root, options) { │ │ │ │ │ + var version; │ │ │ │ │ + // read │ │ │ │ │ + if (root) { │ │ │ │ │ + version = this.version; │ │ │ │ │ + if (!version) { │ │ │ │ │ + version = root.getAttribute("version"); │ │ │ │ │ + if (!version) { │ │ │ │ │ + version = this.defaultVersion; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { // write │ │ │ │ │ + version = (options && options.version) || │ │ │ │ │ + this.version || this.defaultVersion; │ │ │ │ │ } │ │ │ │ │ - this.symbolizer = null; │ │ │ │ │ - delete this.symbolizers; │ │ │ │ │ + return version; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * evaluates this rule for a specific feature │ │ │ │ │ - * │ │ │ │ │ + * Method: getParser │ │ │ │ │ + * Get an instance of the cached parser if available, otherwise create one. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} feature to apply the rule to. │ │ │ │ │ - * │ │ │ │ │ + * version - {String} │ │ │ │ │ + * │ │ │ │ │ * 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); │ │ │ │ │ + getParser: function(version) { │ │ │ │ │ + version = version || this.defaultVersion; │ │ │ │ │ + var profile = this.profile ? "_" + this.profile : ""; │ │ │ │ │ + if (!this.parser || this.parser.VERSION != version) { │ │ │ │ │ + var format = OpenLayers.Format[this.name][ │ │ │ │ │ + "v" + version.replace(/\./g, "_") + profile │ │ │ │ │ + ]; │ │ │ │ │ + if (!format) { │ │ │ │ │ + if (profile !== "" && this.allowFallback) { │ │ │ │ │ + // fallback to the non-profiled version of the parser │ │ │ │ │ + profile = ""; │ │ │ │ │ + format = OpenLayers.Format[this.name][ │ │ │ │ │ + "v" + version.replace(/\./g, "_") │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + if (!format) { │ │ │ │ │ + throw "Can't find a " + this.name + " parser for version " + │ │ │ │ │ + version + profile; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + this.parser = new format(this.options); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return applies; │ │ │ │ │ + return this.parser; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getContext │ │ │ │ │ - * Gets the context for evaluating this rule │ │ │ │ │ - * │ │ │ │ │ - * Paramters: │ │ │ │ │ - * feature - {} feature to take the context from if │ │ │ │ │ - * none is specified. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Write a document. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} An object representing the document. │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The document as a string │ │ │ │ │ */ │ │ │ │ │ - getContext: function(feature) { │ │ │ │ │ - var context = this.context; │ │ │ │ │ - if (!context) { │ │ │ │ │ - context = feature.attributes || feature.data; │ │ │ │ │ - } │ │ │ │ │ - if (typeof this.context == "function") { │ │ │ │ │ - context = this.context(feature); │ │ │ │ │ + write: function(obj, options) { │ │ │ │ │ + var version = this.getVersion(null, options); │ │ │ │ │ + this.parser = this.getParser(version); │ │ │ │ │ + var root = this.parser.write(obj, options); │ │ │ │ │ + if (this.stringifyOutput === false) { │ │ │ │ │ + return root; │ │ │ │ │ + } else { │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ } │ │ │ │ │ - return context; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this rule. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read a doc and return an object representing the document. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String | DOMElement} Data to read. │ │ │ │ │ + * options - {Object} Options for the reader. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Clone of this rule. │ │ │ │ │ + * {Object} An object representing the document. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + read: function(data, options) { │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ } │ │ │ │ │ - // 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); │ │ │ │ │ + var root = data.documentElement; │ │ │ │ │ + var version = this.getVersion(root); │ │ │ │ │ + this.parser = this.getParser(version); // Select the parser │ │ │ │ │ + var obj = this.parser.read(data, options); // Parse the data │ │ │ │ │ + │ │ │ │ │ + var errorProperty = this.parser.errorProperty || null; │ │ │ │ │ + if (errorProperty !== null && obj[errorProperty] === undefined) { │ │ │ │ │ + // an error must have happened, so parse it and report back │ │ │ │ │ + var format = new OpenLayers.Format.OGCExceptionReport(); │ │ │ │ │ + obj.error = format.read(data); │ │ │ │ │ + } │ │ │ │ │ + obj.version = version; │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.XML.VersionedOGC" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + OpenLayers/Format/OWSCommon.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 │ │ │ │ │ + * @requires OpenLayers/Format/XML/VersionedOGC.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * Read WPS DescribeProcess responses. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Format.OWSCommon │ │ │ │ │ + * Read OWSCommon. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ * 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", │ │ │ │ │ +OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ - */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: defaultVersion │ │ │ │ │ + * {String} Version number to assume if none found. Default is "1.0.0". │ │ │ │ │ + */ │ │ │ │ │ + defaultVersion: "1.0.0", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.OWSCommon │ │ │ │ │ + * Create a new parser for OWSCommon. │ │ │ │ │ + * │ │ │ │ │ + * 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]); │ │ │ │ │ + /** │ │ │ │ │ + * Method: getVersion │ │ │ │ │ + * Returns the version to use. Subclasses can override this function │ │ │ │ │ + * if a different version detection is needed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * root - {DOMElement} │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The version to use. │ │ │ │ │ + */ │ │ │ │ │ + getVersion: function(root, options) { │ │ │ │ │ + var version = this.version; │ │ │ │ │ + if (!version) { │ │ │ │ │ + // remember version does not correspond to the OWS version │ │ │ │ │ + // it corresponds to the WMS/WFS/WCS etc. request version │ │ │ │ │ + var uri = root.getAttribute("xmlns:ows"); │ │ │ │ │ + // the above will fail if the namespace prefix is different than │ │ │ │ │ + // ows and if the namespace is declared on a different element │ │ │ │ │ + if (uri && uri.substring(uri.lastIndexOf("/") + 1) === "1.1") { │ │ │ │ │ + version = "1.1.0"; │ │ │ │ │ } │ │ │ │ │ - if (data && data.nodeType == 9) { │ │ │ │ │ - data = data.documentElement; │ │ │ │ │ + if (!version) { │ │ │ │ │ + version = this.defaultVersion; │ │ │ │ │ } │ │ │ │ │ - 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"] │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + return version; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess" │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read an OWSCommon document and return an object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String | DOMElement} Data to read. │ │ │ │ │ + * options - {Object} Options for the reader. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the structure of the document. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - }); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.OWSCommon" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/WPSClient.js │ │ │ │ │ + OpenLayers/Format/OWSCommon/v1.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 │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon.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. │ │ │ │ │ + * Class: OpenLayers.Format.OWSCommon.v1 │ │ │ │ │ + * Common readers and writers for OWSCommon v1.X formats │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ +OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - 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]; │ │ │ │ │ - } │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: execute │ │ │ │ │ - * Shortcut to execute a process with a single function call. This is │ │ │ │ │ - * equivalent to using and then calling execute on the │ │ │ │ │ - * process. │ │ │ │ │ + * Method: read │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Options for the execute operation. │ │ │ │ │ + * data - {DOMElement} An OWSCommon document element. │ │ │ │ │ + * options - {Object} Options for the reader. │ │ │ │ │ * │ │ │ │ │ - * 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: │ │ │ │ │ + * {Object} An object representing the OWSCommon document. │ │ │ │ │ */ │ │ │ │ │ - execute: function(options) { │ │ │ │ │ - var process = this.getProcess(options.server, options.process); │ │ │ │ │ - process.execute({ │ │ │ │ │ - inputs: options.inputs, │ │ │ │ │ - success: options.success, │ │ │ │ │ - scope: options.scope │ │ │ │ │ - }); │ │ │ │ │ + read: function(data, options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults(options, this.options); │ │ │ │ │ + var ows = {}; │ │ │ │ │ + this.readChildNodes(data, ows); │ │ │ │ │ + return ows; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: │ │ │ │ │ - * {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getProcess: function(serverID, processID) { │ │ │ │ │ - var process = new OpenLayers.WPSProcess({ │ │ │ │ │ - client: this, │ │ │ │ │ - server: serverID, │ │ │ │ │ - identifier: processID │ │ │ │ │ - }); │ │ │ │ │ - if (!this.lazy) { │ │ │ │ │ - process.describe(); │ │ │ │ │ + readers: { │ │ │ │ │ + "ows": { │ │ │ │ │ + "Exception": function(node, exceptionReport) { │ │ │ │ │ + var exception = { │ │ │ │ │ + code: node.getAttribute('exceptionCode'), │ │ │ │ │ + locator: node.getAttribute('locator'), │ │ │ │ │ + texts: [] │ │ │ │ │ + }; │ │ │ │ │ + exceptionReport.exceptions.push(exception); │ │ │ │ │ + this.readChildNodes(node, exception); │ │ │ │ │ + }, │ │ │ │ │ + "ExceptionText": function(node, exception) { │ │ │ │ │ + var text = this.getChildValue(node); │ │ │ │ │ + exception.texts.push(text); │ │ │ │ │ + }, │ │ │ │ │ + "ServiceIdentification": function(node, obj) { │ │ │ │ │ + obj.serviceIdentification = {}; │ │ │ │ │ + this.readChildNodes(node, obj.serviceIdentification); │ │ │ │ │ + }, │ │ │ │ │ + "Title": function(node, obj) { │ │ │ │ │ + obj.title = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Abstract": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification["abstract"] = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Keywords": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification.keywords = {}; │ │ │ │ │ + this.readChildNodes(node, serviceIdentification.keywords); │ │ │ │ │ + }, │ │ │ │ │ + "Keyword": function(node, keywords) { │ │ │ │ │ + keywords[this.getChildValue(node)] = true; │ │ │ │ │ + }, │ │ │ │ │ + "ServiceType": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification.serviceType = { │ │ │ │ │ + codeSpace: node.getAttribute('codeSpace'), │ │ │ │ │ + value: this.getChildValue(node) │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + "ServiceTypeVersion": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification.serviceTypeVersion = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Fees": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification.fees = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "AccessConstraints": function(node, serviceIdentification) { │ │ │ │ │ + serviceIdentification.accessConstraints = │ │ │ │ │ + this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "ServiceProvider": function(node, obj) { │ │ │ │ │ + obj.serviceProvider = {}; │ │ │ │ │ + this.readChildNodes(node, obj.serviceProvider); │ │ │ │ │ + }, │ │ │ │ │ + "ProviderName": function(node, serviceProvider) { │ │ │ │ │ + serviceProvider.providerName = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "ProviderSite": function(node, serviceProvider) { │ │ │ │ │ + serviceProvider.providerSite = this.getAttributeNS(node, │ │ │ │ │ + this.namespaces.xlink, "href"); │ │ │ │ │ + }, │ │ │ │ │ + "ServiceContact": function(node, serviceProvider) { │ │ │ │ │ + serviceProvider.serviceContact = {}; │ │ │ │ │ + this.readChildNodes(node, serviceProvider.serviceContact); │ │ │ │ │ + }, │ │ │ │ │ + "IndividualName": function(node, serviceContact) { │ │ │ │ │ + serviceContact.individualName = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "PositionName": function(node, serviceContact) { │ │ │ │ │ + serviceContact.positionName = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "ContactInfo": function(node, serviceContact) { │ │ │ │ │ + serviceContact.contactInfo = {}; │ │ │ │ │ + this.readChildNodes(node, serviceContact.contactInfo); │ │ │ │ │ + }, │ │ │ │ │ + "Phone": function(node, contactInfo) { │ │ │ │ │ + contactInfo.phone = {}; │ │ │ │ │ + this.readChildNodes(node, contactInfo.phone); │ │ │ │ │ + }, │ │ │ │ │ + "Voice": function(node, phone) { │ │ │ │ │ + phone.voice = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Address": function(node, contactInfo) { │ │ │ │ │ + contactInfo.address = {}; │ │ │ │ │ + this.readChildNodes(node, contactInfo.address); │ │ │ │ │ + }, │ │ │ │ │ + "DeliveryPoint": function(node, address) { │ │ │ │ │ + address.deliveryPoint = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "City": function(node, address) { │ │ │ │ │ + address.city = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "AdministrativeArea": function(node, address) { │ │ │ │ │ + address.administrativeArea = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "PostalCode": function(node, address) { │ │ │ │ │ + address.postalCode = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Country": function(node, address) { │ │ │ │ │ + address.country = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "ElectronicMailAddress": function(node, address) { │ │ │ │ │ + address.electronicMailAddress = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Role": function(node, serviceContact) { │ │ │ │ │ + serviceContact.role = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "OperationsMetadata": function(node, obj) { │ │ │ │ │ + obj.operationsMetadata = {}; │ │ │ │ │ + this.readChildNodes(node, obj.operationsMetadata); │ │ │ │ │ + }, │ │ │ │ │ + "Operation": function(node, operationsMetadata) { │ │ │ │ │ + var name = node.getAttribute("name"); │ │ │ │ │ + operationsMetadata[name] = {}; │ │ │ │ │ + this.readChildNodes(node, operationsMetadata[name]); │ │ │ │ │ + }, │ │ │ │ │ + "DCP": function(node, operation) { │ │ │ │ │ + operation.dcp = {}; │ │ │ │ │ + this.readChildNodes(node, operation.dcp); │ │ │ │ │ + }, │ │ │ │ │ + "HTTP": function(node, dcp) { │ │ │ │ │ + dcp.http = {}; │ │ │ │ │ + this.readChildNodes(node, dcp.http); │ │ │ │ │ + }, │ │ │ │ │ + "Get": function(node, http) { │ │ │ │ │ + if (!http.get) { │ │ │ │ │ + http.get = []; │ │ │ │ │ + } │ │ │ │ │ + var obj = { │ │ │ │ │ + url: this.getAttributeNS(node, this.namespaces.xlink, "href") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + http.get.push(obj); │ │ │ │ │ + }, │ │ │ │ │ + "Post": function(node, http) { │ │ │ │ │ + if (!http.post) { │ │ │ │ │ + http.post = []; │ │ │ │ │ + } │ │ │ │ │ + var obj = { │ │ │ │ │ + url: this.getAttributeNS(node, this.namespaces.xlink, "href") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + http.post.push(obj); │ │ │ │ │ + }, │ │ │ │ │ + "Parameter": function(node, operation) { │ │ │ │ │ + if (!operation.parameters) { │ │ │ │ │ + operation.parameters = {}; │ │ │ │ │ + } │ │ │ │ │ + var name = node.getAttribute("name"); │ │ │ │ │ + operation.parameters[name] = {}; │ │ │ │ │ + this.readChildNodes(node, operation.parameters[name]); │ │ │ │ │ + }, │ │ │ │ │ + "Constraint": function(node, obj) { │ │ │ │ │ + if (!obj.constraints) { │ │ │ │ │ + obj.constraints = {}; │ │ │ │ │ + } │ │ │ │ │ + var name = node.getAttribute("name"); │ │ │ │ │ + obj.constraints[name] = {}; │ │ │ │ │ + this.readChildNodes(node, obj.constraints[name]); │ │ │ │ │ + }, │ │ │ │ │ + "Value": function(node, allowedValues) { │ │ │ │ │ + allowedValues[this.getChildValue(node)] = true; │ │ │ │ │ + }, │ │ │ │ │ + "OutputFormat": function(node, obj) { │ │ │ │ │ + obj.formats.push({ │ │ │ │ │ + value: this.getChildValue(node) │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "WGS84BoundingBox": function(node, obj) { │ │ │ │ │ + var boundingBox = {}; │ │ │ │ │ + boundingBox.crs = node.getAttribute("crs"); │ │ │ │ │ + if (obj.BoundingBox) { │ │ │ │ │ + obj.BoundingBox.push(boundingBox); │ │ │ │ │ + } else { │ │ │ │ │ + obj.projection = boundingBox.crs; │ │ │ │ │ + boundingBox = obj; │ │ │ │ │ + } │ │ │ │ │ + this.readChildNodes(node, boundingBox); │ │ │ │ │ + }, │ │ │ │ │ + "BoundingBox": function(node, obj) { │ │ │ │ │ + // FIXME: We consider that BoundingBox is the same as WGS84BoundingBox │ │ │ │ │ + // LowerCorner = "min_x min_y" │ │ │ │ │ + // UpperCorner = "max_x max_y" │ │ │ │ │ + // It should normally depend on the projection │ │ │ │ │ + this.readers['ows']['WGS84BoundingBox'].apply(this, [node, obj]); │ │ │ │ │ + }, │ │ │ │ │ + "LowerCorner": function(node, obj) { │ │ │ │ │ + var str = this.getChildValue(node).replace( │ │ │ │ │ + this.regExes.trimSpace, ""); │ │ │ │ │ + str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ + var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ + obj.left = pointList[0]; │ │ │ │ │ + obj.bottom = pointList[1]; │ │ │ │ │ + }, │ │ │ │ │ + "UpperCorner": function(node, obj) { │ │ │ │ │ + var str = this.getChildValue(node).replace( │ │ │ │ │ + this.regExes.trimSpace, ""); │ │ │ │ │ + str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ + var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ + obj.right = pointList[0]; │ │ │ │ │ + obj.top = pointList[1]; │ │ │ │ │ + obj.bounds = new OpenLayers.Bounds(obj.left, obj.bottom, │ │ │ │ │ + obj.right, obj.top); │ │ │ │ │ + delete obj.left; │ │ │ │ │ + delete obj.bottom; │ │ │ │ │ + delete obj.right; │ │ │ │ │ + delete obj.top; │ │ │ │ │ + }, │ │ │ │ │ + "Language": function(node, obj) { │ │ │ │ │ + obj.language = this.getChildValue(node); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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 │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + writers: { │ │ │ │ │ + "ows": { │ │ │ │ │ + "BoundingBox": function(options, nodeName) { │ │ │ │ │ + var node = this.createElementNSPlus(nodeName || "ows:BoundingBox", { │ │ │ │ │ + attributes: { │ │ │ │ │ + crs: options.projection │ │ │ │ │ } │ │ │ │ │ }); │ │ │ │ │ + this.writeNode("ows:LowerCorner", options, node); │ │ │ │ │ + this.writeNode("ows:UpperCorner", options, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LowerCorner": function(options) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:LowerCorner", { │ │ │ │ │ + value: options.bounds.left + " " + options.bounds.bottom │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "UpperCorner": function(options) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:UpperCorner", { │ │ │ │ │ + value: options.bounds.right + " " + options.bounds.top │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Identifier": function(identifier) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:Identifier", { │ │ │ │ │ + value: identifier │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Title": function(title) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:Title", { │ │ │ │ │ + value: title │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Abstract": function(abstractValue) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:Abstract", { │ │ │ │ │ + value: abstractValue │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "OutputFormat": function(format) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:OutputFormat", { │ │ │ │ │ + value: format │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ } │ │ │ │ │ - } 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' │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.OWSCommon.v1" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Kinetic.js │ │ │ │ │ + OpenLayers/Format/OWSCommon/v1_1_0.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 │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.OWSCommon.v1_1_0 │ │ │ │ │ + * Parser for OWS Common version 1.1.0. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: threshold │ │ │ │ │ - * In most cases changing the threshold isn't needed. │ │ │ │ │ - * In px/ms, default to 0. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - threshold: 0, │ │ │ │ │ + namespaces: { │ │ │ │ │ + ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: deceleration │ │ │ │ │ - * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - deceleration: 0.0035, │ │ │ │ │ + readers: { │ │ │ │ │ + "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "ExceptionReport": function(node, obj) { │ │ │ │ │ + obj.exceptionReport = { │ │ │ │ │ + version: node.getAttribute('version'), │ │ │ │ │ + language: node.getAttribute('xml:lang'), │ │ │ │ │ + exceptions: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ + }, │ │ │ │ │ + "AllowedValues": function(node, parameter) { │ │ │ │ │ + parameter.allowedValues = {}; │ │ │ │ │ + this.readChildNodes(node, parameter.allowedValues); │ │ │ │ │ + }, │ │ │ │ │ + "AnyValue": function(node, parameter) { │ │ │ │ │ + parameter.anyValue = true; │ │ │ │ │ + }, │ │ │ │ │ + "DataType": function(node, parameter) { │ │ │ │ │ + parameter.dataType = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Range": function(node, allowedValues) { │ │ │ │ │ + allowedValues.range = {}; │ │ │ │ │ + this.readChildNodes(node, allowedValues.range); │ │ │ │ │ + }, │ │ │ │ │ + "MinimumValue": function(node, range) { │ │ │ │ │ + range.minValue = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "MaximumValue": function(node, range) { │ │ │ │ │ + range.maxValue = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Identifier": function(node, obj) { │ │ │ │ │ + obj.identifier = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "SupportedCRS": function(node, obj) { │ │ │ │ │ + obj.supportedCRS = this.getChildValue(node); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.OWSCommon.v1.prototype.readers["ows"]) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: nbPoints │ │ │ │ │ - * {Integer} the number of points we use to calculate the kinetic │ │ │ │ │ - * initial values. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - nbPoints: 100, │ │ │ │ │ + writers: { │ │ │ │ │ + "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "Range": function(range) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:Range", { │ │ │ │ │ + attributes: { │ │ │ │ │ + 'ows:rangeClosure': range.closure │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("ows:MinimumValue", range.minValue, node); │ │ │ │ │ + this.writeNode("ows:MaximumValue", range.maxValue, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MinimumValue": function(minValue) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:MinimumValue", { │ │ │ │ │ + value: minValue │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MaximumValue": function(maxValue) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:MaximumValue", { │ │ │ │ │ + value: maxValue │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Value": function(value) { │ │ │ │ │ + var node = this.createElementNSPlus("ows:Value", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.OWSCommon.v1.prototype.writers["ows"]) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: delay │ │ │ │ │ - * {Float} time to consider to calculate the kinetic initial values. │ │ │ │ │ - * In ms, default to 200. │ │ │ │ │ - */ │ │ │ │ │ - delay: 200, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_1_0" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/WCSGetCoverage.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.WCSGetCoverage version 1.1.0 │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WCSGetCoverage = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: points │ │ │ │ │ - * List of points use to calculate the kinetic initial values. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - points: undefined, │ │ │ │ │ + namespaces: { │ │ │ │ │ + ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ + wcs: "http://www.opengis.net/wcs/1.1", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * ID of the timer. │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - timerId: undefined, │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Kinetic │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.1.2 │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ + VERSION: "1.1.2", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: begin │ │ │ │ │ - * Begins the dragging. │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location │ │ │ │ │ */ │ │ │ │ │ - begin: function() { │ │ │ │ │ - OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ - this.timerId = undefined; │ │ │ │ │ - this.points = []; │ │ │ │ │ - }, │ │ │ │ │ + schemaLocation: "http://www.opengis.net/wcs/1.1 http://schemas.opengis.net/wcs/1.1/wcsGetCoverage.xsd", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Updates during the dragging. │ │ │ │ │ + * Constructor: OpenLayers.Format.WCSGetCoverage │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The new position. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - update: function(xy) { │ │ │ │ │ - this.points.unshift({ │ │ │ │ │ - xy: xy, │ │ │ │ │ - tick: new Date().getTime() │ │ │ │ │ - }); │ │ │ │ │ - if (this.points.length > this.nbPoints) { │ │ │ │ │ - this.points.pop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: end │ │ │ │ │ - * Ends the dragging, start the kinetic. │ │ │ │ │ + * Method: write │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The last position. │ │ │ │ │ + * options - {Object} Optional object. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {String} A WCS GetCoverage request XML string. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + write: function(options) { │ │ │ │ │ + var node = this.writeNode("wcs:GetCoverage", options); │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + node, this.namespaces.xsi, │ │ │ │ │ + "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ + ); │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Launch the kinetic move pan. │ │ │ │ │ - * │ │ │ │ │ - * 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). │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + writers: { │ │ │ │ │ + "wcs": { │ │ │ │ │ + "GetCoverage": function(options) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:GetCoverage", { │ │ │ │ │ + attributes: { │ │ │ │ │ + version: options.version || this.VERSION, │ │ │ │ │ + service: 'WCS' │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("ows:Identifier", options.identifier, node); │ │ │ │ │ + this.writeNode("wcs:DomainSubset", options.domainSubset, node); │ │ │ │ │ + this.writeNode("wcs:Output", options.output, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "DomainSubset": function(domainSubset) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:DomainSubset", {}); │ │ │ │ │ + this.writeNode("ows:BoundingBox", domainSubset.boundingBox, node); │ │ │ │ │ + if (domainSubset.temporalSubset) { │ │ │ │ │ + this.writeNode("wcs:TemporalSubset", domainSubset.temporalSubset, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "TemporalSubset": function(temporalSubset) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:TemporalSubset", {}); │ │ │ │ │ + for (var i = 0, len = temporalSubset.timePeriods.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("wcs:TimePeriod", temporalSubset.timePeriods[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "TimePeriod": function(timePeriod) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:TimePeriod", {}); │ │ │ │ │ + this.writeNode("wcs:BeginPosition", timePeriod.begin, node); │ │ │ │ │ + this.writeNode("wcs:EndPosition", timePeriod.end, node); │ │ │ │ │ + if (timePeriod.resolution) { │ │ │ │ │ + this.writeNode("wcs:TimeResolution", timePeriod.resolution, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "BeginPosition": function(begin) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:BeginPosition", { │ │ │ │ │ + value: begin │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "EndPosition": function(end) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:EndPosition", { │ │ │ │ │ + value: end │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "TimeResolution": function(resolution) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:TimeResolution", { │ │ │ │ │ + value: resolution │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Output": function(output) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:Output", { │ │ │ │ │ + attributes: { │ │ │ │ │ + format: output.format, │ │ │ │ │ + store: output.store │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (output.gridCRS) { │ │ │ │ │ + this.writeNode("wcs:GridCRS", output.gridCRS, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "GridCRS": function(gridCRS) { │ │ │ │ │ + var node = this.createElementNSPlus("wcs:GridCRS", {}); │ │ │ │ │ + this.writeNode("wcs:GridBaseCRS", gridCRS.baseCRS, node); │ │ │ │ │ + if (gridCRS.type) { │ │ │ │ │ + this.writeNode("wcs:GridType", gridCRS.type, node); │ │ │ │ │ + } │ │ │ │ │ + if (gridCRS.origin) { │ │ │ │ │ + this.writeNode("wcs:GridOrigin", gridCRS.origin, node); │ │ │ │ │ + } │ │ │ │ │ + this.writeNode("wcs:GridOffsets", gridCRS.offsets, node); │ │ │ │ │ + if (gridCRS.CS) { │ │ │ │ │ + this.writeNode("wcs:GridCS", gridCRS.CS, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "GridBaseCRS": function(baseCRS) { │ │ │ │ │ + return this.createElementNSPlus("wcs:GridBaseCRS", { │ │ │ │ │ + value: baseCRS │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "GridOrigin": function(origin) { │ │ │ │ │ + return this.createElementNSPlus("wcs:GridOrigin", { │ │ │ │ │ + value: origin │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "GridType": function(type) { │ │ │ │ │ + return this.createElementNSPlus("wcs:GridType", { │ │ │ │ │ + value: type │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "GridOffsets": function(offsets) { │ │ │ │ │ + return this.createElementNSPlus("wcs:GridOffsets", { │ │ │ │ │ + value: offsets │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "GridCS": function(CS) { │ │ │ │ │ + return this.createElementNSPlus("wcs:GridCS", { │ │ │ │ │ + value: CS │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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) │ │ │ │ │ - ); │ │ │ │ │ + }, │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Kinetic" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WCSGetCoverage" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer.js │ │ │ │ │ + OpenLayers/Format/WFST.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 │ │ │ │ │ + * @requires OpenLayers/Format.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer │ │ │ │ │ + * Function: OpenLayers.Format.WFST │ │ │ │ │ + * Used to create a versioned WFS protocol. Default version is 1.0.0. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A WFST format of the given version. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ +OpenLayers.Format.WFST = function(options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults( │ │ │ │ │ + options, OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ + ); │ │ │ │ │ + var cls = OpenLayers.Format.WFST["v" + options.version.replace(/\./g, "_")]; │ │ │ │ │ + if (!cls) { │ │ │ │ │ + throw "Unsupported WFST version: " + options.version; │ │ │ │ │ + } │ │ │ │ │ + return new cls(options); │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ + * {Object} Default properties for the WFST format. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WFST.DEFAULTS = { │ │ │ │ │ + "version": "1.0.0" │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter/Spatial.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - div: 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: opacity │ │ │ │ │ - * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ - * is 1. │ │ │ │ │ - */ │ │ │ │ │ - opacity: 1, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Filter.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter.Spatial │ │ │ │ │ + * This class represents a spatial filter. │ │ │ │ │ + * Currently implemented: BBOX, DWithin and Intersects │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter.Spatial = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ - * {Array} The properties that are used for calculating resolutions │ │ │ │ │ - * information. │ │ │ │ │ + * APIProperty: type │ │ │ │ │ + * {String} Type of spatial filter. │ │ │ │ │ + * │ │ │ │ │ + * The type should be one of: │ │ │ │ │ + * - OpenLayers.Filter.Spatial.BBOX │ │ │ │ │ + * - OpenLayers.Filter.Spatial.INTERSECTS │ │ │ │ │ + * - OpenLayers.Filter.Spatial.DWITHIN │ │ │ │ │ + * - OpenLayers.Filter.Spatial.WITHIN │ │ │ │ │ + * - OpenLayers.Filter.Spatial.CONTAINS │ │ │ │ │ */ │ │ │ │ │ - RESOLUTION_PROPERTIES: [ │ │ │ │ │ - 'scales', 'resolutions', │ │ │ │ │ - 'maxScale', 'minScale', │ │ │ │ │ - 'maxResolution', 'minResolution', │ │ │ │ │ - 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ - ], │ │ │ │ │ + type: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: property │ │ │ │ │ + * {String} Name of the context property to compare. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + property: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: map │ │ │ │ │ - * {} This variable is set when the layer is added to │ │ │ │ │ - * the map, via the accessor function setMap(). │ │ │ │ │ + * APIProperty: value │ │ │ │ │ + * { || } The bounds or geometry │ │ │ │ │ + * to be used by the filter. Use bounds for BBOX filters and geometry │ │ │ │ │ + * for INTERSECTS or DWITHIN filters. │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ + value: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ - * individually by all subclasses. Default is false │ │ │ │ │ + * APIProperty: distance │ │ │ │ │ + * {Number} The distance to use in a DWithin spatial filter. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ + distance: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: alpha │ │ │ │ │ - * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ + * APIProperty: distanceUnits │ │ │ │ │ + * {String} The units to use for the distance, e.g. 'm'. │ │ │ │ │ */ │ │ │ │ │ - alpha: false, │ │ │ │ │ + distanceUnits: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Constructor: OpenLayers.Filter.Spatial │ │ │ │ │ + * Creates a spatial filter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * filter. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: visibility │ │ │ │ │ - * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ + * Method: evaluate │ │ │ │ │ + * Evaluates this filter for a specific feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} feature to apply the filter to. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The feature meets filter criteria. │ │ │ │ │ */ │ │ │ │ │ - visibility: true, │ │ │ │ │ + evaluate: function(feature) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + switch (this.type) { │ │ │ │ │ + case OpenLayers.Filter.Spatial.BBOX: │ │ │ │ │ + case OpenLayers.Filter.Spatial.INTERSECTS: │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + var geom = this.value; │ │ │ │ │ + if (this.value.CLASS_NAME == "OpenLayers.Bounds") { │ │ │ │ │ + geom = this.value.toGeometry(); │ │ │ │ │ + } │ │ │ │ │ + if (feature.geometry.intersects(geom)) { │ │ │ │ │ + intersect = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + throw new Error('evaluate is not implemented for this filter type.'); │ │ │ │ │ + } │ │ │ │ │ + return intersect; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: attribution │ │ │ │ │ - * {String} Attribution string, displayed when an │ │ │ │ │ - * has been added to the map. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ */ │ │ │ │ │ - attribution: null, │ │ │ │ │ + clone: function() { │ │ │ │ │ + var options = OpenLayers.Util.applyDefaults({ │ │ │ │ │ + value: this.value && this.value.clone && this.value.clone() │ │ │ │ │ + }, this); │ │ │ │ │ + return new OpenLayers.Filter.Spatial(options); │ │ │ │ │ + }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter.Spatial" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +OpenLayers.Filter.Spatial.BBOX = "BBOX"; │ │ │ │ │ +OpenLayers.Filter.Spatial.INTERSECTS = "INTERSECTS"; │ │ │ │ │ +OpenLayers.Filter.Spatial.DWITHIN = "DWITHIN"; │ │ │ │ │ +OpenLayers.Filter.Spatial.WITHIN = "WITHIN"; │ │ │ │ │ +OpenLayers.Filter.Spatial.CONTAINS = "CONTAINS"; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter/FeatureId.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Propery: imageSize │ │ │ │ │ - * {} For layers with a gutter, the image is larger than │ │ │ │ │ - * the tile by twice the gutter in each dimension. │ │ │ │ │ - */ │ │ │ │ │ - imageSize: 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. */ │ │ │ │ │ │ │ │ │ │ - // OPTIONS │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Filter.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter.FeatureId │ │ │ │ │ + * This class represents a ogc:FeatureId Filter, as being used for rule-based SLD │ │ │ │ │ + * styling │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter.FeatureId = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: fids │ │ │ │ │ + * {Array(String)} Feature Ids to evaluate this rule against. │ │ │ │ │ + * To be passed inside the params object. │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + fids: 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: type │ │ │ │ │ + * {String} Type to identify this filter. │ │ │ │ │ */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ + type: "FID", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter.FeatureId │ │ │ │ │ + * Creates an ogc:FeatureId rule. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * rule │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - gutter: 0, │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.fids = []; │ │ │ │ │ + OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * evaluates this rule for a specific feature │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} feature to apply the rule to. │ │ │ │ │ + * For vector features, the check is run against the fid, │ │ │ │ │ + * for plain features against the id. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} true if the rule applies, false if it does not │ │ │ │ │ */ │ │ │ │ │ - projection: null, │ │ │ │ │ + evaluate: function(feature) { │ │ │ │ │ + for (var i = 0, len = this.fids.length; i < len; i++) { │ │ │ │ │ + var fid = feature.fid || feature.id; │ │ │ │ │ + if (fid == this.fids[i]) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ */ │ │ │ │ │ - units: null, │ │ │ │ │ + clone: function() { │ │ │ │ │ + var filter = new OpenLayers.Filter.FeatureId(); │ │ │ │ │ + OpenLayers.Util.extend(filter, this); │ │ │ │ │ + filter.fids = this.fids.slice(); │ │ │ │ │ + return filter; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter.FeatureId" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/WFST/v1.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +/* 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: 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, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Format/WFST.js │ │ │ │ │ + * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.WFST.v1 │ │ │ │ │ + * Superclass for WFST parsers. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - maxResolution: null, │ │ │ │ │ + namespaces: { │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance", │ │ │ │ │ + wfs: "http://www.opengis.net/wfs", │ │ │ │ │ + gml: "http://www.opengis.net/gml", │ │ │ │ │ + ogc: "http://www.opengis.net/ogc", │ │ │ │ │ + ows: "http://www.opengis.net/ows" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ + defaultPrefix: "wfs", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} │ │ │ │ │ + * Property: version │ │ │ │ │ + * {String} WFS version number. │ │ │ │ │ */ │ │ │ │ │ - numZoomLevels: null, │ │ │ │ │ + version: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. │ │ │ │ │ */ │ │ │ │ │ - minScale: null, │ │ │ │ │ + schemaLocations: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ + * APIProperty: srsName │ │ │ │ │ + * {String} URI for spatial reference system. │ │ │ │ │ */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ + srsName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayOutsideMaxExtent │ │ │ │ │ - * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ - * extent for this layer. Defaults to false. │ │ │ │ │ + * APIProperty: extractAttributes │ │ │ │ │ + * {Boolean} Extract attributes from GML. Default is true. │ │ │ │ │ */ │ │ │ │ │ - displayOutsideMaxExtent: false, │ │ │ │ │ + extractAttributes: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: xy │ │ │ │ │ + * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ + * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ */ │ │ │ │ │ - wrapDateLine: false, │ │ │ │ │ + xy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: metadata │ │ │ │ │ - * {Object} This object can be used to store additional information on a │ │ │ │ │ - * layer object. │ │ │ │ │ + * Property: stateName │ │ │ │ │ + * {Object} Maps feature states to node names. │ │ │ │ │ */ │ │ │ │ │ - metadata: null, │ │ │ │ │ + stateName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer │ │ │ │ │ + * Constructor: OpenLayers.Format.WFST.v1 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * or │ │ │ │ │ + * constructor instead. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} The layer name │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + // set state name mapping │ │ │ │ │ + this.stateName = {}; │ │ │ │ │ + this.stateName[OpenLayers.State.INSERT] = "wfs:Insert"; │ │ │ │ │ + this.stateName[OpenLayers.State.UPDATE] = "wfs:Update"; │ │ │ │ │ + this.stateName[OpenLayers.State.DELETE] = "wfs:Delete"; │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: getSrsName │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + getSrsName: function(feature, options) { │ │ │ │ │ + var srsName = options && options.srsName; │ │ │ │ │ + if (!srsName) { │ │ │ │ │ + if (feature && feature.layer) { │ │ │ │ │ + srsName = feature.layer.projection.getCode(); │ │ │ │ │ + } else { │ │ │ │ │ + srsName = this.srsName; │ │ │ │ │ } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - this.events = null; │ │ │ │ │ + return srsName; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Parse the response from a transaction. Because WFS is split into │ │ │ │ │ + * Transaction requests (create, update, and delete) and GetFeature │ │ │ │ │ + * requests (read), this method handles parsing of both types of │ │ │ │ │ + * responses. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {} The layer to be cloned │ │ │ │ │ + * data - {String | Document} The WFST document to read │ │ │ │ │ + * options - {Object} Options for the reader │ │ │ │ │ + * │ │ │ │ │ + * Valid options properties: │ │ │ │ │ + * output - {String} either "features" or "object". The default is │ │ │ │ │ + * "features", which means that the method will return an array of │ │ │ │ │ + * features. If set to "object", an object with a "features" property │ │ │ │ │ + * and other properties read by the parser will be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ + * {Array | Object} Output depending on the output option. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + read: function(data, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ + output: "features" │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + if (data && data.nodeType == 9) { │ │ │ │ │ + data = data.documentElement; │ │ │ │ │ + } │ │ │ │ │ + var obj = {}; │ │ │ │ │ + if (data) { │ │ │ │ │ + this.readNode(data, obj, true); │ │ │ │ │ + } │ │ │ │ │ + if (obj.features && options.output === "features") { │ │ │ │ │ + obj = obj.features; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getOptions: function() { │ │ │ │ │ - var options = {}; │ │ │ │ │ - for (var o in this.options) { │ │ │ │ │ - options[o] = this[o]; │ │ │ │ │ + readers: { │ │ │ │ │ + "wfs": { │ │ │ │ │ + "FeatureCollection": function(node, obj) { │ │ │ │ │ + obj.features = []; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setName │ │ │ │ │ - * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ - * on the map. │ │ │ │ │ + /** │ │ │ │ │ + * Method: write │ │ │ │ │ + * Given an array of features, write a WFS transaction. This assumes │ │ │ │ │ + * the features have a state property that determines the operation │ │ │ │ │ + * type - insert, update, or delete. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newName - {String} The new name. │ │ │ │ │ + * features - {Array()} A list of features. See │ │ │ │ │ + * below for a more detailed description of the influence of the │ │ │ │ │ + * feature's *modified* property. │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * feature.modified rules: │ │ │ │ │ + * If a feature has a modified property set, the following checks will be │ │ │ │ │ + * made before a feature's geometry or attribute is included in an Update │ │ │ │ │ + * transaction: │ │ │ │ │ + * - *modified* is not set at all: The geometry and all attributes will be │ │ │ │ │ + * included. │ │ │ │ │ + * - *modified.geometry* is set (null or a geometry): The geometry will be │ │ │ │ │ + * included. If *modified.attributes* is not set, all attributes will │ │ │ │ │ + * be included. │ │ │ │ │ + * - *modified.attributes* is set: Only the attributes set (i.e. to null or │ │ │ │ │ + * a value) in *modified.attributes* will be included. │ │ │ │ │ + * If *modified.geometry* is not set, the geometry will not be included. │ │ │ │ │ + * │ │ │ │ │ + * Valid options include: │ │ │ │ │ + * - *multi* {Boolean} If set to true, geometries will be casted to │ │ │ │ │ + * Multi geometries before writing. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A serialized WFS transaction. │ │ │ │ │ */ │ │ │ │ │ - setName: function(newName) { │ │ │ │ │ - if (newName != this.name) { │ │ │ │ │ - this.name = newName; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "name" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + write: function(features, options) { │ │ │ │ │ + var node = this.writeNode("wfs:Transaction", { │ │ │ │ │ + features: features, │ │ │ │ │ + options: options │ │ │ │ │ + }); │ │ │ │ │ + var value = this.schemaLocationAttr(); │ │ │ │ │ + if (value) { │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + node, this.namespaces["xsi"], "xsi:schemaLocation", value │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + writers: { │ │ │ │ │ + "wfs": { │ │ │ │ │ + "GetFeature": function(options) { │ │ │ │ │ + var node = this.createElementNSPlus("wfs:GetFeature", { │ │ │ │ │ + attributes: { │ │ │ │ │ + service: "WFS", │ │ │ │ │ + version: this.version, │ │ │ │ │ + handle: options && options.handle, │ │ │ │ │ + outputFormat: options && options.outputFormat, │ │ │ │ │ + maxFeatures: options && options.maxFeatures, │ │ │ │ │ + "xsi:schemaLocation": this.schemaLocationAttr(options) │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (typeof this.featureType == "string") { │ │ │ │ │ + this.writeNode("Query", options, node); │ │ │ │ │ + } else { │ │ │ │ │ + for (var i = 0, len = this.featureType.length; i < len; i++) { │ │ │ │ │ + options.featureType = this.featureType[i]; │ │ │ │ │ + this.writeNode("Query", options, node); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Transaction": function(obj) { │ │ │ │ │ + obj = obj || {}; │ │ │ │ │ + var options = obj.options || {}; │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Transaction", { │ │ │ │ │ + attributes: { │ │ │ │ │ + service: "WFS", │ │ │ │ │ + version: this.version, │ │ │ │ │ + handle: options.handle │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + var i, len; │ │ │ │ │ + var features = obj.features; │ │ │ │ │ + if (features) { │ │ │ │ │ + // temporarily re-assigning geometry types │ │ │ │ │ + if (options.multi === true) { │ │ │ │ │ + OpenLayers.Util.extend(this.geometryTypes, { │ │ │ │ │ + "OpenLayers.Geometry.Point": "MultiPoint", │ │ │ │ │ + "OpenLayers.Geometry.LineString": (this.multiCurve === true) ? "MultiCurve" : "MultiLineString", │ │ │ │ │ + "OpenLayers.Geometry.Polygon": (this.multiSurface === true) ? "MultiSurface" : "MultiPolygon" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + var name, feature; │ │ │ │ │ + for (i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + name = this.stateName[feature.state]; │ │ │ │ │ + if (name) { │ │ │ │ │ + this.writeNode(name, { │ │ │ │ │ + feature: feature, │ │ │ │ │ + options: options │ │ │ │ │ + }, node); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // switch back to original geometry types assignment │ │ │ │ │ + if (options.multi === true) { │ │ │ │ │ + this.setGeometryTypes(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (options.nativeElements) { │ │ │ │ │ + for (i = 0, len = options.nativeElements.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("wfs:Native", │ │ │ │ │ + options.nativeElements[i], node); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Native": function(nativeElement) { │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Native", { │ │ │ │ │ + attributes: { │ │ │ │ │ + vendorId: nativeElement.vendorId, │ │ │ │ │ + safeToIgnore: nativeElement.safeToIgnore │ │ │ │ │ + }, │ │ │ │ │ + value: nativeElement.value │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Insert": function(obj) { │ │ │ │ │ + var feature = obj.feature; │ │ │ │ │ + var options = obj.options; │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Insert", { │ │ │ │ │ + attributes: { │ │ │ │ │ + handle: options && options.handle │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.srsName = this.getSrsName(feature); │ │ │ │ │ + this.writeNode("feature:_typeName", feature, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Update": function(obj) { │ │ │ │ │ + var feature = obj.feature; │ │ │ │ │ + var options = obj.options; │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Update", { │ │ │ │ │ + attributes: { │ │ │ │ │ + handle: options && options.handle, │ │ │ │ │ + typeName: (this.featureNS ? this.featurePrefix + ":" : "") + │ │ │ │ │ + this.featureType │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (this.featureNS) { │ │ │ │ │ + node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // add new options to this │ │ │ │ │ - OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ + // add in geometry │ │ │ │ │ + var modified = feature.modified; │ │ │ │ │ + if (this.geometryName !== null && (!modified || modified.geometry !== undefined)) { │ │ │ │ │ + this.srsName = this.getSrsName(feature); │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "Property", { │ │ │ │ │ + name: this.geometryName, │ │ │ │ │ + value: feature.geometry │ │ │ │ │ + }, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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(); │ │ │ │ │ - } │ │ │ │ │ + // add in attributes │ │ │ │ │ + for (var key in feature.attributes) { │ │ │ │ │ + if (feature.attributes[key] !== undefined && │ │ │ │ │ + (!modified || !modified.attributes || │ │ │ │ │ + (modified.attributes && modified.attributes[key] !== undefined))) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "Property", { │ │ │ │ │ + name: key, │ │ │ │ │ + value: feature.attributes[key] │ │ │ │ │ + }, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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) { │ │ │ │ │ + // add feature id filter │ │ │ │ │ + this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ │ │ │ │ │ + fids: [feature.fid] │ │ │ │ │ + }), node); │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Property": function(obj) { │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Property"); │ │ │ │ │ + this.writeNode("Name", obj.name, node); │ │ │ │ │ + if (obj.value !== null) { │ │ │ │ │ + this.writeNode("Value", obj.value, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Name": function(name) { │ │ │ │ │ + return this.createElementNSPlus("wfs:Name", { │ │ │ │ │ + value: name │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Value": function(obj) { │ │ │ │ │ + var node; │ │ │ │ │ + if (obj instanceof OpenLayers.Geometry) { │ │ │ │ │ + node = this.createElementNSPlus("wfs:Value"); │ │ │ │ │ + var geom = this.writeNode("feature:_geometry", obj).firstChild; │ │ │ │ │ + node.appendChild(geom); │ │ │ │ │ + } else { │ │ │ │ │ + node = this.createElementNSPlus("wfs:Value", { │ │ │ │ │ + value: obj │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Delete": function(obj) { │ │ │ │ │ + var feature = obj.feature; │ │ │ │ │ + var options = obj.options; │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Delete", { │ │ │ │ │ + attributes: { │ │ │ │ │ + handle: options && options.handle, │ │ │ │ │ + typeName: (this.featureNS ? this.featurePrefix + ":" : "") + │ │ │ │ │ + this.featureType │ │ │ │ │ } │ │ │ │ │ - break; │ │ │ │ │ + }); │ │ │ │ │ + if (this.featureNS) { │ │ │ │ │ + node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); │ │ │ │ │ } │ │ │ │ │ + this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ │ │ │ │ │ + fids: [feature.fid] │ │ │ │ │ + }), node); │ │ │ │ │ + return node; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: schemaLocationAttr │ │ │ │ │ + * Generate the xsi:schemaLocation attribute value. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ + * {String} The xsi:schemaLocation attribute or undefined if none. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + schemaLocationAttr: function(options) { │ │ │ │ │ + options = OpenLayers.Util.extend({ │ │ │ │ │ + featurePrefix: this.featurePrefix, │ │ │ │ │ + schema: this.schema │ │ │ │ │ + }, options); │ │ │ │ │ + var schemaLocations = OpenLayers.Util.extend({}, this.schemaLocations); │ │ │ │ │ + if (options.schema) { │ │ │ │ │ + schemaLocations[options.featurePrefix] = options.schema; │ │ │ │ │ + } │ │ │ │ │ + var parts = []; │ │ │ │ │ + var uri; │ │ │ │ │ + for (var key in schemaLocations) { │ │ │ │ │ + uri = this.namespaces[key]; │ │ │ │ │ + if (uri) { │ │ │ │ │ + parts.push(uri + " " + schemaLocations[key]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return redrawn; │ │ │ │ │ + var value = parts.join(" ") || undefined; │ │ │ │ │ + return value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * │ │ │ │ │ + * Method: setFilterProperty │ │ │ │ │ + * Set the property of each spatial filter. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ - * do some init work in that case. │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * filter - {} │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - var display = this.visibility; │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - display = display && this.inRange; │ │ │ │ │ + setFilterProperty: function(filter) { │ │ │ │ │ + if (filter.filters) { │ │ │ │ │ + for (var i = 0, len = filter.filters.length; i < len; ++i) { │ │ │ │ │ + OpenLayers.Format.WFST.v1.prototype.setFilterProperty.call(this, filter.filters[i]); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + if (filter instanceof OpenLayers.Filter.Spatial && !filter.property) { │ │ │ │ │ + // got a spatial filter without property, so set it │ │ │ │ │ + filter.property = this.geometryName; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WFST.v1" │ │ │ │ │ │ │ │ │ │ - this.projection = this.projection || this.map.projection; │ │ │ │ │ - if (typeof this.projection == "string") { │ │ │ │ │ - this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ - } │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter/Logical.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ +/* 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.initResolutions(); │ │ │ │ │ │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ - this.div.style.display = show ? "" : "none"; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Filter.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // deal with gutters │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter.Logical │ │ │ │ │ + * This class represents ogc:And, ogc:Or and ogc:Not rules. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: filters │ │ │ │ │ + * {Array()} Child filters for this filter. │ │ │ │ │ */ │ │ │ │ │ - afterAdd: function() {}, │ │ │ │ │ + filters: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 - {} │ │ │ │ │ + * APIProperty: type │ │ │ │ │ + * {String} type of logical operator. Available types are: │ │ │ │ │ + * - OpenLayers.Filter.Logical.AND = "&&"; │ │ │ │ │ + * - OpenLayers.Filter.Logical.OR = "||"; │ │ │ │ │ + * - OpenLayers.Filter.Logical.NOT = "!"; │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - //to be overridden by subclasses │ │ │ │ │ - }, │ │ │ │ │ + type: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getImageSize │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter.Logical │ │ │ │ │ + * Creates a logical filter (And, Or, Not). │ │ │ │ │ * │ │ │ │ │ * 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) │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * filter. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The size that the image should be, taking into │ │ │ │ │ - * account gutters. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getImageSize: function(bounds) { │ │ │ │ │ - return (this.imageSize || this.tileSize); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.filters = []; │ │ │ │ │ + OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ - * or use by Tile.Image. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Remove reference to child filters. │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.filters = null; │ │ │ │ │ + OpenLayers.Filter.prototype.destroy.apply(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getVisibility │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * Evaluates this filter in a specific context. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * context - {Object} Context to use in evaluating the filter. A vector │ │ │ │ │ + * feature may also be provided to evaluate feature attributes in │ │ │ │ │ + * comparison filters or geometries in spatial filters. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ + * {Boolean} The filter applies. │ │ │ │ │ */ │ │ │ │ │ - getVisibility: function() { │ │ │ │ │ - return this.visibility; │ │ │ │ │ - }, │ │ │ │ │ + evaluate: function(context) { │ │ │ │ │ + var i, len; │ │ │ │ │ + switch (this.type) { │ │ │ │ │ + case OpenLayers.Filter.Logical.AND: │ │ │ │ │ + for (i = 0, len = this.filters.length; i < len; i++) { │ │ │ │ │ + if (this.filters[i].evaluate(context) == false) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + case OpenLayers.Filter.Logical.OR: │ │ │ │ │ + for (i = 0, len = this.filters.length; i < len; i++) { │ │ │ │ │ + if (this.filters[i].evaluate(context) == true) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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"; │ │ │ │ │ + case OpenLayers.Filter.Logical.NOT: │ │ │ │ │ + return (!this.filters[0].evaluate(context)); │ │ │ │ │ } │ │ │ │ │ + return undefined; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: calculateInRange │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. │ │ │ │ │ * │ │ │ │ │ * 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} │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ */ │ │ │ │ │ - setIsBaseLayer: function(isBaseLayer) { │ │ │ │ │ - if (isBaseLayer != this.isBaseLayer) { │ │ │ │ │ - this.isBaseLayer = isBaseLayer; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + clone: function() { │ │ │ │ │ + var filters = []; │ │ │ │ │ + for (var i = 0, len = this.filters.length; i < len; ++i) { │ │ │ │ │ + filters.push(this.filters[i].clone()); │ │ │ │ │ } │ │ │ │ │ + return new OpenLayers.Filter.Logical({ │ │ │ │ │ + type: this.type, │ │ │ │ │ + filters: filters │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* 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); │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter.Logical" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - if (props.resolutions) { │ │ │ │ │ │ │ │ │ │ - //sort resolutions array descendingly │ │ │ │ │ - props.resolutions.sort(function(a, b) { │ │ │ │ │ - return (b - a); │ │ │ │ │ - }); │ │ │ │ │ +OpenLayers.Filter.Logical.AND = "&&"; │ │ │ │ │ +OpenLayers.Filter.Logical.OR = "||"; │ │ │ │ │ +OpenLayers.Filter.Logical.NOT = "!"; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter/Comparison.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // if we still don't have a maxResolution get it from the │ │ │ │ │ - // resolutions array │ │ │ │ │ - if (!maxResolution) { │ │ │ │ │ - maxResolution = props.resolutions[0]; │ │ │ │ │ - } │ │ │ │ │ +/* 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 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]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Filter.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter.Comparison │ │ │ │ │ + * This class represents a comparison filter. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resolutionsFromScales │ │ │ │ │ - * Derive resolutions from scales. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scales - {Array(Number)} Scales │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {Array(Number)} Resolutions │ │ │ │ │ + * APIProperty: type │ │ │ │ │ + * {String} type: type of the comparison. This is one of │ │ │ │ │ + * - OpenLayers.Filter.Comparison.EQUAL_TO = "=="; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.NOT_EQUAL_TO = "!="; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.LESS_THAN = "<"; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.GREATER_THAN = ">"; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.BETWEEN = ".."; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.LIKE = "~"; │ │ │ │ │ + * - OpenLayers.Filter.Comparison.IS_NULL = "NULL"; │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + type: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: calculateResolutions │ │ │ │ │ - * Calculate resolutions based on the provided properties. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * props - {Object} Properties │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array({Number})} Array of resolutions. │ │ │ │ │ + * APIProperty: property │ │ │ │ │ + * {String} │ │ │ │ │ + * name of the context property to compare │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + property: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ - * resolutions array, indexed by current zoom level. │ │ │ │ │ + * APIProperty: value │ │ │ │ │ + * {Number} or {String} │ │ │ │ │ + * comparison value for binary comparisons. In the case of a String, this │ │ │ │ │ + * can be a combination of text and propertyNames in the form │ │ │ │ │ + * "literal ${propertyName}" │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var zoom = this.map.getZoom(); │ │ │ │ │ - return this.getResolutionForZoom(zoom); │ │ │ │ │ - }, │ │ │ │ │ + value: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ + /** │ │ │ │ │ + * Property: matchCase │ │ │ │ │ + * {Boolean} Force case sensitive searches for EQUAL_TO and NOT_EQUAL_TO │ │ │ │ │ + * comparisons. The Filter Encoding 1.1 specification added a matchCase │ │ │ │ │ + * attribute to ogc:PropertyIsEqualTo and ogc:PropertyIsNotEqualTo │ │ │ │ │ + * elements. This property will be serialized with those elements only │ │ │ │ │ + * if using the v1.1.0 filter format. However, when evaluating filters │ │ │ │ │ + * here, the matchCase property will always be respected (for EQUAL_TO │ │ │ │ │ + * and NOT_EQUAL_TO). Default is true. │ │ │ │ │ */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ - // means it will user map's current center & resolution │ │ │ │ │ - // │ │ │ │ │ - return this.map.calculateBounds(); │ │ │ │ │ - }, │ │ │ │ │ + matchCase: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: lowerBoundary │ │ │ │ │ + * {Number} or {String} │ │ │ │ │ + * lower boundary for between comparisons. In the case of a String, this │ │ │ │ │ + * can be a combination of text and propertyNames in the form │ │ │ │ │ + * "literal ${propertyName}" │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + lowerBoundary: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ - * This function is to be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: upperBoundary │ │ │ │ │ + * {Number} or {String} │ │ │ │ │ + * upper boundary for between comparisons. In the case of a String, this │ │ │ │ │ + * can be a combination of text and propertyNames in the form │ │ │ │ │ + * "literal ${propertyName}" │ │ │ │ │ */ │ │ │ │ │ - getDataExtent: function() { │ │ │ │ │ - //to be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ + upperBoundary: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter.Comparison │ │ │ │ │ + * Creates a comparison rule. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * rule │ │ │ │ │ * │ │ │ │ │ * 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)]; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Filter.prototype.initialize.apply(this, [options]); │ │ │ │ │ + // since matchCase on PropertyIsLike is not schema compliant, we only │ │ │ │ │ + // want to use this if explicitly asked for │ │ │ │ │ + if (this.type === OpenLayers.Filter.Comparison.LIKE && │ │ │ │ │ + options.matchCase === undefined) { │ │ │ │ │ + this.matchCase = null; │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getZoomForResolution │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * Evaluates this filter in a specific context. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * context - {Object} Context to use in evaluating the filter. If a vector │ │ │ │ │ + * feature is provided, the feature.attributes will be used as context. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {Boolean} The filter applies. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + evaluate: function(context) { │ │ │ │ │ + if (context instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ + context = context.attributes; │ │ │ │ │ + } │ │ │ │ │ + var result = false; │ │ │ │ │ + var got = context[this.property]; │ │ │ │ │ + var exp; │ │ │ │ │ + switch (this.type) { │ │ │ │ │ + case OpenLayers.Filter.Comparison.EQUAL_TO: │ │ │ │ │ + exp = this.value; │ │ │ │ │ + if (!this.matchCase && │ │ │ │ │ + typeof got == "string" && typeof exp == "string") { │ │ │ │ │ + result = (got.toUpperCase() == exp.toUpperCase()); │ │ │ │ │ + } else { │ │ │ │ │ + result = (got == exp); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - 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; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.NOT_EQUAL_TO: │ │ │ │ │ + exp = this.value; │ │ │ │ │ + if (!this.matchCase && │ │ │ │ │ + typeof got == "string" && typeof exp == "string") { │ │ │ │ │ + result = (got.toUpperCase() != exp.toUpperCase()); │ │ │ │ │ } else { │ │ │ │ │ - if (this.resolutions[i] < resolution) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + result = (got != exp); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - zoom = Math.max(0, i - 1); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.LESS_THAN: │ │ │ │ │ + result = got < this.value; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.GREATER_THAN: │ │ │ │ │ + result = got > this.value; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO: │ │ │ │ │ + result = got <= this.value; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO: │ │ │ │ │ + result = got >= this.value; │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.BETWEEN: │ │ │ │ │ + result = (got >= this.lowerBoundary) && │ │ │ │ │ + (got <= this.upperBoundary); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.LIKE: │ │ │ │ │ + var regexp = new RegExp(this.value, "gi"); │ │ │ │ │ + result = regexp.test(got); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Filter.Comparison.IS_NULL: │ │ │ │ │ + result = (got === null); │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLonLatFromViewPortPx │ │ │ │ │ + * APIMethod: value2regex │ │ │ │ │ + * Converts the value of this rule into a regular expression string, │ │ │ │ │ + * according to the wildcard characters specified. This method has to │ │ │ │ │ + * be called after instantiation of this class, if the value is not a │ │ │ │ │ + * regular expression already. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ - * an object with a 'x' │ │ │ │ │ - * and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ + * wildCard - {Char} wildcard character in the above value, default │ │ │ │ │ + * is "*" │ │ │ │ │ + * singleChar - {Char} single-character wildcard in the above value │ │ │ │ │ + * default is "." │ │ │ │ │ + * escapeChar - {Char} escape character in the above value, default is │ │ │ │ │ + * "!" │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in │ │ │ │ │ - * view port , translated into lon/lat by the layer. │ │ │ │ │ + * {String} regular expression string │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + value2regex: function(wildCard, singleChar, escapeChar) { │ │ │ │ │ + if (wildCard == ".") { │ │ │ │ │ + throw new Error("'.' is an unsupported wildCard character for " + │ │ │ │ │ + "OpenLayers.Filter.Comparison"); │ │ │ │ │ } │ │ │ │ │ - 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" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + // set UMN MapServer defaults for unspecified parameters │ │ │ │ │ + wildCard = wildCard ? wildCard : "*"; │ │ │ │ │ + singleChar = singleChar ? singleChar : "."; │ │ │ │ │ + escapeChar = escapeChar ? escapeChar : "!"; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getZIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} the z-index of this layer │ │ │ │ │ - */ │ │ │ │ │ - getZIndex: function() { │ │ │ │ │ - return this.div.style.zIndex; │ │ │ │ │ + this.value = this.value.replace( │ │ │ │ │ + new RegExp("\\" + escapeChar + "(.|$)", "g"), "\\$1"); │ │ │ │ │ + this.value = this.value.replace( │ │ │ │ │ + new RegExp("\\" + singleChar, "g"), "."); │ │ │ │ │ + this.value = this.value.replace( │ │ │ │ │ + new RegExp("\\" + wildCard, "g"), ".*"); │ │ │ │ │ + this.value = this.value.replace( │ │ │ │ │ + new RegExp("\\\\.\\*", "g"), "\\" + wildCard); │ │ │ │ │ + this.value = this.value.replace( │ │ │ │ │ + new RegExp("\\\\\\.", "g"), "\\" + singleChar); │ │ │ │ │ + │ │ │ │ │ + return this.value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setZIndex │ │ │ │ │ + * Method: regex2value │ │ │ │ │ + * Convert the value of this rule from a regular expression string into an │ │ │ │ │ + * ogc literal string using a wildCard of *, a singleChar of ., and an │ │ │ │ │ + * escape of !. Leaves the property unmodified. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zIndex - {Integer} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string value. │ │ │ │ │ */ │ │ │ │ │ - setZIndex: function(zIndex) { │ │ │ │ │ - this.div.style.zIndex = zIndex; │ │ │ │ │ + regex2value: function() { │ │ │ │ │ + │ │ │ │ │ + var value = this.value; │ │ │ │ │ + │ │ │ │ │ + // replace ! with !! │ │ │ │ │ + value = value.replace(/!/g, "!!"); │ │ │ │ │ + │ │ │ │ │ + // replace \. with !. (watching out for \\.) │ │ │ │ │ + value = value.replace(/(\\)?\\\./g, function($0, $1) { │ │ │ │ │ + return $1 ? $0 : "!."; │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + // replace \* with #* (watching out for \\*) │ │ │ │ │ + value = value.replace(/(\\)?\\\*/g, function($0, $1) { │ │ │ │ │ + return $1 ? $0 : "!*"; │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + // replace \\ with \ │ │ │ │ │ + value = value.replace(/\\\\/g, "\\"); │ │ │ │ │ + │ │ │ │ │ + // convert .* to * (the sequence #.* is not allowed) │ │ │ │ │ + value = value.replace(/\.\*/g, "*"); │ │ │ │ │ + │ │ │ │ │ + return value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + clone: function() { │ │ │ │ │ + return OpenLayers.Util.extend(new OpenLayers.Filter.Comparison(), this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter.Comparison" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Filter.Comparison.EQUAL_TO = "=="; │ │ │ │ │ +OpenLayers.Filter.Comparison.NOT_EQUAL_TO = "!="; │ │ │ │ │ +OpenLayers.Filter.Comparison.LESS_THAN = "<"; │ │ │ │ │ +OpenLayers.Filter.Comparison.GREATER_THAN = ">"; │ │ │ │ │ +OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; │ │ │ │ │ +OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; │ │ │ │ │ +OpenLayers.Filter.Comparison.BETWEEN = ".."; │ │ │ │ │ +OpenLayers.Filter.Comparison.LIKE = "~"; │ │ │ │ │ +OpenLayers.Filter.Comparison.IS_NULL = "NULL"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer/Point.js │ │ │ │ │ + OpenLayers/Format/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/Symbolizer.js │ │ │ │ │ + * @requires OpenLayers/Format/XML/VersionedOGC.js │ │ │ │ │ + * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ + * @requires OpenLayers/Filter/Logical.js │ │ │ │ │ + * @requires OpenLayers/Filter/Comparison.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Point │ │ │ │ │ - * A symbolizer used to render point features. │ │ │ │ │ + * Class: OpenLayers.Format.Filter │ │ │ │ │ + * Read/Write ogc:Filter. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer.Point = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeColor │ │ │ │ │ - * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ - * for red). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeOpacity │ │ │ │ │ - * {Number} Stroke opacity (0-1). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeWidth │ │ │ │ │ - * {Number} Pixel stroke width. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeLinecap │ │ │ │ │ - * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: strokeDashstyle │ │ │ │ │ - * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ - * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ - * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ - * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fillColor │ │ │ │ │ - * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fillOpacity │ │ │ │ │ - * {Number} Fill opacity (0-1). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Format.Filter = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pointRadius │ │ │ │ │ - * {Number} Pixel point radius. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIProperty: defaultVersion │ │ │ │ │ + * {String} Version number to assume if none found. Default is "1.0.0". │ │ │ │ │ */ │ │ │ │ │ + defaultVersion: "1.0.0", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: externalGraphic │ │ │ │ │ - * {String} Url to an external graphic that will be used for rendering │ │ │ │ │ - * points. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Write an ogc:Filter given a filter object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} An filter. │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Elment} An ogc:Filter element node. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: graphicWidth │ │ │ │ │ - * {Number} Pixel width for sizing an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read and Filter doc and return an object representing the Filter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String | DOMElement} Data to read. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A filter object. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicHeight │ │ │ │ │ - * {Number} Pixel height for sizing an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.Filter" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter/Function.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicOpacity │ │ │ │ │ - * {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ +/* 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: graphicXOffset │ │ │ │ │ - * {Number} Pixel offset along the positive x axis for displacing an │ │ │ │ │ - * external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Filter.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicYOffset │ │ │ │ │ - * {Number} Pixel offset along the positive y axis for displacing an │ │ │ │ │ - * external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter.Function │ │ │ │ │ + * This class represents a filter function. │ │ │ │ │ + * We are using this class for creation of complex │ │ │ │ │ + * filters that can contain filter functions as values. │ │ │ │ │ + * Nesting function as other functions parameter is supported. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter.Function = OpenLayers.Class(OpenLayers.Filter, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: rotation │ │ │ │ │ - * {Number} The rotation of a graphic in the clockwise direction about its │ │ │ │ │ - * center point (or any point off center as specified by │ │ │ │ │ - * and ). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} Name of the function. │ │ │ │ │ */ │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: graphicName │ │ │ │ │ - * {String} Named graphic to use when rendering points. Supported values │ │ │ │ │ - * include "circle", "square", "star", "x", "cross", and "triangle". │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIProperty: params │ │ │ │ │ + * {Array( || String || Number)} Function parameters │ │ │ │ │ + * For now support only other Functions, String or Number │ │ │ │ │ */ │ │ │ │ │ + params: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Point │ │ │ │ │ - * Create a symbolizer for rendering points. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter.Function │ │ │ │ │ + * Creates a filter function. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ - * │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * function. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new point symbolizer. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Point" │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter.Function" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer/Line.js │ │ │ │ │ + OpenLayers/BaseTypes/Date.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/Symbolizer.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Line │ │ │ │ │ - * A symbolizer used to render line features. │ │ │ │ │ + * Namespace: OpenLayers.Date │ │ │ │ │ + * Contains implementations of Date.parse and date.toISOString that match the │ │ │ │ │ + * ECMAScript 5 specification for parsing RFC 3339 dates. │ │ │ │ │ + * http://tools.ietf.org/html/rfc3339 │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer.Line = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeColor │ │ │ │ │ - * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ - * for red). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeOpacity │ │ │ │ │ - * {Number} Stroke opacity (0-1). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Date = { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: strokeWidth │ │ │ │ │ - * {Number} Pixel stroke width. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: dateRegEx │ │ │ │ │ + * The regex to be used for validating dates. You can provide your own │ │ │ │ │ + * regex for instance for adding support for years before BC. Default │ │ │ │ │ + * value is: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/ │ │ │ │ │ */ │ │ │ │ │ + dateRegEx: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: strokeLinecap │ │ │ │ │ - * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * APIMethod: toISOString │ │ │ │ │ + * Generates a string representing a date. The format of the string follows │ │ │ │ │ + * the profile of ISO 8601 for date and time on the Internet (see │ │ │ │ │ + * http://tools.ietf.org/html/rfc3339). If the toISOString method is │ │ │ │ │ + * available on the Date prototype, that is used. The toISOString │ │ │ │ │ + * method for Date instances is defined in ECMA-262. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * date - {Date} A date object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representing the date (e.g. │ │ │ │ │ + * "2010-08-07T16:58:23.123Z"). If the date does not have a valid time │ │ │ │ │ + * (i.e. isNaN(date.getTime())) this method returns the string "Invalid │ │ │ │ │ + * Date". The ECMA standard says the toISOString method should throw │ │ │ │ │ + * RangeError in this case, but Firefox returns a string instead. For │ │ │ │ │ + * best results, use isNaN(date.getTime()) to determine date validity │ │ │ │ │ + * before generating date strings. │ │ │ │ │ */ │ │ │ │ │ + toISOString: (function() { │ │ │ │ │ + if ("toISOString" in Date.prototype) { │ │ │ │ │ + return function(date) { │ │ │ │ │ + return date.toISOString(); │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + return function(date) { │ │ │ │ │ + var str; │ │ │ │ │ + if (isNaN(date.getTime())) { │ │ │ │ │ + // ECMA-262 says throw RangeError, Firefox returns │ │ │ │ │ + // "Invalid Date" │ │ │ │ │ + str = "Invalid Date"; │ │ │ │ │ + } else { │ │ │ │ │ + str = │ │ │ │ │ + date.getUTCFullYear() + "-" + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCMonth() + 1, 2) + "-" + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCDate(), 2) + "T" + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCHours(), 2) + ":" + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCMinutes(), 2) + ":" + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCSeconds(), 2) + "." + │ │ │ │ │ + OpenLayers.Number.zeroPad(date.getUTCMilliseconds(), 3) + "Z"; │ │ │ │ │ + } │ │ │ │ │ + return str; │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: strokeDashstyle │ │ │ │ │ - * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ - * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ - * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ - * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ + })(), │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Line │ │ │ │ │ - * Create a symbolizer for rendering lines. │ │ │ │ │ + * APIMethod: parse │ │ │ │ │ + * Generate a date object from a string. The format for the string follows │ │ │ │ │ + * the profile of ISO 8601 for date and time on the Internet (see │ │ │ │ │ + * http://tools.ietf.org/html/rfc3339). We don't call the native │ │ │ │ │ + * Date.parse because of inconsistency between implmentations. In │ │ │ │ │ + * Chrome, calling Date.parse with a string that doesn't contain any │ │ │ │ │ + * indication of the timezone (e.g. "2011"), the date is interpreted │ │ │ │ │ + * in local time. On Firefox, the assumption is UTC. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * str - {String} A string representing the date (e.g. │ │ │ │ │ + * "2010", "2010-08", "2010-08-07", "2010-08-07T16:58:23.123Z", │ │ │ │ │ + * "2010-08-07T11:58:23.123-06"). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new line symbolizer. │ │ │ │ │ + * {Date} A date object. If the string could not be parsed, an invalid │ │ │ │ │ + * date is returned (i.e. isNaN(date.getTime())). │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Line" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ + parse: function(str) { │ │ │ │ │ + var date; │ │ │ │ │ + var match = str.match(this.dateRegEx); │ │ │ │ │ + if (match && (match[1] || match[7])) { // must have at least year or time │ │ │ │ │ + var year = parseInt(match[1], 10) || 0; │ │ │ │ │ + var month = (parseInt(match[2], 10) - 1) || 0; │ │ │ │ │ + var day = parseInt(match[3], 10) || 1; │ │ │ │ │ + date = new Date(Date.UTC(year, month, day)); │ │ │ │ │ + // optional time │ │ │ │ │ + var type = match[7]; │ │ │ │ │ + if (type) { │ │ │ │ │ + var hours = parseInt(match[4], 10); │ │ │ │ │ + var minutes = parseInt(match[5], 10); │ │ │ │ │ + var secFrac = parseFloat(match[6]); │ │ │ │ │ + var seconds = secFrac | 0; │ │ │ │ │ + var milliseconds = Math.round(1000 * (secFrac - seconds)); │ │ │ │ │ + date.setUTCHours(hours, minutes, seconds, milliseconds); │ │ │ │ │ + // check offset │ │ │ │ │ + if (type !== "Z") { │ │ │ │ │ + var hoursOffset = parseInt(type, 10); │ │ │ │ │ + var minutesOffset = parseInt(match[8], 10) || 0; │ │ │ │ │ + var offset = -1000 * (60 * (hoursOffset * 60) + minutesOffset * 60); │ │ │ │ │ + date = new Date(date.getTime() + offset); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + date = new Date("invalid"); │ │ │ │ │ + } │ │ │ │ │ + return date; │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer/Polygon.js │ │ │ │ │ + OpenLayers/Format/Filter/v1.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/Symbolizer.js │ │ │ │ │ + * @requires OpenLayers/Format/Filter.js │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Filter/Function.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Date.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Polygon │ │ │ │ │ - * A symbolizer used to render line features. │ │ │ │ │ + * Class: OpenLayers.Format.Filter.v1 │ │ │ │ │ + * Superclass for Filter version 1 parsers. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer.Polygon = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ +OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: strokeColor │ │ │ │ │ - * {String} Color for line stroke. This is a RGB hex value (e.g. "#ff0000" │ │ │ │ │ - * for red). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + ogc: "http://www.opengis.net/ogc", │ │ │ │ │ + gml: "http://www.opengis.net/gml", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: strokeOpacity │ │ │ │ │ - * {Number} Stroke opacity (0-1). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ */ │ │ │ │ │ + defaultPrefix: "ogc", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: strokeWidth │ │ │ │ │ - * {Number} Pixel stroke width. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. │ │ │ │ │ */ │ │ │ │ │ + schemaLocation: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: strokeLinecap │ │ │ │ │ - * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * Constructor: OpenLayers.Format.Filter.v1 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * constructor instead. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: strokeDashstyle │ │ │ │ │ - * {String} Stroke dash style according to the SLD spec. Note that the │ │ │ │ │ - * OpenLayers values for strokeDashstyle ("dot", "dash", "dashdot", │ │ │ │ │ - * "longdash", "longdashdot", or "solid") will not work in SLD, but │ │ │ │ │ - * most SLD patterns will render correctly in OpenLayers. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fillColor │ │ │ │ │ - * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fillOpacity │ │ │ │ │ - * {Number} Fill opacity (0-1). │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Polygon │ │ │ │ │ - * Create a symbolizer for rendering polygons. │ │ │ │ │ + * Method: read │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * data - {DOMElement} A Filter document element. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new polygon symbolizer. │ │ │ │ │ + * {} A filter object. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readers.ogc["Filter"].apply(this, [data, obj]); │ │ │ │ │ + return obj.filter; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Polygon" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer/Text.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/Symbolizer.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Text │ │ │ │ │ - * A symbolizer used to render text labels for features. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Symbolizer.Text = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: label │ │ │ │ │ - * {String} The text for the label. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fontFamily │ │ │ │ │ - * {String} The font family for the label. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fontSize │ │ │ │ │ - * {String} The font size for the label. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fontWeight │ │ │ │ │ - * {String} The font weight for the label. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Property: fontStyle │ │ │ │ │ - * {String} The font style for the label. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + * 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: { │ │ │ │ │ + "ogc": { │ │ │ │ │ + "_expression": function(node) { │ │ │ │ │ + // only the simplest of ogc:expression handled │ │ │ │ │ + // "some text and an attribute"} │ │ │ │ │ + var obj, value = ""; │ │ │ │ │ + for (var child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + switch (child.nodeType) { │ │ │ │ │ + case 1: │ │ │ │ │ + obj = this.readNode(child); │ │ │ │ │ + if (obj.property) { │ │ │ │ │ + value += "${" + obj.property + "}"; │ │ │ │ │ + } else if (obj.value !== undefined) { │ │ │ │ │ + value += obj.value; │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case 3: // text node │ │ │ │ │ + case 4: // cdata section │ │ │ │ │ + value += child.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return value; │ │ │ │ │ + }, │ │ │ │ │ + "Filter": function(node, parent) { │ │ │ │ │ + // Filters correspond to subclasses of OpenLayers.Filter. │ │ │ │ │ + // Since they contain information we don't persist, we │ │ │ │ │ + // create a temporary object and then pass on the filter │ │ │ │ │ + // (ogc:Filter) to the parent obj. │ │ │ │ │ + var obj = { │ │ │ │ │ + fids: [], │ │ │ │ │ + filters: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (obj.fids.length > 0) { │ │ │ │ │ + parent.filter = new OpenLayers.Filter.FeatureId({ │ │ │ │ │ + fids: obj.fids │ │ │ │ │ + }); │ │ │ │ │ + } else if (obj.filters.length > 0) { │ │ │ │ │ + parent.filter = obj.filters[0]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "FeatureId": function(node, obj) { │ │ │ │ │ + var fid = node.getAttribute("fid"); │ │ │ │ │ + if (fid) { │ │ │ │ │ + obj.fids.push(fid); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "And": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ + type: OpenLayers.Filter.Logical.AND │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "Or": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ + type: OpenLayers.Filter.Logical.OR │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "Not": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ + type: OpenLayers.Filter.Logical.NOT │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLessThan": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.LESS_THAN │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsGreaterThan": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.GREATER_THAN │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLessThanOrEqualTo": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsGreaterThanOrEqualTo": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsBetween": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.BETWEEN │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "Literal": function(node, obj) { │ │ │ │ │ + obj.value = OpenLayers.String.numericIf( │ │ │ │ │ + this.getChildValue(node), true); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyName": function(node, filter) { │ │ │ │ │ + filter.property = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "LowerBoundary": function(node, filter) { │ │ │ │ │ + filter.lowerBoundary = OpenLayers.String.numericIf( │ │ │ │ │ + this.readers.ogc._expression.call(this, node), true); │ │ │ │ │ + }, │ │ │ │ │ + "UpperBoundary": function(node, filter) { │ │ │ │ │ + filter.upperBoundary = OpenLayers.String.numericIf( │ │ │ │ │ + this.readers.ogc._expression.call(this, node), true); │ │ │ │ │ + }, │ │ │ │ │ + "Intersects": function(node, obj) { │ │ │ │ │ + this.readSpatial(node, obj, OpenLayers.Filter.Spatial.INTERSECTS); │ │ │ │ │ + }, │ │ │ │ │ + "Within": function(node, obj) { │ │ │ │ │ + this.readSpatial(node, obj, OpenLayers.Filter.Spatial.WITHIN); │ │ │ │ │ + }, │ │ │ │ │ + "Contains": function(node, obj) { │ │ │ │ │ + this.readSpatial(node, obj, OpenLayers.Filter.Spatial.CONTAINS); │ │ │ │ │ + }, │ │ │ │ │ + "DWithin": function(node, obj) { │ │ │ │ │ + this.readSpatial(node, obj, OpenLayers.Filter.Spatial.DWITHIN); │ │ │ │ │ + }, │ │ │ │ │ + "Distance": function(node, obj) { │ │ │ │ │ + obj.distance = parseInt(this.getChildValue(node)); │ │ │ │ │ + obj.distanceUnits = node.getAttribute("units"); │ │ │ │ │ + }, │ │ │ │ │ + "Function": function(node, obj) { │ │ │ │ │ + //TODO write decoder for it │ │ │ │ │ + return; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNull": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.IS_NULL │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Text │ │ │ │ │ - * Create a symbolizer for rendering text labels. │ │ │ │ │ + * Method: readSpatial │ │ │ │ │ * │ │ │ │ │ + * Read a {} filter. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * node - {DOMElement} A DOM element that contains an ogc:expression. │ │ │ │ │ + * obj - {Object} The target object. │ │ │ │ │ + * type - {String} One of the OpenLayers.Filter.Spatial.* constants. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new text symbolizer. │ │ │ │ │ + * {} The created filter. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + readSpatial: function(node, obj, type) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: type │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + filter.value = filter.components[0]; │ │ │ │ │ + delete filter.components; │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Text" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Symbolizer/Raster.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/Symbolizer.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Raster │ │ │ │ │ - * A symbolizer used to render raster images. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Symbolizer.Raster = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Raster │ │ │ │ │ - * Create a symbolizer for rendering rasters. │ │ │ │ │ + * APIMethod: encodeLiteral │ │ │ │ │ + * Generates the string representation of a value for use in │ │ │ │ │ + * elements. The default encoder writes Date values as ISO 8601 │ │ │ │ │ + * strings. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ + * value - {Object} Literal value to encode │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * A new raster symbolizer. │ │ │ │ │ + * {String} String representation of the provided value. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + encodeLiteral: function(value) { │ │ │ │ │ + if (value instanceof Date) { │ │ │ │ │ + value = OpenLayers.Date.toISOString(value); │ │ │ │ │ + } │ │ │ │ │ + return value; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Raster" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Style2.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/Rule.js │ │ │ │ │ - * @requires OpenLayers/Symbolizer/Point.js │ │ │ │ │ - * @requires OpenLayers/Symbolizer/Line.js │ │ │ │ │ - * @requires OpenLayers/Symbolizer/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Symbolizer/Text.js │ │ │ │ │ - * @requires OpenLayers/Symbolizer/Raster.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Style2 │ │ │ │ │ - * This class represents a collection of rules for rendering features. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style2 = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} Style identifier. │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: title │ │ │ │ │ - * {String} Title of this style. │ │ │ │ │ - */ │ │ │ │ │ - title: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: description │ │ │ │ │ - * {String} Description of this style. │ │ │ │ │ - */ │ │ │ │ │ - description: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {} Name of the layer that this style belongs to, usually │ │ │ │ │ - * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ + * Method: writeOgcExpression │ │ │ │ │ + * Limited support for writing OGC expressions. Currently it supports │ │ │ │ │ + * ( || String || Number) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * value - ( || String || Number) │ │ │ │ │ + * node - {DOMElement} A parent DOM element │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} Updated node element. │ │ │ │ │ */ │ │ │ │ │ - layerName: null, │ │ │ │ │ + writeOgcExpression: function(value, node) { │ │ │ │ │ + if (value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ + this.writeNode("Function", value, node); │ │ │ │ │ + } else { │ │ │ │ │ + this.writeNode("Literal", value, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isDefault │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isDefault: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: rules │ │ │ │ │ - * {Array()} Collection of rendering rules. │ │ │ │ │ - */ │ │ │ │ │ - rules: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Style2 │ │ │ │ │ - * Creates a style representing a collection of rendering rules. │ │ │ │ │ + * Method: write │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * style. Any documented properties may be set at construction. │ │ │ │ │ + * filter - {} A filter object. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A new style object. │ │ │ │ │ + * {DOMElement} An ogc:Filter element. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Util.extend(this, config); │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + write: function(filter) { │ │ │ │ │ + return this.writers.ogc["Filter"].apply(this, [filter]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ - this.rules[i].destroy(); │ │ │ │ │ + writers: { │ │ │ │ │ + "ogc": { │ │ │ │ │ + "Filter": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:Filter"); │ │ │ │ │ + this.writeNode(this.getFilterType(filter), filter, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "_featureIds": function(filter) { │ │ │ │ │ + var node = this.createDocumentFragment(); │ │ │ │ │ + for (var i = 0, ii = filter.fids.length; i < ii; ++i) { │ │ │ │ │ + this.writeNode("ogc:FeatureId", filter.fids[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "FeatureId": function(fid) { │ │ │ │ │ + return this.createElementNSPlus("ogc:FeatureId", { │ │ │ │ │ + attributes: { │ │ │ │ │ + fid: fid │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "And": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:And"); │ │ │ │ │ + var childFilter; │ │ │ │ │ + for (var i = 0, ii = filter.filters.length; i < ii; ++i) { │ │ │ │ │ + childFilter = filter.filters[i]; │ │ │ │ │ + this.writeNode( │ │ │ │ │ + this.getFilterType(childFilter), childFilter, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Or": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:Or"); │ │ │ │ │ + var childFilter; │ │ │ │ │ + for (var i = 0, ii = filter.filters.length; i < ii; ++i) { │ │ │ │ │ + childFilter = filter.filters[i]; │ │ │ │ │ + this.writeNode( │ │ │ │ │ + this.getFilterType(childFilter), childFilter, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Not": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:Not"); │ │ │ │ │ + var childFilter = filter.filters[0]; │ │ │ │ │ + this.writeNode( │ │ │ │ │ + this.getFilterType(childFilter), childFilter, node │ │ │ │ │ + ); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLessThan": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsLessThan"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsGreaterThan": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsGreaterThan"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLessThanOrEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsLessThanOrEqualTo"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsGreaterThanOrEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsGreaterThanOrEqualTo"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsBetween": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsBetween"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + this.writeNode("LowerBoundary", filter, node); │ │ │ │ │ + this.writeNode("UpperBoundary", filter, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyName": function(filter) { │ │ │ │ │ + // no ogc:expression handling for now │ │ │ │ │ + return this.createElementNSPlus("ogc:PropertyName", { │ │ │ │ │ + value: filter.property │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Literal": function(value) { │ │ │ │ │ + var encode = this.encodeLiteral || │ │ │ │ │ + OpenLayers.Format.Filter.v1.prototype.encodeLiteral; │ │ │ │ │ + return this.createElementNSPlus("ogc:Literal", { │ │ │ │ │ + value: encode(value) │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "LowerBoundary": function(filter) { │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + var node = this.createElementNSPlus("ogc:LowerBoundary"); │ │ │ │ │ + this.writeOgcExpression(filter.lowerBoundary, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "UpperBoundary": function(filter) { │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + var node = this.createElementNSPlus("ogc:UpperBoundary"); │ │ │ │ │ + this.writeNode("Literal", filter.upperBoundary, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "INTERSECTS": function(filter) { │ │ │ │ │ + return this.writeSpatial(filter, "Intersects"); │ │ │ │ │ + }, │ │ │ │ │ + "WITHIN": function(filter) { │ │ │ │ │ + return this.writeSpatial(filter, "Within"); │ │ │ │ │ + }, │ │ │ │ │ + "CONTAINS": function(filter) { │ │ │ │ │ + return this.writeSpatial(filter, "Contains"); │ │ │ │ │ + }, │ │ │ │ │ + "DWITHIN": function(filter) { │ │ │ │ │ + var node = this.writeSpatial(filter, "DWithin"); │ │ │ │ │ + this.writeNode("Distance", filter, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Distance": function(filter) { │ │ │ │ │ + return this.createElementNSPlus("ogc:Distance", { │ │ │ │ │ + attributes: { │ │ │ │ │ + units: filter.distanceUnits │ │ │ │ │ + }, │ │ │ │ │ + value: filter.distance │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Function": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:Function", { │ │ │ │ │ + attributes: { │ │ │ │ │ + name: filter.name │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + var params = filter.params; │ │ │ │ │ + for (var i = 0, len = params.length; i < len; i++) { │ │ │ │ │ + this.writeOgcExpression(params[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNull": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsNull"); │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + return node; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - delete this.rules; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this style. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this style. │ │ │ │ │ + * Method: getFilterType │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var config = OpenLayers.Util.extend({}, this); │ │ │ │ │ - // clone rules │ │ │ │ │ - if (this.rules) { │ │ │ │ │ - config.rules = []; │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ - config.rules.push(this.rules[i].clone()); │ │ │ │ │ - } │ │ │ │ │ + getFilterType: function(filter) { │ │ │ │ │ + var filterType = this.filterMap[filter.type]; │ │ │ │ │ + if (!filterType) { │ │ │ │ │ + throw "Filter writing not supported for rule type: " + filter.type; │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Style2(config); │ │ │ │ │ + return filterType; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ + /** │ │ │ │ │ + * Property: filterMap │ │ │ │ │ + * {Object} Contains a member for each filter type. Values are node names │ │ │ │ │ + * for corresponding OGC Filter child elements. │ │ │ │ │ + */ │ │ │ │ │ + filterMap: { │ │ │ │ │ + "&&": "And", │ │ │ │ │ + "||": "Or", │ │ │ │ │ + "!": "Not", │ │ │ │ │ + "==": "PropertyIsEqualTo", │ │ │ │ │ + "!=": "PropertyIsNotEqualTo", │ │ │ │ │ + "<": "PropertyIsLessThan", │ │ │ │ │ + ">": "PropertyIsGreaterThan", │ │ │ │ │ + "<=": "PropertyIsLessThanOrEqualTo", │ │ │ │ │ + ">=": "PropertyIsGreaterThanOrEqualTo", │ │ │ │ │ + "..": "PropertyIsBetween", │ │ │ │ │ + "~": "PropertyIsLike", │ │ │ │ │ + "NULL": "PropertyIsNull", │ │ │ │ │ + "BBOX": "BBOX", │ │ │ │ │ + "DWITHIN": "DWITHIN", │ │ │ │ │ + "WITHIN": "WITHIN", │ │ │ │ │ + "CONTAINS": "CONTAINS", │ │ │ │ │ + "INTERSECTS": "INTERSECTS", │ │ │ │ │ + "FID": "_featureIds" │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.Filter.v1" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ + OpenLayers/Format/GML.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 │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * Class: OpenLayers.Format.GML │ │ │ │ │ + * Read/Write GML. Create a new instance with the │ │ │ │ │ + * constructor. Supports the GML simple features profile. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: featureNS │ │ │ │ │ + * {String} Namespace used for feature attributes. Default is │ │ │ │ │ + * "http://mapserver.gis.umn.edu/mapserver". │ │ │ │ │ */ │ │ │ │ │ - URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ + featureNS: "http://mapserver.gis.umn.edu/mapserver", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ - * a single url string. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: featurePrefix │ │ │ │ │ + * {String} Namespace alias (or prefix) for feature nodes. Default is │ │ │ │ │ + * "feature". │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + featurePrefix: "feature", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: params │ │ │ │ │ - * {Object} Hashtable of key/value parameters │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: featureName │ │ │ │ │ + * {String} Element name for features. Default is "featureMember". │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + featureName: "featureMember", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {String} Name of data layer. Default is "features". │ │ │ │ │ */ │ │ │ │ │ - reproject: false, │ │ │ │ │ + layerName: "features", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {Array(String) or String} │ │ │ │ │ - * params - {Object} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * APIProperty: geometryName │ │ │ │ │ + * {String} Name of geometry element. Defaults to "geometry". │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + geometryName: "geometry", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: collectionName │ │ │ │ │ + * {String} Name of featureCollection element. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.url = null; │ │ │ │ │ - this.params = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + collectionName: "FeatureCollection", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - * │ │ │ │ │ + * APIProperty: gmlns │ │ │ │ │ + * {String} GML Namespace. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + gmlns: "http://www.opengis.net/gml", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setUrl │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newUrl - {String} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: extractAttributes │ │ │ │ │ + * {Boolean} Extract attributes from GML. │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(newUrl) { │ │ │ │ │ - this.url = newUrl; │ │ │ │ │ - }, │ │ │ │ │ + extractAttributes: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ + * APIProperty: xy │ │ │ │ │ + * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ + * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ */ │ │ │ │ │ - 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 ret; │ │ │ │ │ - }, │ │ │ │ │ + xy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * Constructor: OpenLayers.Format.GML │ │ │ │ │ + * Create a new parser for GML. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - redraw: function(force) { │ │ │ │ │ - if (force) { │ │ │ │ │ - return this.mergeNewParams({ │ │ │ │ │ - "_olSalt": Math.random() │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + // compile regular expressions once instead of every time they are used │ │ │ │ │ + this.regExes = { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: │ │ │ │ │ - * paramString - {String} │ │ │ │ │ - * urls - {Array(String)} │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read data from a string, and return a list of features. │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ - * on the paramString. │ │ │ │ │ + * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ } │ │ │ │ │ - return urls[Math.floor(product * urls.length)]; │ │ │ │ │ + var featureNodes = this.getElementsByTagNameNS(data.documentElement, │ │ │ │ │ + this.gmlns, │ │ │ │ │ + this.featureName); │ │ │ │ │ + var features = []; │ │ │ │ │ + for (var i = 0; i < featureNodes.length; i++) { │ │ │ │ │ + var feature = this.parseFeature(featureNodes[i]); │ │ │ │ │ + if (feature) { │ │ │ │ │ + features.push(feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return features; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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" │ │ │ │ │ - * │ │ │ │ │ - * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseFeature │ │ │ │ │ + * This function is the core of the GML parsing code in OpenLayers. │ │ │ │ │ + * It creates the geometries that are then attached to the returned │ │ │ │ │ + * feature, and calls parseAttributes() to get attribute data out. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} │ │ │ │ │ + * node - {DOMElement} A GML feature node. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + parseFeature: function(node) { │ │ │ │ │ + // only accept one geometry per feature - look for highest "order" │ │ │ │ │ + var order = ["MultiPolygon", "Polygon", │ │ │ │ │ + "MultiLineString", "LineString", │ │ │ │ │ + "MultiPoint", "Point", "Envelope" │ │ │ │ │ + ]; │ │ │ │ │ + // FIXME: In case we parse a feature with no geometry, but boundedBy an Envelope, │ │ │ │ │ + // this code creates a geometry derived from the Envelope. This is not correct. │ │ │ │ │ + var type, nodeList, geometry, parser; │ │ │ │ │ + for (var i = 0; i < order.length; ++i) { │ │ │ │ │ + type = order[i]; │ │ │ │ │ + nodeList = this.getElementsByTagNameNS(node, this.gmlns, type); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + // only deal with first geometry of this type │ │ │ │ │ + parser = this.parseGeometry[type.toLowerCase()]; │ │ │ │ │ + if (parser) { │ │ │ │ │ + geometry = parser.apply(this, [nodeList[0]]); │ │ │ │ │ + if (this.internalProjection && this.externalProjection) { │ │ │ │ │ + geometry.transform(this.externalProjection, │ │ │ │ │ + this.internalProjection); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + throw new TypeError("Unsupported geometry type: " + type); │ │ │ │ │ + } │ │ │ │ │ + // stop looking for different geometry types │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // 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]; │ │ │ │ │ + var bounds; │ │ │ │ │ + var boxNodes = this.getElementsByTagNameNS(node, this.gmlns, "Box"); │ │ │ │ │ + for (i = 0; i < boxNodes.length; ++i) { │ │ │ │ │ + var boxNode = boxNodes[i]; │ │ │ │ │ + var box = this.parseGeometry["box"].apply(this, [boxNode]); │ │ │ │ │ + var parentNode = boxNode.parentNode; │ │ │ │ │ + var parentName = parentNode.localName || │ │ │ │ │ + parentNode.nodeName.split(":").pop(); │ │ │ │ │ + if (parentName === "boundedBy") { │ │ │ │ │ + bounds = box; │ │ │ │ │ + } else { │ │ │ │ │ + geometry = box.toGeometry(); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - 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. */ │ │ │ │ │ │ │ │ │ │ + // construct feature (optionally with attributes) │ │ │ │ │ + var attributes; │ │ │ │ │ + if (this.extractAttributes) { │ │ │ │ │ + attributes = this.parseAttributes(node); │ │ │ │ │ + } │ │ │ │ │ + var feature = new OpenLayers.Feature.Vector(geometry, attributes); │ │ │ │ │ + feature.bounds = bounds; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Tile.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ + feature.gml = { │ │ │ │ │ + featureType: node.firstChild.nodeName.split(":")[1], │ │ │ │ │ + featureNS: node.firstChild.namespaceURI, │ │ │ │ │ + featureNSPrefix: node.firstChild.prefix │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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, { │ │ │ │ │ + // assign fid - this can come from a "fid" or "id" attribute │ │ │ │ │ + var childNode = node.firstChild; │ │ │ │ │ + var fid; │ │ │ │ │ + while (childNode) { │ │ │ │ │ + if (childNode.nodeType == 1) { │ │ │ │ │ + fid = childNode.getAttribute("fid") || │ │ │ │ │ + childNode.getAttribute("id"); │ │ │ │ │ + if (fid) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + childNode = childNode.nextSibling; │ │ │ │ │ + } │ │ │ │ │ + feature.fid = fid; │ │ │ │ │ + return feature; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: parseGeometry │ │ │ │ │ + * Properties of this object are the functions that parse geometries based │ │ │ │ │ + * on their type. │ │ │ │ │ */ │ │ │ │ │ + parseGeometry: { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.point │ │ │ │ │ + * Given a GML node representing a point geometry, create an OpenLayers │ │ │ │ │ + * point geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A point geometry. │ │ │ │ │ + */ │ │ │ │ │ + point: function(node) { │ │ │ │ │ + /** │ │ │ │ │ + * Three coordinate variations to consider: │ │ │ │ │ + * 1) x y z │ │ │ │ │ + * 2) x, y, z │ │ │ │ │ + * 3) xy │ │ │ │ │ + */ │ │ │ │ │ + var nodeList, coordString; │ │ │ │ │ + var coords = []; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: imgDiv │ │ │ │ │ - * {HTMLImageElement} The image for this tile. │ │ │ │ │ - */ │ │ │ │ │ - imgDiv: null, │ │ │ │ │ + // look for │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, "pos"); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ + coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + // look for │ │ │ │ │ + if (coords.length == 0) { │ │ │ │ │ + nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "coordinates"); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ + coordString = coordString.replace(this.regExes.removeSpace, │ │ │ │ │ + ""); │ │ │ │ │ + coords = coordString.split(","); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageReloadAttempts │ │ │ │ │ - * {Integer} Attempts to load the image. │ │ │ │ │ - */ │ │ │ │ │ - imageReloadAttempts: null, │ │ │ │ │ + // look for │ │ │ │ │ + if (coords.length == 0) { │ │ │ │ │ + nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "coord"); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + var xList = this.getElementsByTagNameNS(nodeList[0], │ │ │ │ │ + this.gmlns, "X"); │ │ │ │ │ + var yList = this.getElementsByTagNameNS(nodeList[0], │ │ │ │ │ + this.gmlns, "Y"); │ │ │ │ │ + if (xList.length > 0 && yList.length > 0) { │ │ │ │ │ + coords = [xList[0].firstChild.nodeValue, │ │ │ │ │ + yList[0].firstChild.nodeValue │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerAlphaHack │ │ │ │ │ - * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ - */ │ │ │ │ │ - layerAlphaHack: null, │ │ │ │ │ + // preserve third dimension │ │ │ │ │ + if (coords.length == 2) { │ │ │ │ │ + coords[2] = null; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - asyncRequestId: null, │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + return new OpenLayers.Geometry.Point(coords[0], coords[1], │ │ │ │ │ + coords[2]); │ │ │ │ │ + } else { │ │ │ │ │ + return new OpenLayers.Geometry.Point(coords[1], coords[0], │ │ │ │ │ + coords[2]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - maxGetUrlLength: null, │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.multipoint │ │ │ │ │ + * Given a GML node representing a multipoint geometry, create an │ │ │ │ │ + * OpenLayers multipoint geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A multipoint geometry. │ │ │ │ │ + */ │ │ │ │ │ + multipoint: function(node) { │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "Point"); │ │ │ │ │ + var components = []; │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + var point; │ │ │ │ │ + for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ + point = this.parseGeometry.point.apply(this, [nodeList[i]]); │ │ │ │ │ + if (point) { │ │ │ │ │ + components.push(point); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.MultiPoint(components); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: canvasContext │ │ │ │ │ - * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ - * the tile image. │ │ │ │ │ - */ │ │ │ │ │ - canvasContext: null, │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.linestring │ │ │ │ │ + * Given a GML node representing a linestring geometry, create an │ │ │ │ │ + * OpenLayers linestring geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A linestring geometry. │ │ │ │ │ + */ │ │ │ │ │ + linestring: function(node, ring) { │ │ │ │ │ + /** │ │ │ │ │ + * Two coordinate variations to consider: │ │ │ │ │ + * 1) x0 y0 z0 x1 y1 z1 │ │ │ │ │ + * 2) x0, y0, z0 x1, y1, z1 │ │ │ │ │ + */ │ │ │ │ │ + var nodeList, coordString; │ │ │ │ │ + var coords = []; │ │ │ │ │ + var points = []; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - crossOriginKeyword: null, │ │ │ │ │ + // look for │ │ │ │ │ + nodeList = this.getElementsByTagNameNS(node, this.gmlns, "posList"); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + coordString = this.getChildValue(nodeList[0]); │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ + coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ + var dim = parseInt(nodeList[0].getAttribute("dimension")); │ │ │ │ │ + var j, x, y, z; │ │ │ │ │ + for (var i = 0; i < coords.length / dim; ++i) { │ │ │ │ │ + j = i * dim; │ │ │ │ │ + x = coords[j]; │ │ │ │ │ + y = coords[j + 1]; │ │ │ │ │ + z = (dim == 2) ? null : coords[j + 2]; │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + points.push(new OpenLayers.Geometry.Point(x, y, z)); │ │ │ │ │ + } else { │ │ │ │ │ + points.push(new OpenLayers.Geometry.Point(y, x, z)); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** 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. │ │ │ │ │ - */ │ │ │ │ │ + // look for │ │ │ │ │ + if (coords.length == 0) { │ │ │ │ │ + nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "coordinates"); │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + coordString = this.getChildValue(nodeList[0]); │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimSpace, │ │ │ │ │ + ""); │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimComma, │ │ │ │ │ + ","); │ │ │ │ │ + var pointList = coordString.split(this.regExes.splitSpace); │ │ │ │ │ + for (var i = 0; i < pointList.length; ++i) { │ │ │ │ │ + coords = pointList[i].split(","); │ │ │ │ │ + if (coords.length == 2) { │ │ │ │ │ + coords[2] = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + points.push(new OpenLayers.Geometry.Point(coords[0], │ │ │ │ │ + coords[1], │ │ │ │ │ + coords[2])); │ │ │ │ │ + } else { │ │ │ │ │ + points.push(new OpenLayers.Geometry.Point(coords[1], │ │ │ │ │ + coords[0], │ │ │ │ │ + coords[2])); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ - OpenLayers.Tile.prototype.initialize.apply(this, arguments); │ │ │ │ │ + var line = null; │ │ │ │ │ + if (points.length != 0) { │ │ │ │ │ + if (ring) { │ │ │ │ │ + line = new OpenLayers.Geometry.LinearRing(points); │ │ │ │ │ + } else { │ │ │ │ │ + line = new OpenLayers.Geometry.LineString(points); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return line; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.url = url; //deprecated remove me │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.multilinestring │ │ │ │ │ + * Given a GML node representing a multilinestring geometry, create an │ │ │ │ │ + * OpenLayers multilinestring geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A multilinestring geometry. │ │ │ │ │ + */ │ │ │ │ │ + multilinestring: function(node) { │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "LineString"); │ │ │ │ │ + var components = []; │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + var line; │ │ │ │ │ + for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ + line = this.parseGeometry.linestring.apply(this, │ │ │ │ │ + [nodeList[i]]); │ │ │ │ │ + if (line) { │ │ │ │ │ + components.push(line); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.MultiLineString(components); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.polygon │ │ │ │ │ + * Given a GML node representing a polygon geometry, create an │ │ │ │ │ + * OpenLayers polygon geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A polygon geometry. │ │ │ │ │ + */ │ │ │ │ │ + polygon: function(node) { │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "LinearRing"); │ │ │ │ │ + var components = []; │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + // this assumes exterior ring first, inner rings after │ │ │ │ │ + var ring; │ │ │ │ │ + for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ + ring = this.parseGeometry.linestring.apply(this, │ │ │ │ │ + [nodeList[i], true]); │ │ │ │ │ + if (ring) { │ │ │ │ │ + components.push(ring); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.Polygon(components); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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: parseGeometry.multipolygon │ │ │ │ │ + * Given a GML node representing a multipolygon geometry, create an │ │ │ │ │ + * OpenLayers multipolygon geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A multipolygon geometry. │ │ │ │ │ + */ │ │ │ │ │ + multipolygon: function(node) { │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "Polygon"); │ │ │ │ │ + var components = []; │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + var polygon; │ │ │ │ │ + for (var i = 0; i < nodeList.length; ++i) { │ │ │ │ │ + polygon = this.parseGeometry.polygon.apply(this, │ │ │ │ │ + [nodeList[i]]); │ │ │ │ │ + if (polygon) { │ │ │ │ │ + components.push(polygon); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Geometry.MultiPolygon(components); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + envelope: function(node) { │ │ │ │ │ + var components = []; │ │ │ │ │ + var coordString; │ │ │ │ │ + var envelope; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + var lpoint = this.getElementsByTagNameNS(node, this.gmlns, "lowerCorner"); │ │ │ │ │ + if (lpoint.length > 0) { │ │ │ │ │ + var coords = []; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: renderTile │ │ │ │ │ - * Internal function to actually initialize the image tile, │ │ │ │ │ - * position it correctly, and set its url. │ │ │ │ │ - */ │ │ │ │ │ - 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(); │ │ │ │ │ + if (lpoint.length > 0) { │ │ │ │ │ + coordString = lpoint[0].firstChild.nodeValue; │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ + coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ } │ │ │ │ │ - }, this); │ │ │ │ │ - } else { │ │ │ │ │ - // synchronous image requests get the url immediately. │ │ │ │ │ - this.url = this.layer.getURL(this.bounds); │ │ │ │ │ - this.initImage(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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(); │ │ │ │ │ - } │ │ │ │ │ - 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: clear │ │ │ │ │ - * Remove the tile from the DOM, clear it of any image related data so that │ │ │ │ │ - * it can be reused in a new location. │ │ │ │ │ - */ │ │ │ │ │ - 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 = ""; │ │ │ │ │ + if (coords.length == 2) { │ │ │ │ │ + coords[2] = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + var lowerPoint = new OpenLayers.Geometry.Point(coords[0], coords[1], coords[2]); │ │ │ │ │ + } else { │ │ │ │ │ + var lowerPoint = new OpenLayers.Geometry.Point(coords[1], coords[0], coords[2]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.removeClass(img, "olImageLoadError"); │ │ │ │ │ - } │ │ │ │ │ - this.canvasContext = null; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getImage │ │ │ │ │ - * Returns or creates and returns the tile image. │ │ │ │ │ - */ │ │ │ │ │ - getImage: function() { │ │ │ │ │ - if (!this.imgDiv) { │ │ │ │ │ - this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ + var upoint = this.getElementsByTagNameNS(node, this.gmlns, "upperCorner"); │ │ │ │ │ + if (upoint.length > 0) { │ │ │ │ │ + var coords = []; │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + if (upoint.length > 0) { │ │ │ │ │ + coordString = upoint[0].firstChild.nodeValue; │ │ │ │ │ + coordString = coordString.replace(this.regExes.trimSpace, ""); │ │ │ │ │ + coords = coordString.split(this.regExes.splitSpace); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (coords.length == 2) { │ │ │ │ │ + coords[2] = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + var upperPoint = new OpenLayers.Geometry.Point(coords[0], coords[1], coords[2]); │ │ │ │ │ + } else { │ │ │ │ │ + var upperPoint = new OpenLayers.Geometry.Point(coords[1], coords[0], coords[2]); │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - return this.imgDiv; │ │ │ │ │ - }, │ │ │ │ │ + if (lowerPoint && upperPoint) { │ │ │ │ │ + components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y)); │ │ │ │ │ + components.push(new OpenLayers.Geometry.Point(upperPoint.x, lowerPoint.y)); │ │ │ │ │ + components.push(new OpenLayers.Geometry.Point(upperPoint.x, upperPoint.y)); │ │ │ │ │ + components.push(new OpenLayers.Geometry.Point(lowerPoint.x, upperPoint.y)); │ │ │ │ │ + components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y)); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - setImage: function(img) { │ │ │ │ │ - this.imgDiv = img; │ │ │ │ │ - }, │ │ │ │ │ + var ring = new OpenLayers.Geometry.LinearRing(components); │ │ │ │ │ + envelope = new OpenLayers.Geometry.Polygon([ring]); │ │ │ │ │ + } │ │ │ │ │ + return envelope; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: initImage │ │ │ │ │ - * Creates the content for the frame on the tile. │ │ │ │ │ - */ │ │ │ │ │ - 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"); │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry.box │ │ │ │ │ + * Given a GML node representing a box geometry, create an │ │ │ │ │ + * OpenLayers.Bounds. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} A GML node. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A bounds representing the box. │ │ │ │ │ + */ │ │ │ │ │ + box: function(node) { │ │ │ │ │ + var nodeList = this.getElementsByTagNameNS(node, this.gmlns, │ │ │ │ │ + "coordinates"); │ │ │ │ │ + var coordString; │ │ │ │ │ + var coords, beginPoint = null, │ │ │ │ │ + endPoint = null; │ │ │ │ │ + if (nodeList.length > 0) { │ │ │ │ │ + coordString = nodeList[0].firstChild.nodeValue; │ │ │ │ │ + coords = coordString.split(" "); │ │ │ │ │ + if (coords.length == 2) { │ │ │ │ │ + beginPoint = coords[0].split(","); │ │ │ │ │ + endPoint = coords[1].split(","); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (beginPoint !== null && endPoint !== null) { │ │ │ │ │ + return new OpenLayers.Bounds(parseFloat(beginPoint[0]), │ │ │ │ │ + parseFloat(beginPoint[1]), │ │ │ │ │ + parseFloat(endPoint[0]), │ │ │ │ │ + parseFloat(endPoint[1])); │ │ │ │ │ } │ │ │ │ │ - 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: setImgSrc │ │ │ │ │ - * Sets the source for the tile image │ │ │ │ │ + * Method: parseAttributes │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * url - {String} or undefined to hide the image │ │ │ │ │ + * node - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An attributes object. │ │ │ │ │ */ │ │ │ │ │ - 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"); │ │ │ │ │ + parseAttributes: function(node) { │ │ │ │ │ + var attributes = {}; │ │ │ │ │ + // assume attributes are children of the first type 1 child │ │ │ │ │ + var childNode = node.firstChild; │ │ │ │ │ + var children, i, child, grandchildren, grandchild, name, value; │ │ │ │ │ + while (childNode) { │ │ │ │ │ + if (childNode.nodeType == 1) { │ │ │ │ │ + // attributes are type 1 children with one type 3 child │ │ │ │ │ + children = childNode.childNodes; │ │ │ │ │ + for (i = 0; i < children.length; ++i) { │ │ │ │ │ + child = children[i]; │ │ │ │ │ + if (child.nodeType == 1) { │ │ │ │ │ + grandchildren = child.childNodes; │ │ │ │ │ + if (grandchildren.length == 1) { │ │ │ │ │ + grandchild = grandchildren[0]; │ │ │ │ │ + if (grandchild.nodeType == 3 || │ │ │ │ │ + grandchild.nodeType == 4) { │ │ │ │ │ + name = (child.prefix) ? │ │ │ │ │ + child.nodeName.split(":")[1] : │ │ │ │ │ + child.nodeName; │ │ │ │ │ + value = grandchild.nodeValue.replace( │ │ │ │ │ + this.regExes.trimSpace, ""); │ │ │ │ │ + attributes[name] = value; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // If child has no childNodes (grandchildren), │ │ │ │ │ + // set an attribute with null value. │ │ │ │ │ + // e.g. becomes │ │ │ │ │ + // {fieldname: null} │ │ │ │ │ + attributes[child.nodeName.split(":").pop()] = null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + childNode = childNode.nextSibling; │ │ │ │ │ } │ │ │ │ │ + return attributes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTile │ │ │ │ │ - * Get the tile's markup. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Generate a GML document string given a list of features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} List of features to │ │ │ │ │ + * serialize into a string. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The tile's markup │ │ │ │ │ + * {String} A string representing the GML document. │ │ │ │ │ */ │ │ │ │ │ - getTile: function() { │ │ │ │ │ - return this.frame ? this.frame : this.getImage(); │ │ │ │ │ + write: function(features) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ + features = [features]; │ │ │ │ │ + } │ │ │ │ │ + var gml = this.createElementNS("http://www.opengis.net/wfs", │ │ │ │ │ + "wfs:" + this.collectionName); │ │ │ │ │ + for (var i = 0; i < features.length; i++) { │ │ │ │ │ + gml.appendChild(this.createFeatureXML(features[i])); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [gml]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: createFeatureXML │ │ │ │ │ + * Accept an OpenLayers.Feature.Vector, and build a GML node for it. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature to be built as GML. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ - * or if it's currently loading. │ │ │ │ │ + * {DOMElement} A node reprensting the feature in GML. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + createFeatureXML: function(feature) { │ │ │ │ │ + var geometry = feature.geometry; │ │ │ │ │ + var geometryNode = this.buildGeometryNode(geometry); │ │ │ │ │ + var geomContainer = this.createElementNS(this.featureNS, │ │ │ │ │ + this.featurePrefix + ":" + │ │ │ │ │ + this.geometryName); │ │ │ │ │ + geomContainer.appendChild(geometryNode); │ │ │ │ │ + var featureNode = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:" + this.featureName); │ │ │ │ │ + var featureContainer = this.createElementNS(this.featureNS, │ │ │ │ │ + this.featurePrefix + ":" + │ │ │ │ │ + this.layerName); │ │ │ │ │ + var fid = feature.fid || feature.id; │ │ │ │ │ + featureContainer.setAttribute("fid", fid); │ │ │ │ │ + featureContainer.appendChild(geomContainer); │ │ │ │ │ + for (var attr in feature.attributes) { │ │ │ │ │ + var attrText = this.createTextNode(feature.attributes[attr]); │ │ │ │ │ + var nodename = attr.substring(attr.lastIndexOf(":") + 1); │ │ │ │ │ + var attrContainer = this.createElementNS(this.featureNS, │ │ │ │ │ + this.featurePrefix + ":" + │ │ │ │ │ + nodename); │ │ │ │ │ + attrContainer.appendChild(attrText); │ │ │ │ │ + featureContainer.appendChild(attrContainer); │ │ │ │ │ } │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - return backBuffer; │ │ │ │ │ + featureNode.appendChild(featureContainer); │ │ │ │ │ + return featureNode; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageLoad │ │ │ │ │ - * Handler for the image onload event │ │ │ │ │ + * APIMethod: buildGeometryNode │ │ │ │ │ */ │ │ │ │ │ - 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')"; │ │ │ │ │ + buildGeometryNode: function(geometry) { │ │ │ │ │ + if (this.externalProjection && this.internalProjection) { │ │ │ │ │ + geometry = geometry.clone(); │ │ │ │ │ + geometry.transform(this.internalProjection, │ │ │ │ │ + this.externalProjection); │ │ │ │ │ } │ │ │ │ │ + var className = geometry.CLASS_NAME; │ │ │ │ │ + var type = className.substring(className.lastIndexOf(".") + 1); │ │ │ │ │ + var builder = this.buildGeometry[type.toLowerCase()]; │ │ │ │ │ + return builder.apply(this, [geometry]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageError │ │ │ │ │ - * Handler for the image onerror event │ │ │ │ │ + * Property: buildGeometry │ │ │ │ │ + * Object containing methods to do the actual geometry node building │ │ │ │ │ + * based on geometry type. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + buildGeometry: { │ │ │ │ │ + // TBD retrieve the srs from layer │ │ │ │ │ + // srsName is non-standard, so not including it until it's right. │ │ │ │ │ + // gml.setAttribute("srsName", │ │ │ │ │ + // "http://www.opengis.net/gml/srs/epsg.xml#4326"); │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.point │ │ │ │ │ + * Given an OpenLayers point geometry, create a GML point. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A point geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML point node. │ │ │ │ │ + */ │ │ │ │ │ + point: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:Point"); │ │ │ │ │ + gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.multipoint │ │ │ │ │ + * Given an OpenLayers multipoint geometry, create a GML multipoint. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A multipoint geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML multipoint node. │ │ │ │ │ + */ │ │ │ │ │ + multipoint: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:MultiPoint"); │ │ │ │ │ + var points = geometry.components; │ │ │ │ │ + var pointMember, pointGeom; │ │ │ │ │ + for (var i = 0; i < points.length; i++) { │ │ │ │ │ + pointMember = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:pointMember"); │ │ │ │ │ + pointGeom = this.buildGeometry.point.apply(this, │ │ │ │ │ + [points[i]]); │ │ │ │ │ + pointMember.appendChild(pointGeom); │ │ │ │ │ + gml.appendChild(pointMember); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: stopLoading │ │ │ │ │ - * Stops a loading sequence so won't be executed. │ │ │ │ │ - */ │ │ │ │ │ - stopLoading: function() { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ - window.clearTimeout(this._loadTimeout); │ │ │ │ │ - delete this._loadTimeout; │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.linestring │ │ │ │ │ + * Given an OpenLayers linestring geometry, create a GML linestring. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A linestring geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML linestring node. │ │ │ │ │ + */ │ │ │ │ │ + linestring: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:LineString"); │ │ │ │ │ + gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.multilinestring │ │ │ │ │ + * Given an OpenLayers multilinestring geometry, create a GML │ │ │ │ │ + * multilinestring. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A multilinestring │ │ │ │ │ + * geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML multilinestring node. │ │ │ │ │ + */ │ │ │ │ │ + multilinestring: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:MultiLineString"); │ │ │ │ │ + var lines = geometry.components; │ │ │ │ │ + var lineMember, lineGeom; │ │ │ │ │ + for (var i = 0; i < lines.length; ++i) { │ │ │ │ │ + lineMember = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:lineStringMember"); │ │ │ │ │ + lineGeom = this.buildGeometry.linestring.apply(this, │ │ │ │ │ + [lines[i]]); │ │ │ │ │ + lineMember.appendChild(lineGeom); │ │ │ │ │ + gml.appendChild(lineMember); │ │ │ │ │ + } │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.linearring │ │ │ │ │ + * Given an OpenLayers linearring geometry, create a GML linearring. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A linearring geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML linearring node. │ │ │ │ │ + */ │ │ │ │ │ + linearring: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:LinearRing"); │ │ │ │ │ + gml.appendChild(this.buildCoordinatesNode(geometry)); │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.polygon │ │ │ │ │ + * Given an OpenLayers polygon geometry, create a GML polygon. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A polygon geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML polygon node. │ │ │ │ │ + */ │ │ │ │ │ + polygon: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:Polygon"); │ │ │ │ │ + var rings = geometry.components; │ │ │ │ │ + var ringMember, ringGeom, type; │ │ │ │ │ + for (var i = 0; i < rings.length; ++i) { │ │ │ │ │ + type = (i == 0) ? "outerBoundaryIs" : "innerBoundaryIs"; │ │ │ │ │ + ringMember = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:" + type); │ │ │ │ │ + ringGeom = this.buildGeometry.linearring.apply(this, │ │ │ │ │ + [rings[i]]); │ │ │ │ │ + ringMember.appendChild(ringGeom); │ │ │ │ │ + gml.appendChild(ringMember); │ │ │ │ │ + } │ │ │ │ │ + return gml; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.multipolygon │ │ │ │ │ + * Given an OpenLayers multipolygon geometry, create a GML multipolygon. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} A multipolygon │ │ │ │ │ + * geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML multipolygon node. │ │ │ │ │ + */ │ │ │ │ │ + multipolygon: function(geometry) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:MultiPolygon"); │ │ │ │ │ + var polys = geometry.components; │ │ │ │ │ + var polyMember, polyGeom; │ │ │ │ │ + for (var i = 0; i < polys.length; ++i) { │ │ │ │ │ + polyMember = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:polygonMember"); │ │ │ │ │ + polyGeom = this.buildGeometry.polygon.apply(this, │ │ │ │ │ + [polys[i]]); │ │ │ │ │ + polyMember.appendChild(polyGeom); │ │ │ │ │ + gml.appendChild(polyMember); │ │ │ │ │ + } │ │ │ │ │ + return gml; │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildGeometry.bounds │ │ │ │ │ + * Given an OpenLayers bounds, create a GML box. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} A bounds object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A GML box node. │ │ │ │ │ + */ │ │ │ │ │ + bounds: function(bounds) { │ │ │ │ │ + var gml = this.createElementNS(this.gmlns, "gml:Box"); │ │ │ │ │ + gml.appendChild(this.buildCoordinatesNode(bounds)); │ │ │ │ │ + return gml; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: │ │ │ │ │ + * Method: buildCoordinates │ │ │ │ │ + * builds the coordinates XmlNode │ │ │ │ │ * (code) │ │ │ │ │ - * var context = tile.getCanvasContext(); │ │ │ │ │ - * if (context) { │ │ │ │ │ - * var data = context.canvas.toDataURL('image/jpeg'); │ │ │ │ │ - * } │ │ │ │ │ + * ... │ │ │ │ │ * (end) │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * {XmlNode} created xmlNode │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + buildCoordinatesNode: function(geometry) { │ │ │ │ │ + var coordinatesNode = this.createElementNS(this.gmlns, │ │ │ │ │ + "gml:coordinates"); │ │ │ │ │ + coordinatesNode.setAttribute("decimal", "."); │ │ │ │ │ + coordinatesNode.setAttribute("cs", ","); │ │ │ │ │ + coordinatesNode.setAttribute("ts", " "); │ │ │ │ │ + │ │ │ │ │ + var parts = []; │ │ │ │ │ + │ │ │ │ │ + if (geometry instanceof OpenLayers.Bounds) { │ │ │ │ │ + parts.push(geometry.left + "," + geometry.bottom); │ │ │ │ │ + parts.push(geometry.right + "," + geometry.top); │ │ │ │ │ + } else { │ │ │ │ │ + var points = (geometry.components) ? geometry.components : [geometry]; │ │ │ │ │ + for (var i = 0; i < points.length; i++) { │ │ │ │ │ + parts.push(points[i].x + "," + points[i].y); │ │ │ │ │ } │ │ │ │ │ - return this.canvasContext; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile.Image" │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ + var txtNode = this.createTextNode(parts.join(" ")); │ │ │ │ │ + coordinatesNode.appendChild(txtNode); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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; │ │ │ │ │ -}()); │ │ │ │ │ + return coordinatesNode; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.GML" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Grid.js │ │ │ │ │ + OpenLayers/Format/GML/Base.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/GML.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * Though required in the full build, if the GML format is excluded, we set │ │ │ │ │ + * the namespace here. │ │ │ │ │ */ │ │ │ │ │ +if (!OpenLayers.Format.GML) { │ │ │ │ │ + OpenLayers.Format.GML = {}; │ │ │ │ │ +} │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Grid │ │ │ │ │ - * Base class for layers that use a lattice of tiles. Create a new grid │ │ │ │ │ - * layer with the constructor. │ │ │ │ │ + * Class: OpenLayers.Format.GML.Base │ │ │ │ │ + * Superclass for GML parsers. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: backBuffer │ │ │ │ │ - * {DOMElement} The back buffer. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - backBuffer: null, │ │ │ │ │ + namespaces: { │ │ │ │ │ + gml: "http://www.opengis.net/gml", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance", │ │ │ │ │ + wfs: "http://www.opengis.net/wfs" // this is a convenience for reading wfs:FeatureCollection │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ */ │ │ │ │ │ - gridResolution: null, │ │ │ │ │ + defaultPrefix: "gml", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: backBufferResolution │ │ │ │ │ - * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ - * updated each time a back buffer is created. │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. │ │ │ │ │ */ │ │ │ │ │ - backBufferResolution: null, │ │ │ │ │ + schemaLocation: 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: featureType │ │ │ │ │ + * {Array(String) or String} The local (without prefix) feature typeName(s). │ │ │ │ │ */ │ │ │ │ │ - backBufferLonLat: null, │ │ │ │ │ + featureType: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: featureNS │ │ │ │ │ + * {String} The feature namespace. Must be set in the options at │ │ │ │ │ + * construction. │ │ │ │ │ */ │ │ │ │ │ - backBufferTimerId: null, │ │ │ │ │ + featureNS: 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. │ │ │ │ │ + * APIProperty: geometry │ │ │ │ │ + * {String} Name of geometry element. Defaults to "geometry". If null, it │ │ │ │ │ + * will be set on when the first geometry is parsed. │ │ │ │ │ */ │ │ │ │ │ - removeBackBufferDelay: null, │ │ │ │ │ + geometryName: "geometry", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: extractAttributes │ │ │ │ │ + * {Boolean} Extract attributes from GML. Default is true. │ │ │ │ │ */ │ │ │ │ │ - className: null, │ │ │ │ │ + extractAttributes: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: srsName │ │ │ │ │ + * {String} URI for spatial reference system. This is optional for │ │ │ │ │ + * single part geometries and mandatory for collections and multis. │ │ │ │ │ + * If set, the srsName attribute will be written for all geometries. │ │ │ │ │ + * Default is null. │ │ │ │ │ */ │ │ │ │ │ + srsName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: gridLayout │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * APIProperty: xy │ │ │ │ │ + * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) │ │ │ │ │ + * Changing is not recommended, a new Format should be instantiated. │ │ │ │ │ */ │ │ │ │ │ - gridLayout: null, │ │ │ │ │ + xy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: geometryTypes │ │ │ │ │ + * {Object} Maps OpenLayers geometry class names to GML element names. │ │ │ │ │ + * Use before accessing this property. │ │ │ │ │ */ │ │ │ │ │ - rowSign: null, │ │ │ │ │ + geometryTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: transitionendEvents │ │ │ │ │ - * {Array} Event names for transitionend │ │ │ │ │ + * Property: singleFeatureType │ │ │ │ │ + * {Boolean} True if there is only 1 featureType, and not an array │ │ │ │ │ + * of featuretypes. │ │ │ │ │ */ │ │ │ │ │ - transitionendEvents: [ │ │ │ │ │ - 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ - 'oTransitionEnd' │ │ │ │ │ - ], │ │ │ │ │ + singleFeatureType: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: autoConfig │ │ │ │ │ + * {Boolean} Indicates if the format was configured without a , │ │ │ │ │ + * but auto-configured and during read. │ │ │ │ │ + * Subclasses making use of auto-configuration should make │ │ │ │ │ + * the first call to the method (usually in the read method) │ │ │ │ │ + * with true as 3rd argument, so the auto-configured featureType can be │ │ │ │ │ + * reset and the format can be reused for subsequent reads with data from │ │ │ │ │ + * different featureTypes. Set to false after read if you want to keep the │ │ │ │ │ + * auto-configured values. │ │ │ │ │ */ │ │ │ │ │ - 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: initProperties │ │ │ │ │ - * Set any properties that depend on the value of singleTile. │ │ │ │ │ - * Currently sets removeBackBufferDelay and className │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - initProperties: function() { │ │ │ │ │ - if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ - this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.options.className === undefined) { │ │ │ │ │ - this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ - 'olLayerGrid'; │ │ │ │ │ - } │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g), │ │ │ │ │ + featureMember: (/^(.*:)?featureMembers?$/) │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ + * Constructor: OpenLayers.Format.GML.Base │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * or constructor │ │ │ │ │ + * instead. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ - OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * Called when the layer is removed from the map. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct the layer and clear the grid. │ │ │ │ │ + * Valid options properties: │ │ │ │ │ + * featureType - {Array(String) or String} Local (without prefix) feature │ │ │ │ │ + * typeName(s) (required for write). │ │ │ │ │ + * featureNS - {String} Feature namespace (required for write). │ │ │ │ │ + * geometryName - {String} Geometry element name (required for write). │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - │ │ │ │ │ - this.grid = null; │ │ │ │ │ - this.tileSize = null; │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.setGeometryTypes(); │ │ │ │ │ + if (options && options.featureNS) { │ │ │ │ │ + this.setNamespace("feature", options.featureNS); │ │ │ │ │ + } │ │ │ │ │ + this.singleFeatureType = !options || (typeof options.featureType === "string"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: read │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ + * data - {DOMElement} A gml:featureMember element, a gml:featureMembers │ │ │ │ │ + * element, or an element containing either of the above at any level. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearGrid │ │ │ │ │ - * Go through and remove all tiles from the grid, calling │ │ │ │ │ - * destroy() on each of them to kill circular references │ │ │ │ │ + * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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 features = []; │ │ │ │ │ + this.readNode(data, { │ │ │ │ │ + features: features │ │ │ │ │ + }, true); │ │ │ │ │ + if (features.length == 0) { │ │ │ │ │ + // look for gml:featureMember elements │ │ │ │ │ + var elements = this.getElementsByTagNameNS( │ │ │ │ │ + data, this.namespaces.gml, "featureMember" │ │ │ │ │ + ); │ │ │ │ │ + if (elements.length) { │ │ │ │ │ + for (var i = 0, len = elements.length; i < len; ++i) { │ │ │ │ │ + this.readNode(elements[i], { │ │ │ │ │ + features: features │ │ │ │ │ + }, true); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // look for gml:featureMembers elements (this is v3, but does no harm here) │ │ │ │ │ + var elements = this.getElementsByTagNameNS( │ │ │ │ │ + data, this.namespaces.gml, "featureMembers" │ │ │ │ │ + ); │ │ │ │ │ + if (elements.length) { │ │ │ │ │ + // there can be only one │ │ │ │ │ + this.readNode(elements[0], { │ │ │ │ │ + features: features │ │ │ │ │ + }, true); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - this.grid = []; │ │ │ │ │ - this.gridResolution = null; │ │ │ │ │ - this.gridLayout = 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. │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ } │ │ │ │ │ + return features; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * Method: readNode │ │ │ │ │ + * Shorthand for applying one of the named readers given the node │ │ │ │ │ + * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ + * generally extend or modify the second. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} Is this ever used? │ │ │ │ │ - * │ │ │ │ │ + * node - {DOMElement} The node to be read (required). │ │ │ │ │ + * obj - {Object} The object to be modified (optional). │ │ │ │ │ + * first - {Boolean} Should be set to true for the first node read. This │ │ │ │ │ + * is usually the readNode call in the read method. Without this being │ │ │ │ │ + * set, auto-configured properties will stick on subsequent reads. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ + * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + readNode: function(node, obj, first) { │ │ │ │ │ + // on subsequent calls of format.read(), we want to reset auto- │ │ │ │ │ + // configured properties and auto-configure again. │ │ │ │ │ + if (first === true && this.autoConfig === true) { │ │ │ │ │ + this.featureType = null; │ │ │ │ │ + delete this.namespaceAlias[this.featureNS]; │ │ │ │ │ + delete this.namespaces["feature"]; │ │ │ │ │ + this.featureNS = null; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //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(); │ │ │ │ │ + // featureType auto-configuration │ │ │ │ │ + if (!this.featureNS && (!(node.prefix in this.namespaces) && │ │ │ │ │ + node.parentNode.namespaceURI == this.namespaces["gml"] && │ │ │ │ │ + this.regExes.featureMember.test(node.parentNode.nodeName))) { │ │ │ │ │ + this.featureType = node.nodeName.split(":").pop(); │ │ │ │ │ + this.setNamespace("feature", node.namespaceURI); │ │ │ │ │ + this.featureNS = node.namespaceURI; │ │ │ │ │ + this.autoConfig = true; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // 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; │ │ │ │ │ + return OpenLayers.Format.XML.prototype.readNode.apply(this, [node, obj]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + readers: { │ │ │ │ │ + "gml": { │ │ │ │ │ + "_inherit": function(node, obj, container) { │ │ │ │ │ + // To be implemented by version specific parsers │ │ │ │ │ + }, │ │ │ │ │ + "featureMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "featureMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "name": function(node, obj) { │ │ │ │ │ + obj.name = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "boundedBy": function(node, obj) { │ │ │ │ │ + var container = {}; │ │ │ │ │ + this.readChildNodes(node, container); │ │ │ │ │ + if (container.components && container.components.length > 0) { │ │ │ │ │ + obj.bounds = container.components[0]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Point": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + points: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + container.components.push(obj.points[0]); │ │ │ │ │ + }, │ │ │ │ │ + "coordinates": function(node, obj) { │ │ │ │ │ + var str = this.getChildValue(node).replace( │ │ │ │ │ + this.regExes.trimSpace, "" │ │ │ │ │ + ); │ │ │ │ │ + str = str.replace(this.regExes.trimComma, ","); │ │ │ │ │ + var pointList = str.split(this.regExes.splitSpace); │ │ │ │ │ + var coords; │ │ │ │ │ + var numPoints = pointList.length; │ │ │ │ │ + var points = new Array(numPoints); │ │ │ │ │ + for (var i = 0; i < numPoints; ++i) { │ │ │ │ │ + coords = pointList[i].split(","); │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + points[i] = new OpenLayers.Geometry.Point( │ │ │ │ │ + coords[0], coords[1], coords[2] │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + points[i] = new OpenLayers.Geometry.Point( │ │ │ │ │ + coords[1], coords[0], coords[2] │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ + obj.points = points; │ │ │ │ │ + }, │ │ │ │ │ + "coord": function(node, obj) { │ │ │ │ │ + var coord = {}; │ │ │ │ │ + this.readChildNodes(node, coord); │ │ │ │ │ + if (!obj.points) { │ │ │ │ │ + obj.points = []; │ │ │ │ │ + } │ │ │ │ │ + obj.points.push(new OpenLayers.Geometry.Point( │ │ │ │ │ + coord.x, coord.y, coord.z │ │ │ │ │ + )); │ │ │ │ │ + }, │ │ │ │ │ + "X": function(node, coord) { │ │ │ │ │ + coord.x = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Y": function(node, coord) { │ │ │ │ │ + coord.y = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Z": function(node, coord) { │ │ │ │ │ + coord.z = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "MultiPoint": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiPoint(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + }, │ │ │ │ │ + "pointMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "LineString": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + container.components.push( │ │ │ │ │ + new OpenLayers.Geometry.LineString(obj.points) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "MultiLineString": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + }, │ │ │ │ │ + "lineStringMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "Polygon": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + outer: null, │ │ │ │ │ + inner: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + obj.inner.unshift(obj.outer); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + container.components.push( │ │ │ │ │ + new OpenLayers.Geometry.Polygon(obj.inner) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "LinearRing": function(node, obj) { │ │ │ │ │ + var container = {}; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, container]); │ │ │ │ │ + this.readChildNodes(node, container); │ │ │ │ │ + obj.components = [new OpenLayers.Geometry.LinearRing( │ │ │ │ │ + container.points │ │ │ │ │ + )]; │ │ │ │ │ + }, │ │ │ │ │ + "MultiPolygon": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiPolygon(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + }, │ │ │ │ │ + "polygonMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "GeometryCollection": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.Collection(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + }, │ │ │ │ │ + "geometryMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "feature": { │ │ │ │ │ + "*": function(node, obj) { │ │ │ │ │ + // The node can either be named like the featureType, or it │ │ │ │ │ + // can be a child of the feature:featureType. Children can be │ │ │ │ │ + // geometry or attributes. │ │ │ │ │ + var name; │ │ │ │ │ + var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ + // Since an attribute can have the same name as the feature type │ │ │ │ │ + // we only want to read the node as a feature if the parent │ │ │ │ │ + // node can have feature nodes as children. In this case, the │ │ │ │ │ + // obj.features property is set. │ │ │ │ │ + if (obj.features) { │ │ │ │ │ + if (!this.singleFeatureType && │ │ │ │ │ + (OpenLayers.Util.indexOf(this.featureType, local) !== -1)) { │ │ │ │ │ + name = "_typeName"; │ │ │ │ │ + } else if (local === this.featureType) { │ │ │ │ │ + name = "_typeName"; │ │ │ │ │ } │ │ │ │ │ - this.initGriddedTiles(bounds); │ │ │ │ │ } else { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ + // Assume attribute elements have one child node and that the child │ │ │ │ │ + // is a text node. Otherwise assume it is a geometry node. │ │ │ │ │ + if (node.childNodes.length == 0 || │ │ │ │ │ + (node.childNodes.length == 1 && node.firstChild.nodeType == 3)) { │ │ │ │ │ + if (this.extractAttributes) { │ │ │ │ │ + name = "_attribute"; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + name = "_geometry"; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (name) { │ │ │ │ │ + this.readers.feature[name].apply(this, [node, obj]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "_typeName": function(node, obj) { │ │ │ │ │ + var container = { │ │ │ │ │ + components: [], │ │ │ │ │ + attributes: {} │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, container); │ │ │ │ │ + // look for common gml namespaced elements │ │ │ │ │ + if (container.name) { │ │ │ │ │ + container.attributes.name = container.name; │ │ │ │ │ + } │ │ │ │ │ + var feature = new OpenLayers.Feature.Vector( │ │ │ │ │ + container.components[0], container.attributes │ │ │ │ │ + ); │ │ │ │ │ + if (!this.singleFeatureType) { │ │ │ │ │ + feature.type = node.nodeName.split(":").pop(); │ │ │ │ │ + feature.namespace = node.namespaceURI; │ │ │ │ │ + } │ │ │ │ │ + var fid = node.getAttribute("fid") || │ │ │ │ │ + this.getAttributeNS(node, this.namespaces["gml"], "id"); │ │ │ │ │ + if (fid) { │ │ │ │ │ + feature.fid = fid; │ │ │ │ │ + } │ │ │ │ │ + if (this.internalProjection && this.externalProjection && │ │ │ │ │ + feature.geometry) { │ │ │ │ │ + feature.geometry.transform( │ │ │ │ │ + this.externalProjection, this.internalProjection │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (container.bounds) { │ │ │ │ │ + feature.bounds = container.bounds; │ │ │ │ │ + } │ │ │ │ │ + obj.features.push(feature); │ │ │ │ │ + }, │ │ │ │ │ + "_geometry": function(node, obj) { │ │ │ │ │ + if (!this.geometryName) { │ │ │ │ │ + this.geometryName = node.nodeName.split(":").pop(); │ │ │ │ │ } │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "_attribute": function(node, obj) { │ │ │ │ │ + var local = node.localName || node.nodeName.split(":").pop(); │ │ │ │ │ + var value = this.getChildValue(node); │ │ │ │ │ + obj.attributes[local] = value; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "wfs": { │ │ │ │ │ + "FeatureCollection": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: write │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * loc - {} map location │ │ │ │ │ + * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ + * An array of features or a single feature. │ │ │ │ │ * │ │ │ │ │ * 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). │ │ │ │ │ + * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ + * element will be returned. Given a single feature, a doc with a │ │ │ │ │ + * gml:featureMember element will be returned. │ │ │ │ │ */ │ │ │ │ │ - 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) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + write: function(features) { │ │ │ │ │ + var name; │ │ │ │ │ + if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ + name = "featureMembers"; │ │ │ │ │ + } else { │ │ │ │ │ + name = "featureMember"; │ │ │ │ │ } │ │ │ │ │ - return data; │ │ │ │ │ - }, │ │ │ │ │ + var root = this.writeNode("gml:" + name, features); │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + root, this.namespaces["xsi"], │ │ │ │ │ + "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyTile │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ - */ │ │ │ │ │ - destroyTile: function(tile) { │ │ │ │ │ - this.removeTileMonitoringHooks(tile); │ │ │ │ │ - tile.destroy(); │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + writers: { │ │ │ │ │ + "gml": { │ │ │ │ │ + "featureMember": function(feature) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:featureMember"); │ │ │ │ │ + this.writeNode("feature:_typeName", feature, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MultiPoint": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:MultiPoint"); │ │ │ │ │ + var components = geometry.components || [geometry]; │ │ │ │ │ + for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ + this.writeNode("pointMember", components[i], node); │ │ │ │ │ } │ │ │ │ │ - distance = newDistance; │ │ │ │ │ - serverResolution = newResolution; │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "pointMember": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:pointMember"); │ │ │ │ │ + this.writeNode("Point", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MultiLineString": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:MultiLineString"); │ │ │ │ │ + var components = geometry.components || [geometry]; │ │ │ │ │ + for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ + this.writeNode("lineStringMember", components[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "lineStringMember": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:lineStringMember"); │ │ │ │ │ + this.writeNode("LineString", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MultiPolygon": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:MultiPolygon"); │ │ │ │ │ + var components = geometry.components || [geometry]; │ │ │ │ │ + for (var i = 0, ii = components.length; i < ii; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "polygonMember", components[i], node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "polygonMember": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:polygonMember"); │ │ │ │ │ + this.writeNode("Polygon", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "GeometryCollection": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:GeometryCollection"); │ │ │ │ │ + for (var i = 0, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("geometryMember", geometry.components[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "geometryMember": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:geometryMember"); │ │ │ │ │ + var child = this.writeNode("feature:_geometry", geometry); │ │ │ │ │ + node.appendChild(child.firstChild); │ │ │ │ │ + return node; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "feature": { │ │ │ │ │ + "_typeName": function(feature) { │ │ │ │ │ + var node = this.createElementNSPlus("feature:" + this.featureType, { │ │ │ │ │ + attributes: { │ │ │ │ │ + fid: feature.fid │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + this.writeNode("feature:_geometry", feature.geometry, node); │ │ │ │ │ + } │ │ │ │ │ + for (var name in feature.attributes) { │ │ │ │ │ + var value = feature.attributes[name]; │ │ │ │ │ + if (value != null) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "feature:_attribute", { │ │ │ │ │ + name: name, │ │ │ │ │ + value: value │ │ │ │ │ + }, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "_geometry": function(geometry) { │ │ │ │ │ + if (this.externalProjection && this.internalProjection) { │ │ │ │ │ + geometry = geometry.clone().transform( │ │ │ │ │ + this.internalProjection, this.externalProjection │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + var node = this.createElementNSPlus( │ │ │ │ │ + "feature:" + this.geometryName │ │ │ │ │ + ); │ │ │ │ │ + var type = this.geometryTypes[geometry.CLASS_NAME]; │ │ │ │ │ + var child = this.writeNode("gml:" + type, geometry, node); │ │ │ │ │ + if (this.srsName) { │ │ │ │ │ + child.setAttribute("srsName", this.srsName); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "_attribute": function(obj) { │ │ │ │ │ + return this.createElementNSPlus("feature:" + obj.name, { │ │ │ │ │ + value: obj.value │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "wfs": { │ │ │ │ │ + "FeatureCollection": function(features) { │ │ │ │ │ + /** │ │ │ │ │ + * This is only here because GML2 only describes abstract │ │ │ │ │ + * feature collections. Typically, you would not be using │ │ │ │ │ + * the GML format to write wfs elements. This just provides │ │ │ │ │ + * some way to write out lists of features. GML3 defines the │ │ │ │ │ + * featureMembers element, so that is used by default instead. │ │ │ │ │ + */ │ │ │ │ │ + var node = this.createElementNSPlus("wfs:FeatureCollection"); │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("gml:featureMember", features[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ } │ │ │ │ │ - resolution = serverResolution; │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: setGeometryTypes │ │ │ │ │ + * Sets the mapping. │ │ │ │ │ */ │ │ │ │ │ - getServerZoom: function() { │ │ │ │ │ - var resolution = this.getServerResolution(); │ │ │ │ │ - return this.serverResolutions ? │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ - this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ + setGeometryTypes: function() { │ │ │ │ │ + this.geometryTypes = { │ │ │ │ │ + "OpenLayers.Geometry.Point": "Point", │ │ │ │ │ + "OpenLayers.Geometry.MultiPoint": "MultiPoint", │ │ │ │ │ + "OpenLayers.Geometry.LineString": "LineString", │ │ │ │ │ + "OpenLayers.Geometry.MultiLineString": "MultiLineString", │ │ │ │ │ + "OpenLayers.Geometry.Polygon": "Polygon", │ │ │ │ │ + "OpenLayers.Geometry.MultiPolygon": "MultiPolygon", │ │ │ │ │ + "OpenLayers.Geometry.Collection": "GeometryCollection" │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: applyBackBuffer │ │ │ │ │ - * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resolution - {Number} The resolution to transition to. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.GML.Base" │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ - } │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/GML/v3.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var ratio = this.backBufferResolution / resolution; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - // 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'; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/GML/Base.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // 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'; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.GML.v3 │ │ │ │ │ + * Parses GML version 3. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * Create a back buffer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ - * grid isn't initialized yet. │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. The writers │ │ │ │ │ + * conform with the Simple Features Profile for GML. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeBackBuffer │ │ │ │ │ - * Remove back buffer from DOM. │ │ │ │ │ + * Property: curve │ │ │ │ │ + * {Boolean} Write gml:Curve instead of gml:LineString elements. This also │ │ │ │ │ + * affects the elements in multi-part geometries. Default is false. │ │ │ │ │ + * To write gml:Curve elements instead of gml:LineString, set curve │ │ │ │ │ + * to true in the options to the contstructor (cannot be changed after │ │ │ │ │ + * instantiation). │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + curve: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} │ │ │ │ │ - * dy - {Number} │ │ │ │ │ + * Property: multiCurve │ │ │ │ │ + * {Boolean} Write gml:MultiCurve instead of gml:MultiLineString. Since │ │ │ │ │ + * the latter is deprecated in GML 3, the default is true. To write │ │ │ │ │ + * gml:MultiLineString instead of gml:MultiCurve, set multiCurve to │ │ │ │ │ + * false in the options to the constructor (cannot be changed after │ │ │ │ │ + * instantiation). │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - if (!this.singleTile) { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + multiCurve: 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 - {} │ │ │ │ │ + * Property: surface │ │ │ │ │ + * {Boolean} Write gml:Surface instead of gml:Polygon elements. This also │ │ │ │ │ + * affects the elements in multi-part geometries. Default is false. │ │ │ │ │ + * To write gml:Surface elements instead of gml:Polygon, set surface │ │ │ │ │ + * to true in the options to the contstructor (cannot be changed after │ │ │ │ │ + * instantiation). │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ - }, │ │ │ │ │ + surface: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTilesBounds │ │ │ │ │ - * Return the bounds of the tile grid. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object representing the bounds of all the │ │ │ │ │ - * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ - * onscreen). │ │ │ │ │ + * Property: multiSurface │ │ │ │ │ + * {Boolean} Write gml:multiSurface instead of gml:MultiPolygon. Since │ │ │ │ │ + * the latter is deprecated in GML 3, the default is true. To write │ │ │ │ │ + * gml:MultiPolygon instead of gml:multiSurface, set multiSurface to │ │ │ │ │ + * false in the options to the constructor (cannot be changed after │ │ │ │ │ + * instantiation). │ │ │ │ │ */ │ │ │ │ │ - getTilesBounds: function() { │ │ │ │ │ - var bounds = null; │ │ │ │ │ - │ │ │ │ │ - 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(); │ │ │ │ │ - │ │ │ │ │ - bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ - bottomLeftTileBounds.bottom, │ │ │ │ │ - bottomLeftTileBounds.left + width, │ │ │ │ │ - bottomLeftTileBounds.bottom + height); │ │ │ │ │ - } │ │ │ │ │ - return bounds; │ │ │ │ │ - }, │ │ │ │ │ + multiSurface: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initSingleTile │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - initSingleTile: function(bounds) { │ │ │ │ │ - this.events.triggerEvent("retile"); │ │ │ │ │ - │ │ │ │ │ - //determine new tile bounds │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ - var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ - │ │ │ │ │ - var tileBounds = │ │ │ │ │ - new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ - center.lat - (tileHeight / 2), │ │ │ │ │ - center.lon + (tileWidth / 2), │ │ │ │ │ - center.lat + (tileHeight / 2)); │ │ │ │ │ - │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ - lon: tileBounds.left, │ │ │ │ │ - lat: tileBounds.top │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (!this.grid.length) { │ │ │ │ │ - this.grid[0] = []; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var tile = this.grid[0][0]; │ │ │ │ │ - if (!tile) { │ │ │ │ │ - tile = this.addTile(tileBounds, px); │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ - │ │ │ │ │ - // store the resolution of the grid │ │ │ │ │ - this.gridResolution = this.getServerResolution(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateGridLayout │ │ │ │ │ - * Generate parameters for the grid layout. │ │ │ │ │ + * Constructor: OpenLayers.Format.GML.v3 │ │ │ │ │ + * Create a parser for GML v3. │ │ │ │ │ * │ │ │ │ │ * 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} │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * Valid options properties: │ │ │ │ │ + * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ + * featureNS - {String} Feature namespace (required). │ │ │ │ │ + * geometryName - {String} Geometry element name. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: │ │ │ │ │ - * {} The tile origin. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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 origin; │ │ │ │ │ + readers: { │ │ │ │ │ + "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "_inherit": function(node, obj, container) { │ │ │ │ │ + // SRSReferenceGroup attributes │ │ │ │ │ + var dim = parseInt(node.getAttribute("srsDimension"), 10) || │ │ │ │ │ + (container && container.srsDimension); │ │ │ │ │ + if (dim) { │ │ │ │ │ + obj.srsDimension = dim; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "featureMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "Curve": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + points: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + container.components.push( │ │ │ │ │ + new OpenLayers.Geometry.LineString(obj.points) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "segments": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "LineStringSegment": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (obj.points) { │ │ │ │ │ + Array.prototype.push.apply(container.points, obj.points); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "pos": function(node, obj) { │ │ │ │ │ + var str = this.getChildValue(node).replace( │ │ │ │ │ + this.regExes.trimSpace, "" │ │ │ │ │ + ); │ │ │ │ │ + var coords = str.split(this.regExes.splitSpace); │ │ │ │ │ + var point; │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + point = new OpenLayers.Geometry.Point( │ │ │ │ │ + coords[0], coords[1], coords[2] │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + point = new OpenLayers.Geometry.Point( │ │ │ │ │ + coords[1], coords[0], coords[2] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + obj.points = [point]; │ │ │ │ │ + }, │ │ │ │ │ + "posList": function(node, obj) { │ │ │ │ │ + var str = this.getChildValue(node).replace( │ │ │ │ │ + this.regExes.trimSpace, "" │ │ │ │ │ + ); │ │ │ │ │ + var coords = str.split(this.regExes.splitSpace); │ │ │ │ │ + // The "dimension" attribute is from the GML 3.0.1 spec. │ │ │ │ │ + var dim = obj.srsDimension || │ │ │ │ │ + parseInt(node.getAttribute("srsDimension") || node.getAttribute("dimension"), 10) || 2; │ │ │ │ │ + var j, x, y, z; │ │ │ │ │ + var numPoints = coords.length / dim; │ │ │ │ │ + var points = new Array(numPoints); │ │ │ │ │ + for (var i = 0, len = coords.length; i < len; i += dim) { │ │ │ │ │ + x = coords[i]; │ │ │ │ │ + y = coords[i + 1]; │ │ │ │ │ + z = (dim == 2) ? undefined : coords[i + 2]; │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + points[i / dim] = new OpenLayers.Geometry.Point(x, y, z); │ │ │ │ │ + } else { │ │ │ │ │ + points[i / dim] = new OpenLayers.Geometry.Point(y, x, z); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + obj.points = points; │ │ │ │ │ + }, │ │ │ │ │ + "Surface": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "patches": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "PolygonPatch": function(node, obj) { │ │ │ │ │ + this.readers.gml.Polygon.apply(this, [node, obj]); │ │ │ │ │ + }, │ │ │ │ │ + "exterior": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.outer = obj.components[0]; │ │ │ │ │ + }, │ │ │ │ │ + "interior": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.inner.push(obj.components[0]); │ │ │ │ │ + }, │ │ │ │ │ + "MultiCurve": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (obj.components.length > 0) { │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiLineString(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "curveMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "MultiSurface": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + components: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readers.gml._inherit.apply(this, [node, obj, container]); │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (obj.components.length > 0) { │ │ │ │ │ + container.components = [ │ │ │ │ │ + new OpenLayers.Geometry.MultiPolygon(obj.components) │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "surfaceMember": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "surfaceMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "pointMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "lineStringMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "polygonMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "geometryMembers": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "Envelope": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + points: new Array(2) │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + var min = obj.points[0]; │ │ │ │ │ + var max = obj.points[1]; │ │ │ │ │ + container.components.push( │ │ │ │ │ + new OpenLayers.Bounds(min.x, min.y, max.x, max.y) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "lowerCorner": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readers.gml.pos.apply(this, [node, obj]); │ │ │ │ │ + container.points[0] = obj.points[0]; │ │ │ │ │ + }, │ │ │ │ │ + "upperCorner": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readers.gml.pos.apply(this, [node, obj]); │ │ │ │ │ + container.points[1] = obj.points[0]; │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.GML.Base.prototype.readers["gml"]), │ │ │ │ │ + "feature": OpenLayers.Format.GML.Base.prototype.readers["feature"], │ │ │ │ │ + "wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"] │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileBoundsForGridIndex │ │ │ │ │ + * Method: write │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * row - {Number} The row of the grid │ │ │ │ │ - * col - {Number} The column of the grid │ │ │ │ │ + * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ + * An array of features or a single feature. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The bounds for the tile at (row, col) │ │ │ │ │ + * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ + * element will be returned. Given a single feature, a doc with a │ │ │ │ │ + * gml:featureMember element will be returned. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ + write: function(features) { │ │ │ │ │ + var name; │ │ │ │ │ + if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ + name = "featureMembers"; │ │ │ │ │ + } else { │ │ │ │ │ + name = "featureMember"; │ │ │ │ │ + } │ │ │ │ │ + var root = this.writeNode("gml:" + name, features); │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + root, this.namespaces["xsi"], │ │ │ │ │ + "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ ); │ │ │ │ │ + │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initGriddedTiles │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - │ │ │ │ │ - var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ - this.gridLayout = tileLayout; │ │ │ │ │ - │ │ │ │ │ - var tilelon = tileLayout.tilelon; │ │ │ │ │ - var tilelat = tileLayout.tilelat; │ │ │ │ │ - │ │ │ │ │ - var layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ - var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ - │ │ │ │ │ - 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; │ │ │ │ │ - │ │ │ │ │ - var tileData = [], │ │ │ │ │ - center = this.map.getCenter(); │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ + writers: { │ │ │ │ │ + "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "featureMembers": function(features) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:featureMembers"); │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("feature:_typeName", features[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Point": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Point"); │ │ │ │ │ + this.writeNode("pos", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "pos": function(point) { │ │ │ │ │ + // only 2d for simple features profile │ │ │ │ │ + var pos = (this.xy) ? │ │ │ │ │ + (point.x + " " + point.y) : (point.y + " " + point.x); │ │ │ │ │ + return this.createElementNSPlus("gml:pos", { │ │ │ │ │ + value: pos │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "LineString": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:LineString"); │ │ │ │ │ + this.writeNode("posList", geometry.components, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Curve": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Curve"); │ │ │ │ │ + this.writeNode("segments", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "segments": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:segments"); │ │ │ │ │ + this.writeNode("LineStringSegment", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LineStringSegment": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:LineStringSegment"); │ │ │ │ │ + this.writeNode("posList", geometry.components, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "posList": function(points) { │ │ │ │ │ + // only 2d for simple features profile │ │ │ │ │ + var len = points.length; │ │ │ │ │ + var parts = new Array(len); │ │ │ │ │ + var point; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + point = points[i]; │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + parts[i] = point.x + " " + point.y; │ │ │ │ │ + } else { │ │ │ │ │ + parts[i] = point.y + " " + point.x; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return this.createElementNSPlus("gml:posList", { │ │ │ │ │ + value: parts.join(" ") │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Surface": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Surface"); │ │ │ │ │ + this.writeNode("patches", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "patches": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:patches"); │ │ │ │ │ + this.writeNode("PolygonPatch", geometry, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PolygonPatch": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:PolygonPatch", { │ │ │ │ │ + attributes: { │ │ │ │ │ + interpolation: "planar" │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("exterior", geometry.components[0], node); │ │ │ │ │ + for (var i = 1, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "interior", geometry.components[i], node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Polygon": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Polygon"); │ │ │ │ │ + this.writeNode("exterior", geometry.components[0], node); │ │ │ │ │ + for (var i = 1, len = geometry.components.length; i < len; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "interior", geometry.components[i], node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "exterior": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:exterior"); │ │ │ │ │ + this.writeNode("LinearRing", ring, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "interior": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:interior"); │ │ │ │ │ + this.writeNode("LinearRing", ring, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LinearRing": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:LinearRing"); │ │ │ │ │ + this.writeNode("posList", ring.components, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MultiCurve": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:MultiCurve"); │ │ │ │ │ + var components = geometry.components || [geometry]; │ │ │ │ │ + for (var i = 0, len = components.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("curveMember", components[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "curveMember": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:curveMember"); │ │ │ │ │ + if (this.curve) { │ │ │ │ │ + this.writeNode("Curve", geometry, node); │ │ │ │ │ } else { │ │ │ │ │ - tile.moveTo(tileBounds, px, false); │ │ │ │ │ + this.writeNode("LineString", geometry, node); │ │ │ │ │ } │ │ │ │ │ - var tileCenter = tileBounds.getCenterLonLat(); │ │ │ │ │ - tileData.push({ │ │ │ │ │ - tile: tile, │ │ │ │ │ - distance: Math.pow(tileCenter.lon - center.lon, 2) + │ │ │ │ │ - Math.pow(tileCenter.lat - center.lat, 2) │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "MultiSurface": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:MultiSurface"); │ │ │ │ │ + var components = geometry.components || [geometry]; │ │ │ │ │ + for (var i = 0, len = components.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("surfaceMember", components[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "surfaceMember": function(polygon) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:surfaceMember"); │ │ │ │ │ + if (this.surface) { │ │ │ │ │ + this.writeNode("Surface", polygon, node); │ │ │ │ │ + } else { │ │ │ │ │ + this.writeNode("Polygon", polygon, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Envelope": function(bounds) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Envelope"); │ │ │ │ │ + this.writeNode("lowerCorner", bounds, node); │ │ │ │ │ + this.writeNode("upperCorner", bounds, node); │ │ │ │ │ + // srsName attribute is required for gml:Envelope │ │ │ │ │ + if (this.srsName) { │ │ │ │ │ + node.setAttribute("srsName", this.srsName); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "lowerCorner": function(bounds) { │ │ │ │ │ + // only 2d for simple features profile │ │ │ │ │ + var pos = (this.xy) ? │ │ │ │ │ + (bounds.left + " " + bounds.bottom) : │ │ │ │ │ + (bounds.bottom + " " + bounds.left); │ │ │ │ │ + return this.createElementNSPlus("gml:lowerCorner", { │ │ │ │ │ + value: pos │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ + }, │ │ │ │ │ + "upperCorner": function(bounds) { │ │ │ │ │ + // only 2d for simple features profile │ │ │ │ │ + var pos = (this.xy) ? │ │ │ │ │ + (bounds.right + " " + bounds.top) : │ │ │ │ │ + (bounds.top + " " + bounds.right); │ │ │ │ │ + return this.createElementNSPlus("gml:upperCorner", { │ │ │ │ │ + value: pos │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.GML.Base.prototype.writers["gml"]), │ │ │ │ │ + "feature": OpenLayers.Format.GML.Base.prototype.writers["feature"], │ │ │ │ │ + "wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"] │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMaxExtent │ │ │ │ │ - * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ - * potential specific implementations in sub-classes.) │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Method: setGeometryTypes │ │ │ │ │ + * Sets the mapping. │ │ │ │ │ */ │ │ │ │ │ - getMaxExtent: function() { │ │ │ │ │ - return this.maxExtent; │ │ │ │ │ + setGeometryTypes: function() { │ │ │ │ │ + this.geometryTypes = { │ │ │ │ │ + "OpenLayers.Geometry.Point": "Point", │ │ │ │ │ + "OpenLayers.Geometry.MultiPoint": "MultiPoint", │ │ │ │ │ + "OpenLayers.Geometry.LineString": (this.curve === true) ? "Curve" : "LineString", │ │ │ │ │ + "OpenLayers.Geometry.MultiLineString": (this.multiCurve === false) ? "MultiLineString" : "MultiCurve", │ │ │ │ │ + "OpenLayers.Geometry.Polygon": (this.surface === true) ? "Surface" : "Polygon", │ │ │ │ │ + "OpenLayers.Geometry.MultiPolygon": (this.multiSurface === false) ? "MultiPolygon" : "MultiSurface", │ │ │ │ │ + "OpenLayers.Geometry.Collection": "GeometryCollection" │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.GML.v3" │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: │ │ │ │ │ - * tile - {} │ │ │ │ │ - */ │ │ │ │ │ - addTileMonitoringHooks: function(tile) { │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/Filter/v1_1_0.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var replacingCls = 'olTileReplacing'; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/Filter/v1.js │ │ │ │ │ + * @requires OpenLayers/Format/GML/v3.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - 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"); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.Filter.v1_1_0 │ │ │ │ │ + * Write ogc:Filter version 1.1.0. │ │ │ │ │ + * │ │ │ │ │ + * Differences from the v1.0.0 parser: │ │ │ │ │ + * - uses GML v3 instead of GML v2 │ │ │ │ │ + * - reads matchCase attribute on ogc:PropertyIsEqual and │ │ │ │ │ + * ogc:PropertyIsNotEqual elements. │ │ │ │ │ + * - writes matchCase attribute from comparison filters of type EQUAL_TO, │ │ │ │ │ + * NOT_EQUAL_TO and LIKE. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.GML.v3, OpenLayers.Format.Filter.v1, { │ │ │ │ │ │ │ │ │ │ - tile.onLoadError = function() { │ │ │ │ │ - this.events.triggerEvent("tileerror", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.1.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.1.0", │ │ │ │ │ │ │ │ │ │ - tile.events.on({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - "loaderror": tile.onLoadError, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} http://www.opengis.net/ogc/filter/1.1.0/filter.xsd │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/ogc/filter/1.1.0/filter.xsd", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.Filter.v1_1_0 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * constructor instead. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.GML.v3.prototype.initialize.apply( │ │ │ │ │ + this, [options] │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ + /** │ │ │ │ │ + * 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: { │ │ │ │ │ + "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "PropertyIsEqualTo": function(node, obj) { │ │ │ │ │ + var matchCase = node.getAttribute("matchCase"); │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.EQUAL_TO, │ │ │ │ │ + matchCase: !(matchCase === "false" || matchCase === "0") │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNotEqualTo": function(node, obj) { │ │ │ │ │ + var matchCase = node.getAttribute("matchCase"); │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO, │ │ │ │ │ + matchCase: !(matchCase === "false" || matchCase === "0") │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLike": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.LIKE │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + var wildCard = node.getAttribute("wildCard"); │ │ │ │ │ + var singleChar = node.getAttribute("singleChar"); │ │ │ │ │ + var esc = node.getAttribute("escapeChar"); │ │ │ │ │ + filter.value2regex(wildCard, singleChar, esc); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ + */ │ │ │ │ │ + writers: { │ │ │ │ │ + "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "PropertyIsEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", { │ │ │ │ │ + attributes: { │ │ │ │ │ + matchCase: filter.matchCase │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNotEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", { │ │ │ │ │ + attributes: { │ │ │ │ │ + matchCase: filter.matchCase │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLike": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsLike", { │ │ │ │ │ + attributes: { │ │ │ │ │ + matchCase: filter.matchCase, │ │ │ │ │ + wildCard: "*", │ │ │ │ │ + singleChar: ".", │ │ │ │ │ + escapeChar: "!" │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + // no ogc:expression handling for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // convert regex string to ogc string │ │ │ │ │ + this.writeNode("Literal", filter.regex2value(), node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "BBOX": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:BBOX"); │ │ │ │ │ + // PropertyName is optional in 1.1.0 │ │ │ │ │ + filter.property && this.writeNode("PropertyName", filter, node); │ │ │ │ │ + var box = this.writeNode("gml:Envelope", filter.value); │ │ │ │ │ + if (filter.projection) { │ │ │ │ │ + box.setAttribute("srsName", filter.projection); │ │ │ │ │ + } │ │ │ │ │ + node.appendChild(box); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "SortBy": function(sortProperties) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:SortBy"); │ │ │ │ │ + for (var i = 0, l = sortProperties.length; i < l; i++) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "ogc:SortProperty", │ │ │ │ │ + sortProperties[i], │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "SortProperty": function(sortProperty) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:SortProperty"); │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "ogc:PropertyName", │ │ │ │ │ + sortProperty, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "ogc:SortOrder", │ │ │ │ │ + (sortProperty.order == 'DESC') ? 'DESC' : 'ASC', │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "SortOrder": function(value) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:SortOrder", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: writeSpatial │ │ │ │ │ + * │ │ │ │ │ + * Read a {} filter and converts it into XML. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} The filter. │ │ │ │ │ + * name - {String} Name of the generated XML element. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The created XML element. │ │ │ │ │ + */ │ │ │ │ │ + writeSpatial: function(filter, name) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:" + name); │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + if (filter.value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ + this.writeNode("Function", filter.value, node); │ │ │ │ │ } else { │ │ │ │ │ - break; │ │ │ │ │ + var child; │ │ │ │ │ + if (filter.value instanceof OpenLayers.Geometry) { │ │ │ │ │ + child = this.writeNode("feature:_geometry", filter.value).firstChild; │ │ │ │ │ + } else { │ │ │ │ │ + child = this.writeNode("gml:Envelope", filter.value); │ │ │ │ │ + } │ │ │ │ │ + if (filter.projection) { │ │ │ │ │ + child.setAttribute("srsName", filter.projection); │ │ │ │ │ + } │ │ │ │ │ + node.appendChild(child); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0" │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/OWSCommon/v1_0_0.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.OWSCommon.v1_0_0 │ │ │ │ │ + * Parser for OWS Common version 1.0.0. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.OWSCommon.v1_0_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeExcessTiles │ │ │ │ │ - * When the size of the map or the buffer changes, we may need to │ │ │ │ │ - * remove some excess rows and columns. │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - removeExcessTiles: function(rows, columns) { │ │ │ │ │ - var i, l; │ │ │ │ │ - │ │ │ │ │ - // 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + namespaces: { │ │ │ │ │ + ows: "http://www.opengis.net/ows", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink" │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMapResize │ │ │ │ │ - * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ - * dimensions of the map pane. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - } │ │ │ │ │ + readers: { │ │ │ │ │ + "ows": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "ExceptionReport": function(node, obj) { │ │ │ │ │ + obj.success = false; │ │ │ │ │ + obj.exceptionReport = { │ │ │ │ │ + version: node.getAttribute('version'), │ │ │ │ │ + language: node.getAttribute('language'), │ │ │ │ │ + exceptions: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj.exceptionReport); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.OWSCommon.v1.prototype.readers.ows) │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + writers: { │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1.prototype.writers.ows │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_0_0" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/TileManager.js │ │ │ │ │ + OpenLayers/Format/WFST/v1_1_0.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/Util.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * @requires OpenLayers/Format/WFST/v1.js │ │ │ │ │ + * @requires OpenLayers/Format/Filter/v1_1_0.js │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1_0_0.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.TileManager │ │ │ │ │ - * Provides queueing of image requests and caching of image elements. │ │ │ │ │ + * Class: OpenLayers.Format.WFST.v1_1_0 │ │ │ │ │ + * A format for creating WFS v1.1.0 transactions. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ - * 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: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.Filter.v1_1_0, OpenLayers.Format.WFST.v1, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: version │ │ │ │ │ + * {String} WFS version number. │ │ │ │ │ + */ │ │ │ │ │ + version: "1.1.0", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocations │ │ │ │ │ + * {Object} Properties are namespace aliases, values are schema locations. │ │ │ │ │ + */ │ │ │ │ │ + schemaLocations: { │ │ │ │ │ + "wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WFST.v1_1_0 │ │ │ │ │ + * A class for parsing and generating WFS v1.1.0 transactions. │ │ │ │ │ + * │ │ │ │ │ + * To read additional information like hit count (numberOfFeatures) from │ │ │ │ │ + * the FeatureCollection, call the method │ │ │ │ │ + * with {output: "object"} as 2nd argument. Note that it is possible to │ │ │ │ │ + * just request the hit count from a WFS 1.1.0 server with the │ │ │ │ │ + * resultType="hits" request parameter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ + * │ │ │ │ │ + * Valid options properties: │ │ │ │ │ + * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ + * featureNS - {String} Feature namespace (optional). │ │ │ │ │ + * featurePrefix - {String} Feature namespace alias (optional - only used │ │ │ │ │ + * if featureNS is provided). Default is 'feature'. │ │ │ │ │ + * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.Filter.v1_1_0.prototype.initialize.apply(this, [options]); │ │ │ │ │ + OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: readNode │ │ │ │ │ + * Shorthand for applying one of the named readers given the node │ │ │ │ │ + * namespace and local name. Readers take two args (node, obj) and │ │ │ │ │ + * generally extend or modify the second. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {DOMElement} The node to be read (required). │ │ │ │ │ + * obj - {Object} The object to be modified (optional). │ │ │ │ │ + * first - {Boolean} Should be set to true for the first node read. This │ │ │ │ │ + * is usually the readNode call in the read method. Without this being │ │ │ │ │ + * set, auto-configured properties will stick on subsequent reads. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} The input object, modified (or a new one if none was provided). │ │ │ │ │ + */ │ │ │ │ │ + readNode: function(node, obj, first) { │ │ │ │ │ + // Not the superclass, only the mixin classes inherit from │ │ │ │ │ + // Format.GML.v3. We need this because we don't want to get readNode │ │ │ │ │ + // from the superclass's superclass, which is OpenLayers.Format.XML. │ │ │ │ │ + return OpenLayers.Format.GML.v3.prototype.readNode.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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: { │ │ │ │ │ + "wfs": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "FeatureCollection": function(node, obj) { │ │ │ │ │ + obj.numberOfFeatures = parseInt(node.getAttribute( │ │ │ │ │ + "numberOfFeatures")); │ │ │ │ │ + OpenLayers.Format.WFST.v1.prototype.readers["wfs"]["FeatureCollection"].apply( │ │ │ │ │ + this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + "TransactionResponse": function(node, obj) { │ │ │ │ │ + obj.insertIds = []; │ │ │ │ │ + obj.success = false; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "TransactionSummary": function(node, obj) { │ │ │ │ │ + // this is a limited test of success │ │ │ │ │ + obj.success = true; │ │ │ │ │ + }, │ │ │ │ │ + "InsertResults": function(node, obj) { │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + }, │ │ │ │ │ + "Feature": function(node, container) { │ │ │ │ │ + var obj = { │ │ │ │ │ + fids: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.insertIds.push(obj.fids[0]); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"], │ │ │ │ │ + "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"], │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ + */ │ │ │ │ │ + writers: { │ │ │ │ │ + "wfs": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "GetFeature": function(options) { │ │ │ │ │ + var node = OpenLayers.Format.WFST.v1.prototype.writers["wfs"]["GetFeature"].apply(this, arguments); │ │ │ │ │ + options && this.setAttributes(node, { │ │ │ │ │ + resultType: options.resultType, │ │ │ │ │ + startIndex: options.startIndex, │ │ │ │ │ + count: options.count │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Query": function(options) { │ │ │ │ │ + options = OpenLayers.Util.extend({ │ │ │ │ │ + featureNS: this.featureNS, │ │ │ │ │ + featurePrefix: this.featurePrefix, │ │ │ │ │ + featureType: this.featureType, │ │ │ │ │ + srsName: this.srsName │ │ │ │ │ + }, options); │ │ │ │ │ + var prefix = options.featurePrefix; │ │ │ │ │ + var node = this.createElementNSPlus("wfs:Query", { │ │ │ │ │ + attributes: { │ │ │ │ │ + typeName: (prefix ? prefix + ":" : "") + │ │ │ │ │ + options.featureType, │ │ │ │ │ + srsName: options.srsName │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (options.featureNS) { │ │ │ │ │ + node.setAttribute("xmlns:" + prefix, options.featureNS); │ │ │ │ │ + } │ │ │ │ │ + if (options.propertyNames) { │ │ │ │ │ + for (var i = 0, len = options.propertyNames.length; i < len; i++) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "wfs:PropertyName", { │ │ │ │ │ + property: options.propertyNames[i] │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (options.filter) { │ │ │ │ │ + OpenLayers.Format.WFST.v1_1_0.prototype.setFilterProperty.call(this, options.filter); │ │ │ │ │ + this.writeNode("ogc:Filter", options.filter, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyName": function(obj) { │ │ │ │ │ + return this.createElementNSPlus("wfs:PropertyName", { │ │ │ │ │ + value: obj.property │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"], │ │ │ │ │ + "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/WPSExecute.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 │ │ │ │ │ + * @requires OpenLayers/Format/WCSGetCoverage.js │ │ │ │ │ + * @requires OpenLayers/Format/WFST/v1_1_0.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.WPSExecute version 1.0.0 │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.TileManager = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, │ │ │ │ │ + OpenLayers.Format.Filter.v1_1_0, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: cacheSize │ │ │ │ │ - * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ - * cache for fast reuse. Default is 256. │ │ │ │ │ - */ │ │ │ │ │ - cacheSize: 256, │ │ │ │ │ + /** │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ + gml: "http://www.opengis.net/gml", │ │ │ │ │ + wps: "http://www.opengis.net/wps/1.0.0", │ │ │ │ │ + wfs: "http://www.opengis.net/wfs", │ │ │ │ │ + ogc: "http://www.opengis.net/ogc", │ │ │ │ │ + wcs: "http://www.opengis.net/wcs", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tilesPerFrame │ │ │ │ │ - * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ - * Default is 2. │ │ │ │ │ - */ │ │ │ │ │ - tilesPerFrame: 2, │ │ │ │ │ + /** │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ + */ │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: frameDelay │ │ │ │ │ - * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ - * milliseconds. Default is 16. │ │ │ │ │ - */ │ │ │ │ │ - frameDelay: 16, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: moveDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ - * tiles. Default is 100. │ │ │ │ │ - */ │ │ │ │ │ - moveDelay: 100, │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ - * tiles. Default is 200. │ │ │ │ │ - */ │ │ │ │ │ - zoomDelay: 200, │ │ │ │ │ + schemaLocationAttr: function(options) { │ │ │ │ │ + return undefined; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: maps │ │ │ │ │ - * {Array()} The maps to manage tiles on. │ │ │ │ │ - */ │ │ │ │ │ - maps: null, │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WPSExecute │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueueId │ │ │ │ │ - * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueueId: null, │ │ │ │ │ + /** │ │ │ │ │ + * Method: write │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An WPS Execute request XML string. │ │ │ │ │ + */ │ │ │ │ │ + write: function(options) { │ │ │ │ │ + var doc; │ │ │ │ │ + if (window.ActiveXObject) { │ │ │ │ │ + doc = new ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ + this.xmldom = doc; │ │ │ │ │ + } else { │ │ │ │ │ + doc = document.implementation.createDocument("", "", null); │ │ │ │ │ + } │ │ │ │ │ + var node = this.writeNode("wps:Execute", options, doc); │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + node, this.namespaces.xsi, │ │ │ │ │ + "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ + ); │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [node]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueue │ │ │ │ │ - * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ - * map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueue: null, │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Parse a WPS Execute 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: tileCache │ │ │ │ │ - * {Object} Cached image elements, keyed by URL. │ │ │ │ │ - */ │ │ │ │ │ - tileCache: null, │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ + */ │ │ │ │ │ + writers: { │ │ │ │ │ + "wps": { │ │ │ │ │ + "Execute": function(options) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Execute", { │ │ │ │ │ + attributes: { │ │ │ │ │ + version: this.VERSION, │ │ │ │ │ + service: 'WPS' │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("ows:Identifier", options.identifier, node); │ │ │ │ │ + this.writeNode("wps:DataInputs", options.dataInputs, node); │ │ │ │ │ + this.writeNode("wps:ResponseForm", options.responseForm, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ResponseForm": function(responseForm) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:ResponseForm", {}); │ │ │ │ │ + if (responseForm.rawDataOutput) { │ │ │ │ │ + this.writeNode("wps:RawDataOutput", responseForm.rawDataOutput, node); │ │ │ │ │ + } │ │ │ │ │ + if (responseForm.responseDocument) { │ │ │ │ │ + this.writeNode("wps:ResponseDocument", responseForm.responseDocument, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ResponseDocument": function(responseDocument) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:ResponseDocument", { │ │ │ │ │ + attributes: { │ │ │ │ │ + storeExecuteResponse: responseDocument.storeExecuteResponse, │ │ │ │ │ + lineage: responseDocument.lineage, │ │ │ │ │ + status: responseDocument.status │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (responseDocument.outputs) { │ │ │ │ │ + for (var i = 0, len = responseDocument.outputs.length; i < len; i++) { │ │ │ │ │ + this.writeNode("wps:Output", responseDocument.outputs[i], node); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Output": function(output) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Output", { │ │ │ │ │ + attributes: { │ │ │ │ │ + asReference: output.asReference, │ │ │ │ │ + mimeType: output.mimeType, │ │ │ │ │ + encoding: output.encoding, │ │ │ │ │ + schema: output.schema │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("ows:Identifier", output.identifier, node); │ │ │ │ │ + this.writeNode("ows:Title", output.title, node); │ │ │ │ │ + this.writeNode("ows:Abstract", output["abstract"], node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "RawDataOutput": function(rawDataOutput) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:RawDataOutput", { │ │ │ │ │ + attributes: { │ │ │ │ │ + mimeType: rawDataOutput.mimeType, │ │ │ │ │ + encoding: rawDataOutput.encoding, │ │ │ │ │ + schema: rawDataOutput.schema │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.writeNode("ows:Identifier", rawDataOutput.identifier, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "DataInputs": function(dataInputs) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:DataInputs", {}); │ │ │ │ │ + for (var i = 0, ii = dataInputs.length; i < ii; ++i) { │ │ │ │ │ + this.writeNode("wps:Input", dataInputs[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Input": function(input) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Input", {}); │ │ │ │ │ + this.writeNode("ows:Identifier", input.identifier, node); │ │ │ │ │ + if (input.title) { │ │ │ │ │ + this.writeNode("ows:Title", input.title, node); │ │ │ │ │ + } │ │ │ │ │ + if (input.data) { │ │ │ │ │ + this.writeNode("wps:Data", input.data, node); │ │ │ │ │ + } │ │ │ │ │ + if (input.reference) { │ │ │ │ │ + this.writeNode("wps:Reference", input.reference, node); │ │ │ │ │ + } │ │ │ │ │ + if (input.boundingBoxData) { │ │ │ │ │ + this.writeNode("wps:BoundingBoxData", input.boundingBoxData, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Data": function(data) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Data", {}); │ │ │ │ │ + if (data.literalData) { │ │ │ │ │ + this.writeNode("wps:LiteralData", data.literalData, node); │ │ │ │ │ + } else if (data.complexData) { │ │ │ │ │ + this.writeNode("wps:ComplexData", data.complexData, node); │ │ │ │ │ + } else if (data.boundingBoxData) { │ │ │ │ │ + this.writeNode("ows:BoundingBox", data.boundingBoxData, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LiteralData": function(literalData) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:LiteralData", { │ │ │ │ │ + attributes: { │ │ │ │ │ + uom: literalData.uom │ │ │ │ │ + }, │ │ │ │ │ + value: literalData.value │ │ │ │ │ + }); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ComplexData": function(complexData) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:ComplexData", { │ │ │ │ │ + attributes: { │ │ │ │ │ + mimeType: complexData.mimeType, │ │ │ │ │ + encoding: complexData.encoding, │ │ │ │ │ + schema: complexData.schema │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + var data = complexData.value; │ │ │ │ │ + if (typeof data === "string") { │ │ │ │ │ + node.appendChild( │ │ │ │ │ + this.getXMLDoc().createCDATASection(complexData.value) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + node.appendChild(data); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Reference": function(reference) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Reference", { │ │ │ │ │ + attributes: { │ │ │ │ │ + mimeType: reference.mimeType, │ │ │ │ │ + "xlink:href": reference.href, │ │ │ │ │ + method: reference.method, │ │ │ │ │ + encoding: reference.encoding, │ │ │ │ │ + schema: reference.schema │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + if (reference.body) { │ │ │ │ │ + this.writeNode("wps:Body", reference.body, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "BoundingBoxData": function(node, obj) { │ │ │ │ │ + this.writers['ows']['BoundingBox'].apply(this, [node, obj, "wps:BoundingBoxData"]); │ │ │ │ │ + }, │ │ │ │ │ + "Body": function(body) { │ │ │ │ │ + var node = this.createElementNSPlus("wps:Body", {}); │ │ │ │ │ + if (body.wcs) { │ │ │ │ │ + this.writeNode("wcs:GetCoverage", body.wcs, node); │ │ │ │ │ + } else if (body.wfs) { │ │ │ │ │ + // OpenLayers.Format.WFST expects these to be on the │ │ │ │ │ + // instance and not in the options │ │ │ │ │ + this.featureType = body.wfs.featureType; │ │ │ │ │ + this.version = body.wfs.version; │ │ │ │ │ + this.writeNode("wfs:GetFeature", body.wfs, node); │ │ │ │ │ + } else { │ │ │ │ │ + this.writeNode("wps:Execute", body, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "wcs": OpenLayers.Format.WCSGetCoverage.prototype.writers.wcs, │ │ │ │ │ + "wfs": OpenLayers.Format.WFST.v1_1_0.prototype.writers.wfs, │ │ │ │ │ + "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers.ogc, │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileCacheIndex │ │ │ │ │ - * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ - * used. │ │ │ │ │ - */ │ │ │ │ │ - tileCacheIndex: null, │ │ │ │ │ + /** │ │ │ │ │ + * 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": { │ │ │ │ │ + "ExecuteResponse": function(node, obj) { │ │ │ │ │ + obj.executeResponse = { │ │ │ │ │ + lang: node.getAttribute("lang"), │ │ │ │ │ + statusLocation: node.getAttribute("statusLocation"), │ │ │ │ │ + serviceInstance: node.getAttribute("serviceInstance"), │ │ │ │ │ + service: node.getAttribute("service") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj.executeResponse); │ │ │ │ │ + }, │ │ │ │ │ + "Process": function(node, obj) { │ │ │ │ │ + obj.process = {}; │ │ │ │ │ + this.readChildNodes(node, obj.process); │ │ │ │ │ + }, │ │ │ │ │ + "Status": function(node, obj) { │ │ │ │ │ + obj.status = { │ │ │ │ │ + creationTime: node.getAttribute("creationTime") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj.status); │ │ │ │ │ + }, │ │ │ │ │ + "ProcessSucceeded": function(node, obj) { │ │ │ │ │ + obj.processSucceeded = true; │ │ │ │ │ + }, │ │ │ │ │ + "ProcessOutputs": function(node, processDescription) { │ │ │ │ │ + processDescription.processOutputs = []; │ │ │ │ │ + this.readChildNodes(node, processDescription.processOutputs); │ │ │ │ │ + }, │ │ │ │ │ + "Output": function(node, processOutputs) { │ │ │ │ │ + var output = {}; │ │ │ │ │ + this.readChildNodes(node, output); │ │ │ │ │ + processOutputs.push(output); │ │ │ │ │ + }, │ │ │ │ │ + "Reference": function(node, output) { │ │ │ │ │ + output.reference = { │ │ │ │ │ + href: node.getAttribute("href"), │ │ │ │ │ + mimeType: node.getAttribute("mimeType"), │ │ │ │ │ + encoding: node.getAttribute("encoding"), │ │ │ │ │ + schema: node.getAttribute("schema") │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + "Data": function(node, output) { │ │ │ │ │ + output.data = {}; │ │ │ │ │ + this.readChildNodes(node, output); │ │ │ │ │ + }, │ │ │ │ │ + "LiteralData": function(node, output) { │ │ │ │ │ + output.literalData = { │ │ │ │ │ + dataType: node.getAttribute("dataType"), │ │ │ │ │ + uom: node.getAttribute("uom"), │ │ │ │ │ + value: this.getChildValue(node) │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + "ComplexData": function(node, output) { │ │ │ │ │ + output.complexData = { │ │ │ │ │ + mimeType: node.getAttribute("mimeType"), │ │ │ │ │ + schema: node.getAttribute("schema"), │ │ │ │ │ + encoding: node.getAttribute("encoding"), │ │ │ │ │ + value: "" │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 = []; │ │ │ │ │ - }, │ │ │ │ │ + // try to get *some* value, ignore the empty text values │ │ │ │ │ + if (this.isSimpleContent(node)) { │ │ │ │ │ + var child; │ │ │ │ │ + for (child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + switch (child.nodeType) { │ │ │ │ │ + case 3: // text node │ │ │ │ │ + case 4: // cdata section │ │ │ │ │ + output.complexData.value += child.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + for (child = node.firstChild; child; child = child.nextSibling) { │ │ │ │ │ + if (child.nodeType == 1) { │ │ │ │ │ + output.complexData.value = child; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addMap │ │ │ │ │ - * Binds this instance to a map │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - 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] │ │ │ │ │ - }); │ │ │ │ │ + }, │ │ │ │ │ + "BoundingBox": function(node, output) { │ │ │ │ │ + output.boundingBoxData = { │ │ │ │ │ + dimensions: node.getAttribute("dimensions"), │ │ │ │ │ + crs: node.getAttribute("crs") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, output.boundingBoxData); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + // TODO: we should add Exception parsing here │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WPSExecute" │ │ │ │ │ + │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Request/XMLHttpRequest.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +// XMLHttpRequest.js Copyright (C) 2010 Sergey Ilinsky (http://www.ilinsky.com) │ │ │ │ │ +// │ │ │ │ │ +// Licensed under the Apache License, Version 2.0 (the "License"); │ │ │ │ │ +// you may not use this file except in compliance with the License. │ │ │ │ │ +// You may obtain a copy of the License at │ │ │ │ │ +// │ │ │ │ │ +// http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ │ +// │ │ │ │ │ +// Unless required by applicable law or agreed to in writing, software │ │ │ │ │ +// distributed under the License is distributed on an "AS IS" BASIS, │ │ │ │ │ +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ │ │ │ +// See the License for the specific language governing permissions and │ │ │ │ │ +// limitations under the License. │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +(function() { │ │ │ │ │ + │ │ │ │ │ + // Save reference to earlier defined object implementation (if any) │ │ │ │ │ + var oXMLHttpRequest = window.XMLHttpRequest; │ │ │ │ │ + │ │ │ │ │ + // Define on browser type │ │ │ │ │ + var bGecko = !!window.controllers, │ │ │ │ │ + bIE = window.document.all && !window.opera, │ │ │ │ │ + bIE7 = bIE && window.navigator.userAgent.match(/MSIE 7.0/); │ │ │ │ │ + │ │ │ │ │ + // Enables "XMLHttpRequest()" call next to "new XMLHttpReques()" │ │ │ │ │ + function fXMLHttpRequest() { │ │ │ │ │ + this._object = oXMLHttpRequest && !bIE7 ? new oXMLHttpRequest : new window.ActiveXObject("Microsoft.XMLHTTP"); │ │ │ │ │ + this._listeners = []; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Constructor │ │ │ │ │ + function cXMLHttpRequest() { │ │ │ │ │ + return new fXMLHttpRequest; │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype = fXMLHttpRequest.prototype; │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Firefox with Firebug installed would break pages if not executed │ │ │ │ │ + if (bGecko && oXMLHttpRequest.wrapped) │ │ │ │ │ + cXMLHttpRequest.wrapped = oXMLHttpRequest.wrapped; │ │ │ │ │ + │ │ │ │ │ + // Constants │ │ │ │ │ + cXMLHttpRequest.UNSENT = 0; │ │ │ │ │ + cXMLHttpRequest.OPENED = 1; │ │ │ │ │ + cXMLHttpRequest.HEADERS_RECEIVED = 2; │ │ │ │ │ + cXMLHttpRequest.LOADING = 3; │ │ │ │ │ + cXMLHttpRequest.DONE = 4; │ │ │ │ │ + │ │ │ │ │ + // Public Properties │ │ │ │ │ + cXMLHttpRequest.prototype.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + cXMLHttpRequest.prototype.responseText = ''; │ │ │ │ │ + cXMLHttpRequest.prototype.responseXML = null; │ │ │ │ │ + cXMLHttpRequest.prototype.status = 0; │ │ │ │ │ + cXMLHttpRequest.prototype.statusText = ''; │ │ │ │ │ + │ │ │ │ │ + // Priority proposal │ │ │ │ │ + cXMLHttpRequest.prototype.priority = "NORMAL"; │ │ │ │ │ + │ │ │ │ │ + // Instance-level Events Handlers │ │ │ │ │ + cXMLHttpRequest.prototype.onreadystatechange = null; │ │ │ │ │ + │ │ │ │ │ + // Class-level Events Handlers │ │ │ │ │ + cXMLHttpRequest.onreadystatechange = null; │ │ │ │ │ + cXMLHttpRequest.onopen = null; │ │ │ │ │ + cXMLHttpRequest.onsend = null; │ │ │ │ │ + cXMLHttpRequest.onabort = null; │ │ │ │ │ + │ │ │ │ │ + // Public Methods │ │ │ │ │ + cXMLHttpRequest.prototype.open = function(sMethod, sUrl, bAsync, sUser, sPassword) { │ │ │ │ │ + // Delete headers, required when object is reused │ │ │ │ │ + delete this._headers; │ │ │ │ │ + │ │ │ │ │ + // When bAsync parameter value is omitted, use true as default │ │ │ │ │ + if (arguments.length < 3) │ │ │ │ │ + bAsync = true; │ │ │ │ │ + │ │ │ │ │ + // Save async parameter for fixing Gecko bug with missing readystatechange in synchronous requests │ │ │ │ │ + this._async = bAsync; │ │ │ │ │ + │ │ │ │ │ + // Set the onreadystatechange handler │ │ │ │ │ + var oRequest = this, │ │ │ │ │ + nState = this.readyState, │ │ │ │ │ + fOnUnload; │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: IE - memory leak on page unload (inter-page leak) │ │ │ │ │ + if (bIE && bAsync) { │ │ │ │ │ + fOnUnload = function() { │ │ │ │ │ + if (nState != cXMLHttpRequest.DONE) { │ │ │ │ │ + fCleanTransport(oRequest); │ │ │ │ │ + // Safe to abort here since onreadystatechange handler removed │ │ │ │ │ + oRequest.abort(); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + window.attachEvent("onunload", fOnUnload); │ │ │ │ │ } │ │ │ │ │ - map.events.on({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * Unbinds this instance from a map │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ - return; │ │ │ │ │ + // Add method sniffer │ │ │ │ │ + if (cXMLHttpRequest.onopen) │ │ │ │ │ + cXMLHttpRequest.onopen.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + if (arguments.length > 4) │ │ │ │ │ + this._object.open(sMethod, sUrl, bAsync, sUser, sPassword); │ │ │ │ │ + else │ │ │ │ │ + if (arguments.length > 3) │ │ │ │ │ + this._object.open(sMethod, sUrl, bAsync, sUser); │ │ │ │ │ + else │ │ │ │ │ + this._object.open(sMethod, sUrl, bAsync); │ │ │ │ │ + │ │ │ │ │ + this.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ + fReadyStateChange(this); │ │ │ │ │ + │ │ │ │ │ + this._object.onreadystatechange = function() { │ │ │ │ │ + if (bGecko && !bAsync) │ │ │ │ │ + return; │ │ │ │ │ + │ │ │ │ │ + // Synchronize state │ │ │ │ │ + oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + fSynchronizeValues(oRequest); │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Firefox fires unnecessary DONE when aborting │ │ │ │ │ + if (oRequest._aborted) { │ │ │ │ │ + // Reset readyState to UNSENT │ │ │ │ │ + oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + │ │ │ │ │ + // Return now │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (oRequest.readyState == cXMLHttpRequest.DONE) { │ │ │ │ │ + // Free up queue │ │ │ │ │ + delete oRequest._data; │ │ │ │ │ + /* if (bAsync) │ │ │ │ │ + fQueue_remove(oRequest);*/ │ │ │ │ │ + // │ │ │ │ │ + fCleanTransport(oRequest); │ │ │ │ │ + // Uncomment this block if you need a fix for IE cache │ │ │ │ │ + /* │ │ │ │ │ + // BUGFIX: IE - cache issue │ │ │ │ │ + if (!oRequest._object.getResponseHeader("Date")) { │ │ │ │ │ + // Save object to cache │ │ │ │ │ + oRequest._cached = oRequest._object; │ │ │ │ │ + │ │ │ │ │ + // Instantiate a new transport object │ │ │ │ │ + cXMLHttpRequest.call(oRequest); │ │ │ │ │ + │ │ │ │ │ + // Re-send request │ │ │ │ │ + if (sUser) { │ │ │ │ │ + if (sPassword) │ │ │ │ │ + oRequest._object.open(sMethod, sUrl, bAsync, sUser, sPassword); │ │ │ │ │ + else │ │ │ │ │ + oRequest._object.open(sMethod, sUrl, bAsync, sUser); │ │ │ │ │ + } │ │ │ │ │ + else │ │ │ │ │ + oRequest._object.open(sMethod, sUrl, bAsync); │ │ │ │ │ + oRequest._object.setRequestHeader("If-Modified-Since", oRequest._cached.getResponseHeader("Last-Modified") || new window.Date(0)); │ │ │ │ │ + // Copy headers set │ │ │ │ │ + if (oRequest._headers) │ │ │ │ │ + for (var sHeader in oRequest._headers) │ │ │ │ │ + if (typeof oRequest._headers[sHeader] == "string") // Some frameworks prototype objects with functions │ │ │ │ │ + oRequest._object.setRequestHeader(sHeader, oRequest._headers[sHeader]); │ │ │ │ │ + │ │ │ │ │ + oRequest._object.onreadystatechange = function() { │ │ │ │ │ + // Synchronize state │ │ │ │ │ + oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ + │ │ │ │ │ + if (oRequest._aborted) { │ │ │ │ │ + // │ │ │ │ │ + oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + │ │ │ │ │ + // Return │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (oRequest.readyState == cXMLHttpRequest.DONE) { │ │ │ │ │ + // Clean Object │ │ │ │ │ + fCleanTransport(oRequest); │ │ │ │ │ + │ │ │ │ │ + // get cached request │ │ │ │ │ + if (oRequest.status == 304) │ │ │ │ │ + oRequest._object = oRequest._cached; │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + delete oRequest._cached; │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + fSynchronizeValues(oRequest); │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + fReadyStateChange(oRequest); │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ + if (bIE && bAsync) │ │ │ │ │ + window.detachEvent("onunload", fOnUnload); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + oRequest._object.send(null); │ │ │ │ │ + │ │ │ │ │ + // Return now - wait until re-sent request is finished │ │ │ │ │ + return; │ │ │ │ │ + }; │ │ │ │ │ + */ │ │ │ │ │ + // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ + if (bIE && bAsync) │ │ │ │ │ + window.detachEvent("onunload", fOnUnload); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Some browsers (Internet Explorer, Gecko) fire OPEN readystate twice │ │ │ │ │ + if (nState != oRequest.readyState) │ │ │ │ │ + fReadyStateChange(oRequest); │ │ │ │ │ + │ │ │ │ │ + nState = oRequest.readyState; │ │ │ │ │ } │ │ │ │ │ - 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] │ │ │ │ │ - }); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fXMLHttpRequest_send(oRequest) { │ │ │ │ │ + oRequest._object.send(oRequest._data); │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Gecko - missing readystatechange calls in synchronous requests │ │ │ │ │ + if (bGecko && !oRequest._async) { │ │ │ │ │ + oRequest.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ + │ │ │ │ │ + // Synchronize state │ │ │ │ │ + fSynchronizeValues(oRequest); │ │ │ │ │ + │ │ │ │ │ + // Simulate missing states │ │ │ │ │ + while (oRequest.readyState < cXMLHttpRequest.DONE) { │ │ │ │ │ + oRequest.readyState++; │ │ │ │ │ + fReadyStateChange(oRequest); │ │ │ │ │ + // Check if we are aborted │ │ │ │ │ + if (oRequest._aborted) │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (map.events) { │ │ │ │ │ - map.events.un({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype.send = function(vData) { │ │ │ │ │ + // Add method sniffer │ │ │ │ │ + if (cXMLHttpRequest.onsend) │ │ │ │ │ + cXMLHttpRequest.onsend.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + if (!arguments.length) │ │ │ │ │ + vData = null; │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Safari - fails sending documents created/modified dynamically, so an explicit serialization required │ │ │ │ │ + // BUGFIX: IE - rewrites any custom mime-type to "text/xml" in case an XMLNode is sent │ │ │ │ │ + // BUGFIX: Gecko - fails sending Element (this is up to the implementation either to standard) │ │ │ │ │ + if (vData && vData.nodeType) { │ │ │ │ │ + vData = window.XMLSerializer ? new window.XMLSerializer().serializeToString(vData) : vData.xml; │ │ │ │ │ + if (!this._headers["Content-Type"]) │ │ │ │ │ + this._object.setRequestHeader("Content-Type", "application/xml"); │ │ │ │ │ } │ │ │ │ │ - delete this.tileQueue[map.id]; │ │ │ │ │ - delete this.tileQueueId[map.id]; │ │ │ │ │ - OpenLayers.Util.removeItem(this.maps, map); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + this._data = vData; │ │ │ │ │ + /* │ │ │ │ │ + // Add to queue │ │ │ │ │ + if (this._async) │ │ │ │ │ + fQueue_add(this); │ │ │ │ │ + else*/ │ │ │ │ │ + fXMLHttpRequest_send(this); │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype.abort = function() { │ │ │ │ │ + // Add method sniffer │ │ │ │ │ + if (cXMLHttpRequest.onabort) │ │ │ │ │ + cXMLHttpRequest.onabort.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: Gecko - unnecessary DONE when aborting │ │ │ │ │ + if (this.readyState > cXMLHttpRequest.UNSENT) │ │ │ │ │ + this._aborted = true; │ │ │ │ │ + │ │ │ │ │ + this._object.abort(); │ │ │ │ │ + │ │ │ │ │ + // BUGFIX: IE - memory leak │ │ │ │ │ + fCleanTransport(this); │ │ │ │ │ + │ │ │ │ │ + this.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + │ │ │ │ │ + delete this._data; │ │ │ │ │ + /* if (this._async) │ │ │ │ │ + fQueue_remove(this);*/ │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype.getAllResponseHeaders = function() { │ │ │ │ │ + return this._object.getAllResponseHeaders(); │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype.getResponseHeader = function(sName) { │ │ │ │ │ + return this._object.getResponseHeader(sName); │ │ │ │ │ + }; │ │ │ │ │ + cXMLHttpRequest.prototype.setRequestHeader = function(sName, sValue) { │ │ │ │ │ + // BUGFIX: IE - cache issue │ │ │ │ │ + if (!this._headers) │ │ │ │ │ + this._headers = {}; │ │ │ │ │ + this._headers[sName] = sValue; │ │ │ │ │ + │ │ │ │ │ + return this._object.setRequestHeader(sName, sValue); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // EventTarget interface implementation │ │ │ │ │ + cXMLHttpRequest.prototype.addEventListener = function(sName, fHandler, bUseCapture) { │ │ │ │ │ + for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ + if (oListener[0] == sName && oListener[1] == fHandler && oListener[2] == bUseCapture) │ │ │ │ │ + return; │ │ │ │ │ + // Add listener │ │ │ │ │ + this._listeners.push([sName, fHandler, bUseCapture]); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + cXMLHttpRequest.prototype.removeEventListener = function(sName, fHandler, bUseCapture) { │ │ │ │ │ + for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ + if (oListener[0] == sName && oListener[1] == fHandler && oListener[2] == bUseCapture) │ │ │ │ │ + break; │ │ │ │ │ + // Remove listener │ │ │ │ │ + if (oListener) │ │ │ │ │ + this._listeners.splice(nIndex, 1); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + cXMLHttpRequest.prototype.dispatchEvent = function(oEvent) { │ │ │ │ │ + var oEventPseudo = { │ │ │ │ │ + 'type': oEvent.type, │ │ │ │ │ + 'target': this, │ │ │ │ │ + 'currentTarget': this, │ │ │ │ │ + 'eventPhase': 2, │ │ │ │ │ + 'bubbles': oEvent.bubbles, │ │ │ │ │ + 'cancelable': oEvent.cancelable, │ │ │ │ │ + 'timeStamp': oEvent.timeStamp, │ │ │ │ │ + 'stopPropagation': function() {}, // There is no flow │ │ │ │ │ + 'preventDefault': function() {}, // There is no default action │ │ │ │ │ + 'initEvent': function() {} // Original event object should be initialized │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Execute onreadystatechange │ │ │ │ │ + if (oEventPseudo.type == "readystatechange" && this.onreadystatechange) │ │ │ │ │ + (this.onreadystatechange.handleEvent || this.onreadystatechange).apply(this, [oEventPseudo]); │ │ │ │ │ + │ │ │ │ │ + // Execute listeners │ │ │ │ │ + for (var nIndex = 0, oListener; oListener = this._listeners[nIndex]; nIndex++) │ │ │ │ │ + if (oListener[0] == oEventPseudo.type && !oListener[2]) │ │ │ │ │ + (oListener[1].handleEvent || oListener[1]).apply(this, [oEventPseudo]); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + cXMLHttpRequest.prototype.toString = function() { │ │ │ │ │ + return '[' + "object" + ' ' + "XMLHttpRequest" + ']'; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + cXMLHttpRequest.toString = function() { │ │ │ │ │ + return '[' + "XMLHttpRequest" + ']'; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Helper function │ │ │ │ │ + function fReadyStateChange(oRequest) { │ │ │ │ │ + // Sniffing code │ │ │ │ │ + if (cXMLHttpRequest.onreadystatechange) │ │ │ │ │ + cXMLHttpRequest.onreadystatechange.apply(oRequest); │ │ │ │ │ + │ │ │ │ │ + // Fake event │ │ │ │ │ + oRequest.dispatchEvent({ │ │ │ │ │ + 'type': "readystatechange", │ │ │ │ │ + 'bubbles': false, │ │ │ │ │ + 'cancelable': false, │ │ │ │ │ + 'timeStamp': new Date + 0 │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fGetDocument(oRequest) { │ │ │ │ │ + var oDocument = oRequest.responseXML, │ │ │ │ │ + sResponse = oRequest.responseText; │ │ │ │ │ + // Try parsing responseText │ │ │ │ │ + if (bIE && sResponse && oDocument && !oDocument.documentElement && oRequest.getResponseHeader("Content-Type").match(/[^\/]+\/[^\+]+\+xml/)) { │ │ │ │ │ + oDocument = new window.ActiveXObject("Microsoft.XMLDOM"); │ │ │ │ │ + oDocument.async = false; │ │ │ │ │ + oDocument.validateOnParse = false; │ │ │ │ │ + oDocument.loadXML(sResponse); │ │ │ │ │ + } │ │ │ │ │ + // Check if there is no error in document │ │ │ │ │ + if (oDocument) │ │ │ │ │ + if ((bIE && oDocument.parseError != 0) || !oDocument.documentElement || (oDocument.documentElement && oDocument.documentElement.tagName == "parsererror")) │ │ │ │ │ + return null; │ │ │ │ │ + return oDocument; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fSynchronizeValues(oRequest) { │ │ │ │ │ + try { │ │ │ │ │ + oRequest.responseText = oRequest._object.responseText; │ │ │ │ │ + } catch (e) {} │ │ │ │ │ + try { │ │ │ │ │ + oRequest.responseXML = fGetDocument(oRequest._object); │ │ │ │ │ + } catch (e) {} │ │ │ │ │ + try { │ │ │ │ │ + oRequest.status = oRequest._object.status; │ │ │ │ │ + } catch (e) {} │ │ │ │ │ + try { │ │ │ │ │ + oRequest.statusText = oRequest._object.statusText; │ │ │ │ │ + } catch (e) {} │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fCleanTransport(oRequest) { │ │ │ │ │ + // BUGFIX: IE - memory leak (on-page leak) │ │ │ │ │ + oRequest._object.onreadystatechange = new window.Function; │ │ │ │ │ + }; │ │ │ │ │ + /* │ │ │ │ │ + // Queue manager │ │ │ │ │ + var oQueuePending = {"CRITICAL":[],"HIGH":[],"NORMAL":[],"LOW":[],"LOWEST":[]}, │ │ │ │ │ + aQueueRunning = []; │ │ │ │ │ + function fQueue_add(oRequest) { │ │ │ │ │ + oQueuePending[oRequest.priority in oQueuePending ? oRequest.priority : "NORMAL"].push(oRequest); │ │ │ │ │ + // │ │ │ │ │ + setTimeout(fQueue_process); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fQueue_remove(oRequest) { │ │ │ │ │ + for (var nIndex = 0, bFound = false; nIndex < aQueueRunning.length; nIndex++) │ │ │ │ │ + if (bFound) │ │ │ │ │ + aQueueRunning[nIndex - 1] = aQueueRunning[nIndex]; │ │ │ │ │ + else │ │ │ │ │ + if (aQueueRunning[nIndex] == oRequest) │ │ │ │ │ + bFound = true; │ │ │ │ │ + if (bFound) │ │ │ │ │ + aQueueRunning.length--; │ │ │ │ │ + // │ │ │ │ │ + setTimeout(fQueue_process); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + function fQueue_process() { │ │ │ │ │ + if (aQueueRunning.length < 6) { │ │ │ │ │ + for (var sPriority in oQueuePending) { │ │ │ │ │ + if (oQueuePending[sPriority].length) { │ │ │ │ │ + var oRequest = oQueuePending[sPriority][0]; │ │ │ │ │ + oQueuePending[sPriority] = oQueuePending[sPriority].slice(1); │ │ │ │ │ + // │ │ │ │ │ + aQueueRunning.push(oRequest); │ │ │ │ │ + // Send request │ │ │ │ │ + fXMLHttpRequest_send(oRequest); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + */ │ │ │ │ │ + // Internet Explorer 5.0 (missing apply) │ │ │ │ │ + if (!window.Function.prototype.apply) { │ │ │ │ │ + window.Function.prototype.apply = function(oRequest, oArguments) { │ │ │ │ │ + if (!oArguments) │ │ │ │ │ + oArguments = []; │ │ │ │ │ + oRequest.__func = this; │ │ │ │ │ + oRequest.__func(oArguments[0], oArguments[1], oArguments[2], oArguments[3], oArguments[4]); │ │ │ │ │ + delete oRequest.__func; │ │ │ │ │ + }; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Register new object with window │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handles the map's move event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + * Class: OpenLayers.Request.XMLHttpRequest │ │ │ │ │ + * Standard-compliant (W3C) cross-browser implementation of the │ │ │ │ │ + * XMLHttpRequest object. From │ │ │ │ │ + * http://code.google.com/p/xmlhttprequest/. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ - }, │ │ │ │ │ + if (!OpenLayers.Request) { │ │ │ │ │ + /** │ │ │ │ │ + * This allows for OpenLayers/Request.js to be included │ │ │ │ │ + * before or after this script. │ │ │ │ │ + */ │ │ │ │ │ + OpenLayers.Request = {}; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Request.XMLHttpRequest = cXMLHttpRequest; │ │ │ │ │ +})(); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Request.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/Request/XMLHttpRequest.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * TODO: deprecate me │ │ │ │ │ + * Use OpenLayers.Request.proxy instead. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.ProxyHost = ""; │ │ │ │ │ │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Request │ │ │ │ │ + * The OpenLayers.Request namespace contains convenience methods for working │ │ │ │ │ + * with XMLHttpRequests. These methods work with a cross-browser │ │ │ │ │ + * W3C compliant class. │ │ │ │ │ + */ │ │ │ │ │ +if (!OpenLayers.Request) { │ │ │ │ │ /** │ │ │ │ │ - * Method: zoomEnd │ │ │ │ │ - * Handles the map's zoomEnd event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + * This allows for OpenLayers/Request/XMLHttpRequest.js to be included │ │ │ │ │ + * before or after this script. │ │ │ │ │ */ │ │ │ │ │ - zoomEnd: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ + OpenLayers.Request = {}; │ │ │ │ │ +} │ │ │ │ │ +OpenLayers.Util.extend(OpenLayers.Request, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: DEFAULT_CONFIG │ │ │ │ │ + * {Object} Default configuration for all requests. │ │ │ │ │ + */ │ │ │ │ │ + DEFAULT_CONFIG: { │ │ │ │ │ + method: "GET", │ │ │ │ │ + url: window.location.href, │ │ │ │ │ + async: true, │ │ │ │ │ + user: undefined, │ │ │ │ │ + password: undefined, │ │ │ │ │ + params: null, │ │ │ │ │ + proxy: OpenLayers.ProxyHost, │ │ │ │ │ + headers: {}, │ │ │ │ │ + data: null, │ │ │ │ │ + callback: function() {}, │ │ │ │ │ + success: null, │ │ │ │ │ + failure: null, │ │ │ │ │ + scope: null │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: changeLayer │ │ │ │ │ - * Handles the map's changeLayer event │ │ │ │ │ + * Constant: URL_SPLIT_REGEX │ │ │ │ │ + */ │ │ │ │ │ + URL_SPLIT_REGEX: /([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the {} object. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ + * All event listeners will receive an event object with three properties: │ │ │ │ │ + * request - {} The request object. │ │ │ │ │ + * config - {Object} The config object sent to the specific request method. │ │ │ │ │ + * requestUrl - {String} The request url. │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * complete - Triggered when we have a response from the request, if a │ │ │ │ │ + * listener returns false, no further response processing will take │ │ │ │ │ + * place. │ │ │ │ │ + * success - Triggered when the HTTP response has a success code (200-299). │ │ │ │ │ + * failure - Triggered when the HTTP response does not have a success code. │ │ │ │ │ */ │ │ │ │ │ - changeLayer: function(evt) { │ │ │ │ │ - if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ - this.updateTimeout(evt.object, 0); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + events: new OpenLayers.Events(this), │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Handles the map's addlayer event │ │ │ │ │ + * Method: makeSameOrigin │ │ │ │ │ + * Using the specified proxy, returns a same origin url of the provided url. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * url - {String} An arbitrary url │ │ │ │ │ + * proxy {String|Function} The proxy to use to make the provided url a │ │ │ │ │ + * same origin url. │ │ │ │ │ + * │ │ │ │ │ + * Returns │ │ │ │ │ + * {String} the same origin url. If no proxy is provided, the returned url │ │ │ │ │ + * will be the same as the provided url. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + makeSameOrigin: function(url, proxy) { │ │ │ │ │ + var sameOrigin = url.indexOf("http") !== 0; │ │ │ │ │ + var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX); │ │ │ │ │ + if (urlParts) { │ │ │ │ │ + var location = window.location; │ │ │ │ │ + sameOrigin = │ │ │ │ │ + urlParts[1] == location.protocol && │ │ │ │ │ + urlParts[3] == location.hostname; │ │ │ │ │ + var uPort = urlParts[4], │ │ │ │ │ + lPort = location.port; │ │ │ │ │ + if (uPort != 80 && uPort != "" || lPort != "80" && lPort != "") { │ │ │ │ │ + sameOrigin = sameOrigin && uPort == lPort; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!sameOrigin) { │ │ │ │ │ + if (proxy) { │ │ │ │ │ + if (typeof proxy == "function") { │ │ │ │ │ + url = proxy(url); │ │ │ │ │ + } else { │ │ │ │ │ + url = proxy + encodeURIComponent(url); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + return url; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Handles the map's preremovelayer event │ │ │ │ │ + * APIMethod: issue │ │ │ │ │ + * Create a new XMLHttpRequest object, open it, set any headers, bind │ │ │ │ │ + * a callback to done state, and send any data. It is recommended that │ │ │ │ │ + * you use one , , , , , or . │ │ │ │ │ + * This method is only documented to provide detail on the configuration │ │ │ │ │ + * options available to all request methods. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * config - {Object} Object containing properties for configuring the │ │ │ │ │ + * request. Allowed configuration properties are described below. │ │ │ │ │ + * This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Allowed config properties: │ │ │ │ │ + * method - {String} One of GET, POST, PUT, DELETE, HEAD, or │ │ │ │ │ + * OPTIONS. Default is GET. │ │ │ │ │ + * url - {String} URL for the request. │ │ │ │ │ + * async - {Boolean} Open an asynchronous request. Default is true. │ │ │ │ │ + * user - {String} User for relevant authentication scheme. Set │ │ │ │ │ + * to null to clear current user. │ │ │ │ │ + * password - {String} Password for relevant authentication scheme. │ │ │ │ │ + * Set to null to clear current password. │ │ │ │ │ + * proxy - {String} Optional proxy. Defaults to │ │ │ │ │ + * . │ │ │ │ │ + * params - {Object} Any key:value pairs to be appended to the │ │ │ │ │ + * url as a query string. Assumes url doesn't already include a query │ │ │ │ │ + * string or hash. Typically, this is only appropriate for │ │ │ │ │ + * requests where the query string will be appended to the url. │ │ │ │ │ + * Parameter values that are arrays will be │ │ │ │ │ + * concatenated with a comma (note that this goes against form-encoding) │ │ │ │ │ + * as is done with . │ │ │ │ │ + * headers - {Object} Object with header:value pairs to be set on │ │ │ │ │ + * the request. │ │ │ │ │ + * data - {String | Document} Optional data to send with the request. │ │ │ │ │ + * Typically, this is only used with and requests. │ │ │ │ │ + * Make sure to provide the appropriate "Content-Type" header for your │ │ │ │ │ + * data. For and requests, the content type defaults to │ │ │ │ │ + * "application-xml". If your data is a different content type, or │ │ │ │ │ + * if you are using a different HTTP method, set the "Content-Type" │ │ │ │ │ + * header to match your data type. │ │ │ │ │ + * callback - {Function} Function to call when request is done. │ │ │ │ │ + * To determine if the request failed, check request.status (200 │ │ │ │ │ + * indicates success). │ │ │ │ │ + * success - {Function} Optional function to call if request status is in │ │ │ │ │ + * the 200s. This will be called in addition to callback above and │ │ │ │ │ + * would typically only be used as an alternative. │ │ │ │ │ + * failure - {Function} Optional function to call if request status is not │ │ │ │ │ + * in the 200s. This will be called in addition to callback above and │ │ │ │ │ + * would typically only be used as an alternative. │ │ │ │ │ + * scope - {Object} If callback is a public method on some object, │ │ │ │ │ + * set the scope to that object. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. To abort the request before a response │ │ │ │ │ + * is received, call abort() on the request object. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + issue: function(config) { │ │ │ │ │ + // apply default config - proxy host may have changed │ │ │ │ │ + var defaultConfig = OpenLayers.Util.extend( │ │ │ │ │ + this.DEFAULT_CONFIG, { │ │ │ │ │ + proxy: OpenLayers.ProxyHost │ │ │ │ │ } │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + ); │ │ │ │ │ + config = config || {}; │ │ │ │ │ + config.headers = config.headers || {}; │ │ │ │ │ + config = OpenLayers.Util.applyDefaults(config, defaultConfig); │ │ │ │ │ + config.headers = OpenLayers.Util.applyDefaults(config.headers, defaultConfig.headers); │ │ │ │ │ + // Always set the "X-Requested-With" header to signal that this request │ │ │ │ │ + // was issued through the XHR-object. Since header keys are case │ │ │ │ │ + // insensitive and we want to allow overriding of the "X-Requested-With" │ │ │ │ │ + // header through the user we cannot use applyDefaults, but have to │ │ │ │ │ + // check manually whether we were called with a "X-Requested-With" │ │ │ │ │ + // header. │ │ │ │ │ + var customRequestedWithHeader = false, │ │ │ │ │ + headerKey; │ │ │ │ │ + for (headerKey in config.headers) { │ │ │ │ │ + if (config.headers.hasOwnProperty(headerKey)) { │ │ │ │ │ + if (headerKey.toLowerCase() === 'x-requested-with') { │ │ │ │ │ + customRequestedWithHeader = true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + if (customRequestedWithHeader === false) { │ │ │ │ │ + // we did not have a custom "X-Requested-With" header │ │ │ │ │ + config.headers['X-Requested-With'] = 'XMLHttpRequest'; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateTimeout │ │ │ │ │ - * Applies the or to the loop, │ │ │ │ │ - * and schedules more queue processing after if there are still │ │ │ │ │ - * tiles in the queue. │ │ │ │ │ - * │ │ │ │ │ - * 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); │ │ │ │ │ + // create request, open, and set headers │ │ │ │ │ + var request = new OpenLayers.Request.XMLHttpRequest(); │ │ │ │ │ + var url = OpenLayers.Util.urlAppend(config.url, │ │ │ │ │ + OpenLayers.Util.getParameterString(config.params || {})); │ │ │ │ │ + url = OpenLayers.Request.makeSameOrigin(url, config.proxy); │ │ │ │ │ + request.open( │ │ │ │ │ + config.method, url, config.async, config.user, config.password │ │ │ │ │ + ); │ │ │ │ │ + for (var header in config.headers) { │ │ │ │ │ + request.setRequestHeader(header, config.headers[header]); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var events = this.events; │ │ │ │ │ + │ │ │ │ │ + // we want to execute runCallbacks with "this" as the │ │ │ │ │ + // execution scope │ │ │ │ │ + var self = this; │ │ │ │ │ + │ │ │ │ │ + request.onreadystatechange = function() { │ │ │ │ │ + if (request.readyState == OpenLayers.Request.XMLHttpRequest.DONE) { │ │ │ │ │ + var proceed = events.triggerEvent( │ │ │ │ │ + "complete", { │ │ │ │ │ + request: request, │ │ │ │ │ + config: config, │ │ │ │ │ + requestUrl: url │ │ │ │ │ } │ │ │ │ │ - }, this), delay │ │ │ │ │ - ); │ │ │ │ │ + ); │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + self.runCallbacks({ │ │ │ │ │ + request: request, │ │ │ │ │ + config: config, │ │ │ │ │ + requestUrl: url │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // send request (optionally with data) and return │ │ │ │ │ + // call in a timeout for asynchronous requests so the return is │ │ │ │ │ + // available before readyState == 4 for cached docs │ │ │ │ │ + if (config.async === false) { │ │ │ │ │ + request.send(config.data); │ │ │ │ │ + } else { │ │ │ │ │ + window.setTimeout(function() { │ │ │ │ │ + if (request.readyState !== 0) { // W3C: 0-UNSENT │ │ │ │ │ + request.send(config.data); │ │ │ │ │ + } │ │ │ │ │ + }, 0); │ │ │ │ │ } │ │ │ │ │ + return request; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addTile │ │ │ │ │ - * Listener for the layer's addtile event │ │ │ │ │ + * Method: runCallbacks │ │ │ │ │ + * Calls the complete, success and failure callbacks. Application │ │ │ │ │ + * can listen to the "complete" event, have the listener │ │ │ │ │ + * display a confirm window and always return false, and │ │ │ │ │ + * execute OpenLayers.Request.runCallbacks if the user │ │ │ │ │ + * hits "yes" in the confirm window. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * options - {Object} Hash containing request, config and requestUrl keys │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + runCallbacks: function(options) { │ │ │ │ │ + var request = options.request; │ │ │ │ │ + var config = options.config; │ │ │ │ │ + │ │ │ │ │ + // bind callbacks to readyState 4 (done) │ │ │ │ │ + var complete = (config.scope) ? │ │ │ │ │ + OpenLayers.Function.bind(config.callback, config.scope) : │ │ │ │ │ + config.callback; │ │ │ │ │ + │ │ │ │ │ + // optional success callback │ │ │ │ │ + var success; │ │ │ │ │ + if (config.success) { │ │ │ │ │ + success = (config.scope) ? │ │ │ │ │ + OpenLayers.Function.bind(config.success, config.scope) : │ │ │ │ │ + config.success; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // optional failure callback │ │ │ │ │ + var failure; │ │ │ │ │ + if (config.failure) { │ │ │ │ │ + failure = (config.scope) ? │ │ │ │ │ + OpenLayers.Function.bind(config.failure, config.scope) : │ │ │ │ │ + config.failure; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (OpenLayers.Util.createUrlObject(config.url).protocol == "file:" && │ │ │ │ │ + request.responseText) { │ │ │ │ │ + request.status = 200; │ │ │ │ │ + } │ │ │ │ │ + complete(request); │ │ │ │ │ + │ │ │ │ │ + if (!request.status || (request.status >= 200 && request.status < 300)) { │ │ │ │ │ + this.events.triggerEvent("success", options); │ │ │ │ │ + if (success) { │ │ │ │ │ + success(request); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (request.status && (request.status < 200 || request.status >= 300)) { │ │ │ │ │ + this.events.triggerEvent("failure", options); │ │ │ │ │ + if (failure) { │ │ │ │ │ + failure(request); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unloadTile │ │ │ │ │ - * Listener for the tile's unload event │ │ │ │ │ + * APIMethod: GET │ │ │ │ │ + * Send an HTTP GET request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to GET. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. │ │ │ │ │ + * This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - unloadTile: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - beforedraw: this.queueTileDraw, │ │ │ │ │ - beforeload: this.manageTileCache, │ │ │ │ │ - loadend: this.addToCache, │ │ │ │ │ - unload: this.unloadTile, │ │ │ │ │ - scope: this │ │ │ │ │ + GET: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "GET" │ │ │ │ │ }); │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileQueue[tile.layer.map.id], tile); │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: queueTileDraw │ │ │ │ │ - * Adds a tile to the queue that will draw it. │ │ │ │ │ + * APIMethod: POST │ │ │ │ │ + * Send a POST request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to POST and "Content-Type" header set to "application/xml". │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ - */ │ │ │ │ │ - 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: drawTilesFromQueue │ │ │ │ │ - * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. The │ │ │ │ │ + * default "Content-Type" header will be set to "application-xml" if │ │ │ │ │ + * none is provided. This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + POST: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "POST" │ │ │ │ │ + }); │ │ │ │ │ + // set content type to application/xml if it isn't already set │ │ │ │ │ + config.headers = config.headers ? config.headers : {}; │ │ │ │ │ + if (!("CONTENT-TYPE" in OpenLayers.Util.upperCaseObject(config.headers))) { │ │ │ │ │ + config.headers["Content-Type"] = "application/xml"; │ │ │ │ │ } │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: manageTileCache │ │ │ │ │ - * Adds, updates, removes and fetches cache entries. │ │ │ │ │ + * APIMethod: PUT │ │ │ │ │ + * Send an HTTP PUT request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to PUT and "Content-Type" header set to "application/xml". │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. The │ │ │ │ │ + * default "Content-Type" header will be set to "application-xml" if │ │ │ │ │ + * none is provided. This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + PUT: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "PUT" │ │ │ │ │ + }); │ │ │ │ │ + // set content type to application/xml if it isn't already set │ │ │ │ │ + config.headers = config.headers ? config.headers : {}; │ │ │ │ │ + if (!("CONTENT-TYPE" in OpenLayers.Util.upperCaseObject(config.headers))) { │ │ │ │ │ + config.headers["Content-Type"] = "application/xml"; │ │ │ │ │ } │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addToCache │ │ │ │ │ + * APIMethod: DELETE │ │ │ │ │ + * Send an HTTP DELETE request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to DELETE. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. │ │ │ │ │ + * This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + DELETE: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "DELETE" │ │ │ │ │ + }); │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTileQueue │ │ │ │ │ - * Clears the tile queue from tiles of a specific layer │ │ │ │ │ + * APIMethod: HEAD │ │ │ │ │ + * Send an HTTP HEAD request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to HEAD. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the layer's retile event │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. │ │ │ │ │ + * This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + HEAD: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "HEAD" │ │ │ │ │ + }); │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * APIMethod: OPTIONS │ │ │ │ │ + * Send an HTTP OPTIONS request. Additional configuration properties are │ │ │ │ │ + * documented in the method, with the method property set │ │ │ │ │ + * to OPTIONS. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * config - {Object} Object with properties for configuring the request. │ │ │ │ │ + * See the method for documentation of allowed properties. │ │ │ │ │ + * This object is modified and should not be reused. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {XMLHttpRequest} Request object. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + OPTIONS: function(config) { │ │ │ │ │ + config = OpenLayers.Util.extend(config, { │ │ │ │ │ + method: "OPTIONS" │ │ │ │ │ + }); │ │ │ │ │ + return OpenLayers.Request.issue(config); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Marker/Box.js │ │ │ │ │ + OpenLayers/WPSProcess.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/Marker.js │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Format/WKT.js │ │ │ │ │ + * @requires OpenLayers/Format/GeoJSON.js │ │ │ │ │ + * @requires OpenLayers/Format/WPSExecute.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Marker.Box │ │ │ │ │ + * Class: OpenLayers.WPSProcess │ │ │ │ │ + * Representation of a WPS process. Usually instances of │ │ │ │ │ + * are created by calling 'getProcess' on an │ │ │ │ │ + * instance. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Currently supports processes that have geometries │ │ │ │ │ + * or features as output, using WKT or GeoJSON as output format. It also │ │ │ │ │ + * supports chaining of processes by using the method to create a │ │ │ │ │ + * handle that is used as process input instead of a static value. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, { │ │ │ │ │ +OpenLayers.WPSProcess = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: client │ │ │ │ │ + * {} The client that manages this process. │ │ │ │ │ */ │ │ │ │ │ - bounds: null, │ │ │ │ │ + client: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * Property: server │ │ │ │ │ + * {String} Local client identifier for this process's server. │ │ │ │ │ */ │ │ │ │ │ - div: null, │ │ │ │ │ + server: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Marker.Box │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * borderColor - {String} │ │ │ │ │ - * borderWidth - {int} │ │ │ │ │ + /** │ │ │ │ │ + * Property: identifier │ │ │ │ │ + * {String} Process identifier known to the server. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + identifier: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Property: description │ │ │ │ │ + * {Object} DescribeProcess response for this process. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - this.div = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Marker.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: localWPS │ │ │ │ │ + * {String} Service endpoint for locally chained WPS processes. Default is │ │ │ │ │ + * 'http://geoserver/wps'. │ │ │ │ │ */ │ │ │ │ │ - setBorder: function(color, width) { │ │ │ │ │ - if (!color) { │ │ │ │ │ - color = "red"; │ │ │ │ │ - } │ │ │ │ │ - if (!width) { │ │ │ │ │ - width = 2; │ │ │ │ │ - } │ │ │ │ │ - this.div.style.border = width + "px solid " + color; │ │ │ │ │ - }, │ │ │ │ │ + localWPS: 'http://geoserver/wps', │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * sz - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ - * location passed-in │ │ │ │ │ + /** │ │ │ │ │ + * Property: formats │ │ │ │ │ + * {Object} OpenLayers.Format instances keyed by mimetype. │ │ │ │ │ */ │ │ │ │ │ - draw: function(px, sz) { │ │ │ │ │ - OpenLayers.Util.modifyDOMElement(this.div, null, px, sz); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ + formats: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Rreturn: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ + * Property: chained │ │ │ │ │ + * {Integer} Number of chained processes for pending execute requests that │ │ │ │ │ + * don't have a full configuration yet. │ │ │ │ │ */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsBounds(this.bounds, true, true); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ + chained: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * Property: executeCallbacks │ │ │ │ │ + * {Array} Callbacks waiting to be executed until all chained processes │ │ │ │ │ + * are configured; │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.div.style.display = (display) ? "" : "none"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Marker.Box" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy/Paging.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/Strategy.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Strategy.Paging │ │ │ │ │ - * Strategy for vector feature paging │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Strategy.Paging = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ + executeCallbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: features │ │ │ │ │ - * {Array()} Cached features. │ │ │ │ │ + * Constructor: OpenLayers.WPSProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * │ │ │ │ │ + * Avaliable options: │ │ │ │ │ + * client - {} Mandatory. Client that manages this │ │ │ │ │ + * process. │ │ │ │ │ + * server - {String} Mandatory. Local client identifier of this process's │ │ │ │ │ + * server. │ │ │ │ │ + * identifier - {String} Mandatory. Process identifier known to the server. │ │ │ │ │ */ │ │ │ │ │ - features: null, │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.executeCallbacks = []; │ │ │ │ │ + this.formats = { │ │ │ │ │ + 'application/wkt': new OpenLayers.Format.WKT(), │ │ │ │ │ + 'application/json': new OpenLayers.Format.GeoJSON() │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: length │ │ │ │ │ - * {Integer} Number of features per page. Default is 10. │ │ │ │ │ + * Method: describe │ │ │ │ │ + * Makes the client issue a DescribeProcess request asynchronously. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Configuration for the method call │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * callback - {Function} Callback to execute when the description is │ │ │ │ │ + * available. Will be called with the parsed description as argument. │ │ │ │ │ + * Optional. │ │ │ │ │ + * scope - {Object} The scope in which the callback will be executed. │ │ │ │ │ + * Default is the global object. │ │ │ │ │ */ │ │ │ │ │ - length: 10, │ │ │ │ │ + describe: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + if (!this.description) { │ │ │ │ │ + this.client.describeProcess(this.server, this.identifier, function(description) { │ │ │ │ │ + if (!this.description) { │ │ │ │ │ + this.parseDescription(description); │ │ │ │ │ + } │ │ │ │ │ + if (options.callback) { │ │ │ │ │ + options.callback.call(options.scope, this.description); │ │ │ │ │ + } │ │ │ │ │ + }, this); │ │ │ │ │ + } else if (options.callback) { │ │ │ │ │ + var description = this.description; │ │ │ │ │ + window.setTimeout(function() { │ │ │ │ │ + options.callback.call(options.scope, description); │ │ │ │ │ + }, 0); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: num │ │ │ │ │ - * {Integer} The currently displayed page number. │ │ │ │ │ + * APIMethod: configure │ │ │ │ │ + * Configure the process, but do not execute it. Use this for processes │ │ │ │ │ + * that are chained as input of a different process by means of the │ │ │ │ │ + * method. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} this process. │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * 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. │ │ │ │ │ + * callback - {Function} Callback to call when the configuration is │ │ │ │ │ + * complete. Optional. │ │ │ │ │ + * scope - {Object} Optional scope for the callback. │ │ │ │ │ */ │ │ │ │ │ - num: null, │ │ │ │ │ + configure: function(options) { │ │ │ │ │ + this.describe({ │ │ │ │ │ + callback: function() { │ │ │ │ │ + var description = this.description, │ │ │ │ │ + inputs = options.inputs, │ │ │ │ │ + input, i, ii; │ │ │ │ │ + for (i = 0, ii = description.dataInputs.length; i < ii; ++i) { │ │ │ │ │ + input = description.dataInputs[i]; │ │ │ │ │ + this.setInputData(input, inputs[input.identifier]); │ │ │ │ │ + } │ │ │ │ │ + if (options.callback) { │ │ │ │ │ + options.callback.call(options.scope); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + return this; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: paging │ │ │ │ │ - * {Boolean} The strategy is currently changing pages. │ │ │ │ │ + * APIMethod: execute │ │ │ │ │ + * Configures and executes the process │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * 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 the output to request and parse. │ │ │ │ │ + * Optional. If not provided, the first output will be requested. │ │ │ │ │ + * 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 │ │ │ │ │ + * (or 'result' if output was not configured). For processes that │ │ │ │ │ + * generate spatial output, the value will be an array of │ │ │ │ │ + * instances. │ │ │ │ │ + * scope - {Object} Optional scope for the success callback. │ │ │ │ │ */ │ │ │ │ │ - paging: false, │ │ │ │ │ + execute: function(options) { │ │ │ │ │ + this.configure({ │ │ │ │ │ + inputs: options.inputs, │ │ │ │ │ + callback: function() { │ │ │ │ │ + var me = this; │ │ │ │ │ + //TODO For now we only deal with a single output │ │ │ │ │ + var outputIndex = this.getOutputIndex( │ │ │ │ │ + me.description.processOutputs, options.output │ │ │ │ │ + ); │ │ │ │ │ + me.setResponseForm({ │ │ │ │ │ + outputIndex: outputIndex │ │ │ │ │ + }); │ │ │ │ │ + (function callback() { │ │ │ │ │ + OpenLayers.Util.removeItem(me.executeCallbacks, callback); │ │ │ │ │ + if (me.chained !== 0) { │ │ │ │ │ + // need to wait until chained processes have a │ │ │ │ │ + // description and configuration - see chainProcess │ │ │ │ │ + me.executeCallbacks.push(callback); │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + // all chained processes are added as references now, so │ │ │ │ │ + // let's proceed. │ │ │ │ │ + OpenLayers.Request.POST({ │ │ │ │ │ + url: me.client.servers[me.server].url, │ │ │ │ │ + data: new OpenLayers.Format.WPSExecute().write(me.description), │ │ │ │ │ + success: function(response) { │ │ │ │ │ + var output = me.description.processOutputs[outputIndex]; │ │ │ │ │ + var mimeType = me.findMimeType( │ │ │ │ │ + output.complexOutput.supported.formats │ │ │ │ │ + ); │ │ │ │ │ + //TODO For now we assume a spatial output │ │ │ │ │ + var features = me.formats[mimeType].read(response.responseText); │ │ │ │ │ + if (features instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ + features = [features]; │ │ │ │ │ + } │ │ │ │ │ + if (options.success) { │ │ │ │ │ + var outputs = {}; │ │ │ │ │ + outputs[options.output || 'result'] = features; │ │ │ │ │ + options.success.call(options.scope, outputs); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + scope: me │ │ │ │ │ + }); │ │ │ │ │ + })(); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Paging │ │ │ │ │ - * Create a new paging strategy. │ │ │ │ │ + * APIMethod: output │ │ │ │ │ + * Chain an output of a configured process (see ) as input to │ │ │ │ │ + * another process. │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * intersect = client.getProcess('opengeo', 'JTS:intersection'); │ │ │ │ │ + * intersect.configure({ │ │ │ │ │ + * // ... │ │ │ │ │ + * }); │ │ │ │ │ + * buffer = client.getProcess('opengeo', 'JTS:buffer'); │ │ │ │ │ + * buffer.execute({ │ │ │ │ │ + * inputs: { │ │ │ │ │ + * geom: intersect.output('result'), // <-- here we're chaining │ │ │ │ │ + * distance: 1 │ │ │ │ │ + * }, │ │ │ │ │ + * // ... │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * identifier - {String} Identifier of the output that we're chaining. If │ │ │ │ │ + * not provided, the first output will be used. │ │ │ │ │ */ │ │ │ │ │ + output: function(identifier) { │ │ │ │ │ + return new OpenLayers.WPSProcess.ChainLink({ │ │ │ │ │ + process: this, │ │ │ │ │ + output: identifier │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully activated. │ │ │ │ │ + * Method: parseDescription │ │ │ │ │ + * Parses the DescribeProcess response │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * description - {Object} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "beforefeaturesadded": this.cacheFeatures, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ + parseDescription: function(description) { │ │ │ │ │ + var server = this.client.servers[this.server]; │ │ │ │ │ + this.description = new OpenLayers.Format.WPSDescribeProcess() │ │ │ │ │ + .read(server.processDescription[this.identifier]) │ │ │ │ │ + .processDescriptions[this.identifier]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully deactivated. │ │ │ │ │ + * Method: setInputData │ │ │ │ │ + * Sets the data for a single input │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * input - {Object} An entry from the dataInputs array of the process │ │ │ │ │ + * description. │ │ │ │ │ + * data - {Mixed} For spatial data inputs, this is usually an │ │ │ │ │ + * , an or an array of │ │ │ │ │ + * geometries or features. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - this.clearCache(); │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "beforefeaturesadded": this.cacheFeatures, │ │ │ │ │ + setInputData: function(input, data) { │ │ │ │ │ + // clear any previous data │ │ │ │ │ + delete input.data; │ │ │ │ │ + delete input.reference; │ │ │ │ │ + if (data instanceof OpenLayers.WPSProcess.ChainLink) { │ │ │ │ │ + ++this.chained; │ │ │ │ │ + input.reference = { │ │ │ │ │ + method: 'POST', │ │ │ │ │ + href: data.process.server === this.server ? │ │ │ │ │ + this.localWPS : this.client.servers[data.process.server].url │ │ │ │ │ + }; │ │ │ │ │ + data.process.describe({ │ │ │ │ │ + callback: function() { │ │ │ │ │ + --this.chained; │ │ │ │ │ + this.chainProcess(input, data); │ │ │ │ │ + }, │ │ │ │ │ scope: this │ │ │ │ │ }); │ │ │ │ │ + } else { │ │ │ │ │ + input.data = {}; │ │ │ │ │ + var complexData = input.complexData; │ │ │ │ │ + if (complexData) { │ │ │ │ │ + var format = this.findMimeType(complexData.supported.formats); │ │ │ │ │ + input.data.complexData = { │ │ │ │ │ + mimeType: format, │ │ │ │ │ + value: this.formats[format].write(this.toFeatures(data)) │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + input.data.literalData = { │ │ │ │ │ + value: data │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cacheFeatures │ │ │ │ │ - * Cache features before they are added to the layer. │ │ │ │ │ + * Method: setResponseForm │ │ │ │ │ + * Sets the responseForm property of the payload. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The event that this was listening for. This will come │ │ │ │ │ - * with a batch of features to be paged. │ │ │ │ │ + * options - {Object} See below. │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * outputIndex - {Integer} The index of the output to use. Optional. │ │ │ │ │ + * supportedFormats - {Object} Object with supported mime types as key, │ │ │ │ │ + * and true as value for supported types. Optional. │ │ │ │ │ */ │ │ │ │ │ - cacheFeatures: function(event) { │ │ │ │ │ - if (!this.paging) { │ │ │ │ │ - this.clearCache(); │ │ │ │ │ - this.features = event.features; │ │ │ │ │ - this.pageNext(event); │ │ │ │ │ - } │ │ │ │ │ + setResponseForm: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + var output = this.description.processOutputs[options.outputIndex || 0]; │ │ │ │ │ + this.description.responseForm = { │ │ │ │ │ + rawDataOutput: { │ │ │ │ │ + identifier: output.identifier, │ │ │ │ │ + mimeType: this.findMimeType(output.complexOutput.supported.formats, options.supportedFormats) │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearCache │ │ │ │ │ - * Clear out the cached features. This destroys features, assuming │ │ │ │ │ - * nothing else has a reference. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - clearCache: function() { │ │ │ │ │ - if (this.features) { │ │ │ │ │ - for (var i = 0; i < this.features.length; ++i) { │ │ │ │ │ - this.features[i].destroy(); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - this.features = null; │ │ │ │ │ - this.num = null; │ │ │ │ │ + return output; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: pageCount │ │ │ │ │ - * Get the total count of pages given the current cache of features. │ │ │ │ │ + * Method: chainProcess │ │ │ │ │ + * Sets a fully configured chained process as input for this process. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The page count. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * input - {Object} The dataInput that the chained process provides. │ │ │ │ │ + * chainLink - {} The process to chain. │ │ │ │ │ */ │ │ │ │ │ - pageCount: function() { │ │ │ │ │ - var numFeatures = this.features ? this.features.length : 0; │ │ │ │ │ - return Math.ceil(numFeatures / this.length); │ │ │ │ │ + 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](); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: pageNum │ │ │ │ │ - * Get the zero based page number. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Integer} The current page number being displayed. │ │ │ │ │ + * {Array()} │ │ │ │ │ */ │ │ │ │ │ - pageNum: function() { │ │ │ │ │ - return this.num; │ │ │ │ │ + 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]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: pageLength │ │ │ │ │ - * Gets or sets page length. │ │ │ │ │ + * Method: findMimeType │ │ │ │ │ + * Finds a supported mime type. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newLength - {Integer} Optional length to be set. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Integer} The length of a page (number of features per page). │ │ │ │ │ + * {String} A supported mime type. │ │ │ │ │ */ │ │ │ │ │ - pageLength: function(newLength) { │ │ │ │ │ - if (newLength && newLength > 0) { │ │ │ │ │ - this.length = newLength; │ │ │ │ │ + findMimeType: function(sourceFormats, targetFormats) { │ │ │ │ │ + targetFormats = targetFormats || this.formats; │ │ │ │ │ + for (var f in sourceFormats) { │ │ │ │ │ + if (f in targetFormats) { │ │ │ │ │ + return f; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return this.length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.WPSProcess" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ + * Type for chaining processes. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.WPSProcess.ChainLink = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: pageNext │ │ │ │ │ - * Display the next page of features. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A new page was displayed. │ │ │ │ │ + * Property: process │ │ │ │ │ + * {} The process to chain │ │ │ │ │ */ │ │ │ │ │ - pageNext: function(event) { │ │ │ │ │ - var changed = false; │ │ │ │ │ - if (this.features) { │ │ │ │ │ - if (this.num === null) { │ │ │ │ │ - this.num = -1; │ │ │ │ │ - } │ │ │ │ │ - var start = (this.num + 1) * this.length; │ │ │ │ │ - changed = this.page(start, event); │ │ │ │ │ - } │ │ │ │ │ - return changed; │ │ │ │ │ - }, │ │ │ │ │ + process: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: pagePrevious │ │ │ │ │ - * Display the previous page of features. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A new page was displayed. │ │ │ │ │ + * Property: output │ │ │ │ │ + * {String} The output identifier of the output we are going to use as │ │ │ │ │ + * input for another process. │ │ │ │ │ */ │ │ │ │ │ - pagePrevious: function() { │ │ │ │ │ - var changed = false; │ │ │ │ │ - if (this.features) { │ │ │ │ │ - if (this.num === null) { │ │ │ │ │ - this.num = this.pageCount(); │ │ │ │ │ - } │ │ │ │ │ - var start = (this.num - 1) * this.length; │ │ │ │ │ - changed = this.page(start); │ │ │ │ │ - } │ │ │ │ │ - return changed; │ │ │ │ │ - }, │ │ │ │ │ + output: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: page │ │ │ │ │ - * Display the page starting at the given index from the cache. │ │ │ │ │ + * Constructor: OpenLayers.WPSProcess.ChainLink │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A new page was displayed. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Properties to set on the instance. │ │ │ │ │ */ │ │ │ │ │ - page: function(start, event) { │ │ │ │ │ - var changed = false; │ │ │ │ │ - if (this.features) { │ │ │ │ │ - if (start >= 0 && start < this.features.length) { │ │ │ │ │ - var num = Math.floor(start / this.length); │ │ │ │ │ - if (num != this.num) { │ │ │ │ │ - this.paging = true; │ │ │ │ │ - var features = this.features.slice(start, start + this.length); │ │ │ │ │ - this.layer.removeFeatures(this.layer.features); │ │ │ │ │ - this.num = num; │ │ │ │ │ - // modify the event if any │ │ │ │ │ - if (event && event.features) { │ │ │ │ │ - // this.was called by an event listener │ │ │ │ │ - event.features = features; │ │ │ │ │ - } else { │ │ │ │ │ - // this was called directly on the strategy │ │ │ │ │ - this.layer.addFeatures(features); │ │ │ │ │ - } │ │ │ │ │ - this.paging = false; │ │ │ │ │ - changed = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return changed; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Paging" │ │ │ │ │ + CLASS_NAME: "OpenLayers.WPSProcess.ChainLink" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy/Filter.js │ │ │ │ │ + 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/Strategy.js │ │ │ │ │ - * @requires OpenLayers/Filter.js │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1_1_0.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy.Filter │ │ │ │ │ - * Strategy for limiting features that get added to a layer by │ │ │ │ │ - * evaluating a filter. The strategy maintains a cache of │ │ │ │ │ - * all features until removeFeatures is called on the layer. │ │ │ │ │ + * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * Read WPS DescribeProcess responses. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy.Filter = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ +OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: filter │ │ │ │ │ - * {} Filter for limiting features sent to the layer. │ │ │ │ │ - * Use the method to update this filter after construction. │ │ │ │ │ - */ │ │ │ │ │ - filter: null, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: cache │ │ │ │ │ - * {Array()} List of currently cached │ │ │ │ │ - * features. │ │ │ │ │ - */ │ │ │ │ │ - cache: null, │ │ │ │ │ + /** │ │ │ │ │ + * 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: caching │ │ │ │ │ - * {Boolean} The filter is currently caching features. │ │ │ │ │ - */ │ │ │ │ │ - caching: 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", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Filter │ │ │ │ │ - * Create a new filter strategy. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + */ │ │ │ │ │ + defaultPrefix: "wps", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * By default, this strategy automatically activates itself when a layer │ │ │ │ │ - * is added to a map. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ - * the strategy was already active. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.apply(this, arguments); │ │ │ │ │ - if (activated) { │ │ │ │ │ - this.cache = []; │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "beforefeaturesadded": this.handleAdd, │ │ │ │ │ - "beforefeaturesremoved": this.handleRemove, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ + */ │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the strategy. Clear the feature cache. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully deactivated or false if │ │ │ │ │ - * the strategy was already inactive. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - this.cache = null; │ │ │ │ │ - if (this.layer && this.layer.events) { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "beforefeaturesadded": this.handleAdd, │ │ │ │ │ - "beforefeaturesremoved": this.handleRemove, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Strategy.prototype.deactivate.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleAdd │ │ │ │ │ - */ │ │ │ │ │ - handleAdd: function(event) { │ │ │ │ │ - if (!this.caching && this.filter) { │ │ │ │ │ - var features = event.features; │ │ │ │ │ - event.features = []; │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = 0, ii = features.length; i < ii; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (this.filter.evaluate(feature)) { │ │ │ │ │ - event.features.push(feature); │ │ │ │ │ - } else { │ │ │ │ │ - this.cache.push(feature); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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]); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleRemove │ │ │ │ │ - */ │ │ │ │ │ - handleRemove: function(event) { │ │ │ │ │ - if (!this.caching) { │ │ │ │ │ - this.cache = []; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setFilter │ │ │ │ │ - * Update the filter for this strategy. This will re-evaluate │ │ │ │ │ - * any features on the layer and in the cache. Only features │ │ │ │ │ - * for which filter.evalute(feature) returns true will be │ │ │ │ │ - * added to the layer. Others will be cached by the strategy. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} A filter for evaluating features. │ │ │ │ │ - */ │ │ │ │ │ - setFilter: function(filter) { │ │ │ │ │ - this.filter = filter; │ │ │ │ │ - var previousCache = this.cache; │ │ │ │ │ - this.cache = []; │ │ │ │ │ - // look through layer for features to remove from layer │ │ │ │ │ - this.handleAdd({ │ │ │ │ │ - features: this.layer.features │ │ │ │ │ - }); │ │ │ │ │ - // cache now contains features to remove from layer │ │ │ │ │ - if (this.cache.length > 0) { │ │ │ │ │ - this.caching = true; │ │ │ │ │ - this.layer.removeFeatures(this.cache.slice()); │ │ │ │ │ - this.caching = false; │ │ │ │ │ - } │ │ │ │ │ - // now look through previous cache for features to add to layer │ │ │ │ │ - if (previousCache.length > 0) { │ │ │ │ │ - var event = { │ │ │ │ │ - features: previousCache │ │ │ │ │ - }; │ │ │ │ │ - this.handleAdd(event); │ │ │ │ │ - if (event.features.length > 0) { │ │ │ │ │ - // event has features to add to layer │ │ │ │ │ - this.caching = true; │ │ │ │ │ - this.layer.addFeatures(event.features); │ │ │ │ │ - this.caching = false; │ │ │ │ │ + if (data && data.nodeType == 9) { │ │ │ │ │ + data = data.documentElement; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + var info = {}; │ │ │ │ │ + this.readNode(data, info); │ │ │ │ │ + return info; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Filter" │ │ │ │ │ + /** │ │ │ │ │ + * 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/Strategy/Save.js │ │ │ │ │ + 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/Strategy.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy.Save │ │ │ │ │ - * A strategy that commits newly created or modified features. By default │ │ │ │ │ - * the strategy waits for a call to before persisting changes. By │ │ │ │ │ - * configuring the strategy with the option, changes can be saved │ │ │ │ │ - * automatically. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/WPSProcess.js │ │ │ │ │ + * @requires OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy.Save = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * 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({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the strategy object. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * strategy.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ + * Property: servers │ │ │ │ │ + * {Object} Service metadata, keyed by a local identifier. │ │ │ │ │ * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * start - Triggered before saving │ │ │ │ │ - * success - Triggered after a successful transaction │ │ │ │ │ - * fail - Triggered after a failed transaction │ │ │ │ │ - * │ │ │ │ │ + * 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: events │ │ │ │ │ - * {} Events instance for triggering this protocol │ │ │ │ │ - * events. │ │ │ │ │ + /** │ │ │ │ │ + * Property: version │ │ │ │ │ + * {String} The default WPS version to use if none is configured. Default │ │ │ │ │ + * is '1.0.0'. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + version: '1.0.0', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: auto │ │ │ │ │ - * {Boolean | Number} Auto-save. Default is false. If true, features will be │ │ │ │ │ - * saved immediately after being added to the layer and with each │ │ │ │ │ - * modification or deletion. If auto is a number, features will be │ │ │ │ │ - * saved on an interval provided by the value (in seconds). │ │ │ │ │ + * Property: lazy │ │ │ │ │ + * {Boolean} Should the DescribeProcess be deferred until a process is │ │ │ │ │ + * fully configured? Default is false. │ │ │ │ │ */ │ │ │ │ │ - auto: false, │ │ │ │ │ + lazy: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timer │ │ │ │ │ - * {Number} The id of the timer. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - timer: null, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Save │ │ │ │ │ - * Create a new Save strategy. │ │ │ │ │ + * Constructor: OpenLayers.WPSClient │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * 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.Strategy.prototype.initialize.apply(this, [options]); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ this.events = new OpenLayers.Events(this); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - if (this.auto) { │ │ │ │ │ - if (typeof this.auto === "number") { │ │ │ │ │ - this.timer = window.setInterval( │ │ │ │ │ - OpenLayers.Function.bind(this.save, this), │ │ │ │ │ - this.auto * 1000 │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "featureadded": this.triggerSave, │ │ │ │ │ - "afterfeaturemodified": this.triggerSave, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - if (this.auto) { │ │ │ │ │ - if (typeof this.auto === "number") { │ │ │ │ │ - window.clearInterval(this.timer); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "featureadded": this.triggerSave, │ │ │ │ │ - "afterfeaturemodified": this.triggerSave, │ │ │ │ │ - scope: 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]; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: triggerSave │ │ │ │ │ - * Registered as a listener. Calls save if a feature has insert, update, │ │ │ │ │ - * or delete state. │ │ │ │ │ + * 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: │ │ │ │ │ - * event - {Object} The event this function is listening for. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - triggerSave: function(event) { │ │ │ │ │ - var feature = event.feature; │ │ │ │ │ - if (feature.state === OpenLayers.State.INSERT || │ │ │ │ │ - feature.state === OpenLayers.State.UPDATE || │ │ │ │ │ - feature.state === OpenLayers.State.DELETE) { │ │ │ │ │ - this.save([event.feature]); │ │ │ │ │ - } │ │ │ │ │ + execute: function(options) { │ │ │ │ │ + var process = this.getProcess(options.server, options.process); │ │ │ │ │ + process.execute({ │ │ │ │ │ + inputs: options.inputs, │ │ │ │ │ + success: options.success, │ │ │ │ │ + scope: options.scope │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: save │ │ │ │ │ - * Tell the layer protocol to commit unsaved features. If the layer │ │ │ │ │ - * projection differs from the map projection, features will be │ │ │ │ │ - * transformed into the layer projection before being committed. │ │ │ │ │ + * APIMethod: getProcess │ │ │ │ │ + * Creates an . │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array} Features to be saved. If null, then default is all │ │ │ │ │ - * features in the layer. Features are assumed to be in the map │ │ │ │ │ - * projection. │ │ │ │ │ + * serverID - {String} Local identifier from the servers that this instance │ │ │ │ │ + * was constructed with. │ │ │ │ │ + * processID - {String} Process identifier known to the server. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - save: function(features) { │ │ │ │ │ - if (!features) { │ │ │ │ │ - features = this.layer.features; │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("start", { │ │ │ │ │ - features: features │ │ │ │ │ + getProcess: function(serverID, processID) { │ │ │ │ │ + var process = new OpenLayers.WPSProcess({ │ │ │ │ │ + client: this, │ │ │ │ │ + server: serverID, │ │ │ │ │ + identifier: processID │ │ │ │ │ }); │ │ │ │ │ - var remote = this.layer.projection; │ │ │ │ │ - var local = this.layer.map.getProjectionObject(); │ │ │ │ │ - if (!local.equals(remote)) { │ │ │ │ │ - var len = features.length; │ │ │ │ │ - var clones = new Array(len); │ │ │ │ │ - var orig, clone; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - orig = features[i]; │ │ │ │ │ - clone = orig.clone(); │ │ │ │ │ - clone.fid = orig.fid; │ │ │ │ │ - clone.state = orig.state; │ │ │ │ │ - if (orig.url) { │ │ │ │ │ - clone.url = orig.url; │ │ │ │ │ - } │ │ │ │ │ - clone._original = orig; │ │ │ │ │ - clone.geometry.transform(local, remote); │ │ │ │ │ - clones[i] = clone; │ │ │ │ │ - } │ │ │ │ │ - features = clones; │ │ │ │ │ + if (!this.lazy) { │ │ │ │ │ + process.describe(); │ │ │ │ │ } │ │ │ │ │ - this.layer.protocol.commit(features, { │ │ │ │ │ - callback: this.onCommit, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + return process; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onCommit │ │ │ │ │ - * Called after protocol commit. │ │ │ │ │ + * Method: describeProcess │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * response - {} A response object. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - onCommit: function(response) { │ │ │ │ │ - var evt = { │ │ │ │ │ - "response": response │ │ │ │ │ - }; │ │ │ │ │ - if (response.success()) { │ │ │ │ │ - var features = response.reqFeatures; │ │ │ │ │ - // deal with inserts, updates, and deletes │ │ │ │ │ - var state, feature; │ │ │ │ │ - var destroys = []; │ │ │ │ │ - var insertIds = response.insertIds || []; │ │ │ │ │ - var j = 0; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - // if projection was different, we may be dealing with clones │ │ │ │ │ - feature = feature._original || feature; │ │ │ │ │ - state = feature.state; │ │ │ │ │ - if (state) { │ │ │ │ │ - if (state == OpenLayers.State.DELETE) { │ │ │ │ │ - destroys.push(feature); │ │ │ │ │ - } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ - feature.fid = insertIds[j]; │ │ │ │ │ - ++j; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - feature.state = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (destroys.length > 0) { │ │ │ │ │ - this.layer.destroyFeatures(destroys); │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("success", evt); │ │ │ │ │ - │ │ │ │ │ } else { │ │ │ │ │ - this.events.triggerEvent("fail", evt); │ │ │ │ │ + window.setTimeout(function() { │ │ │ │ │ + callback.call(scope, server.processDescription[processID]); │ │ │ │ │ + }, 0); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Save" │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + this.servers = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy/Fixed.js │ │ │ │ │ + OpenLayers/Kinetic.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/Strategy.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Strategy.Fixed │ │ │ │ │ - * A simple strategy that requests features once and never requests new data. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ +OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: preload │ │ │ │ │ - * {Boolean} Load data before layer made visible. Enabling this may result │ │ │ │ │ - * in considerable overhead if your application loads many data layers │ │ │ │ │ - * that are not visible by default. Default is false. │ │ │ │ │ + * Property: threshold │ │ │ │ │ + * In most cases changing the threshold isn't needed. │ │ │ │ │ + * In px/ms, default to 0. │ │ │ │ │ */ │ │ │ │ │ - preload: false, │ │ │ │ │ + threshold: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Fixed │ │ │ │ │ - * Create a new Fixed strategy. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * Property: deceleration │ │ │ │ │ + * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ */ │ │ │ │ │ + deceleration: 0.0035, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the strategy: load data or add listener to load when visible │ │ │ │ │ + * Property: nbPoints │ │ │ │ │ + * {Integer} the number of points we use to calculate the kinetic │ │ │ │ │ + * initial values. │ │ │ │ │ + */ │ │ │ │ │ + nbPoints: 100, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: delay │ │ │ │ │ + * {Float} time to consider to calculate the kinetic initial values. │ │ │ │ │ + * In ms, default to 200. │ │ │ │ │ + */ │ │ │ │ │ + delay: 200, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: points │ │ │ │ │ + * List of points use to calculate the kinetic initial values. │ │ │ │ │ + */ │ │ │ │ │ + points: undefined, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * ID of the timer. │ │ │ │ │ + */ │ │ │ │ │ + timerId: undefined, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Kinetic │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ - * the strategy was already active. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.apply(this, arguments); │ │ │ │ │ - if (activated) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "refresh": this.load, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - if (this.layer.visibility == true || this.preload) { │ │ │ │ │ - this.load(); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "visibilitychanged": this.load, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the strategy. Undo what is done in . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully deactivated. │ │ │ │ │ + * Method: begin │ │ │ │ │ + * Begins the dragging. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "refresh": this.load, │ │ │ │ │ - "visibilitychanged": this.load, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + begin: function() { │ │ │ │ │ + OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ + this.timerId = undefined; │ │ │ │ │ + this.points = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: load │ │ │ │ │ - * Tells protocol to load data and unhooks the visibilitychanged event │ │ │ │ │ + * Method: update │ │ │ │ │ + * Updates during the dragging. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} options to pass to protocol read. │ │ │ │ │ + * xy - {} The new position. │ │ │ │ │ */ │ │ │ │ │ - load: function(options) { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - layer.events.triggerEvent("loadstart", { │ │ │ │ │ - filter: layer.filter │ │ │ │ │ - }); │ │ │ │ │ - layer.protocol.read(OpenLayers.Util.applyDefaults({ │ │ │ │ │ - callback: this.merge, │ │ │ │ │ - filter: layer.filter, │ │ │ │ │ - scope: this │ │ │ │ │ - }, options)); │ │ │ │ │ - layer.events.un({ │ │ │ │ │ - "visibilitychanged": this.load, │ │ │ │ │ - scope: this │ │ │ │ │ + update: function(xy) { │ │ │ │ │ + this.points.unshift({ │ │ │ │ │ + xy: xy, │ │ │ │ │ + tick: new Date().getTime() │ │ │ │ │ }); │ │ │ │ │ + if (this.points.length > this.nbPoints) { │ │ │ │ │ + this.points.pop(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: merge │ │ │ │ │ - * Add all features to the layer. │ │ │ │ │ - * If the layer projection differs from the map projection, features │ │ │ │ │ - * will be transformed from the layer projection to the map projection. │ │ │ │ │ + * Method: end │ │ │ │ │ + * Ends the dragging, start the kinetic. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * resp - {} The response object passed │ │ │ │ │ - * by the protocol. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - merge: function(resp) { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - layer.destroyFeatures(); │ │ │ │ │ - var features = resp.features; │ │ │ │ │ - if (features && features.length > 0) { │ │ │ │ │ - var remote = layer.projection; │ │ │ │ │ - var local = layer.map.getProjectionObject(); │ │ │ │ │ - if (!local.equals(remote)) { │ │ │ │ │ - var geom; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - geom = features[i].geometry; │ │ │ │ │ - if (geom) { │ │ │ │ │ - geom.transform(remote, local); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - layer.addFeatures(features); │ │ │ │ │ + last = point; │ │ │ │ │ } │ │ │ │ │ - layer.events.triggerEvent("loadend", { │ │ │ │ │ - response: resp │ │ │ │ │ - }); │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Fixed" │ │ │ │ │ + /** │ │ │ │ │ + * Method: move │ │ │ │ │ + * Launch the kinetic move pan. │ │ │ │ │ + * │ │ │ │ │ + * 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). │ │ │ │ │ + */ │ │ │ │ │ + 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) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Kinetic" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy/BBOX.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/Strategy.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy.BBOX │ │ │ │ │ - * A simple strategy that reads new features when the viewport invalidates │ │ │ │ │ - * some bounds. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ +OpenLayers.Renderer = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: container │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + container: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The current data bounds (in the same projection │ │ │ │ │ - * as the layer - not always the same projection as the map). │ │ │ │ │ + * Property: root │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - bounds: null, │ │ │ │ │ + root: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The current data resolution. │ │ │ │ │ + * Property: extent │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - resolution: null, │ │ │ │ │ + extent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: ratio │ │ │ │ │ - * {Float} The ratio of the data bounds to the viewport bounds (in each │ │ │ │ │ - * dimension). Default is 2. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - ratio: 2, │ │ │ │ │ + locked: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resFactor │ │ │ │ │ - * {Float} Optional factor used to determine when previously requested │ │ │ │ │ - * features are invalid. If set, the resFactor will be compared to the │ │ │ │ │ - * resolution of the previous request to the current map resolution. │ │ │ │ │ - * If resFactor > (old / new) and 1/resFactor < (old / new). If you │ │ │ │ │ - * set a resFactor of 1, data will be requested every time the │ │ │ │ │ - * resolution changes. If you set a resFactor of 3, data will be │ │ │ │ │ - * requested if the old resolution is 3 times the new, or if the new is │ │ │ │ │ - * 3 times the old. If the old bounds do not contain the new bounds │ │ │ │ │ - * new data will always be requested (with or without considering │ │ │ │ │ - * resFactor). │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - resFactor: null, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: response │ │ │ │ │ - * {} The protocol response object returned │ │ │ │ │ - * by the layer protocol. │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} cache of current map resolution │ │ │ │ │ */ │ │ │ │ │ - response: null, │ │ │ │ │ + resolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.BBOX │ │ │ │ │ - * Create a new BBOX strategy. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: featureDx │ │ │ │ │ + * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ + * applied to the current feature while rendering (see │ │ │ │ │ + * ). │ │ │ │ │ + */ │ │ │ │ │ + featureDx: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Renderer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Set up strategy with regard to reading new batches of remote data. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully activated. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "moveend": this.update, │ │ │ │ │ - "refresh": this.update, │ │ │ │ │ - "visibilitychanged": this.update, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.update(); │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.container = null; │ │ │ │ │ + this.extent = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Tear down strategy with regard to reading new batches of remote data. │ │ │ │ │ + * APIMethod: supported │ │ │ │ │ + * This should be overridden by specific subclasses │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully deactivated. │ │ │ │ │ + * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "moveend": this.update, │ │ │ │ │ - "refresh": this.update, │ │ │ │ │ - "visibilitychanged": this.update, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + supported: function() { │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Callback function called on "moveend" or "refresh" layer events. │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} Optional object whose properties will determine │ │ │ │ │ - * the behaviour of this Strategy │ │ │ │ │ + * extent - {} │ │ │ │ │ + * resolutionChanged - {Boolean} │ │ │ │ │ * │ │ │ │ │ - * Valid options include: │ │ │ │ │ - * force - {Boolean} if true, new data must be unconditionally read. │ │ │ │ │ - * noAbort - {Boolean} if true, do not abort previous requests. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - update: function(options) { │ │ │ │ │ - var mapBounds = this.getMapBounds(); │ │ │ │ │ - if (mapBounds !== null && ((options && options.force) || │ │ │ │ │ - (this.layer.visibility && this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { │ │ │ │ │ - this.calculateBounds(mapBounds); │ │ │ │ │ - this.resolution = this.layer.map.getResolution(); │ │ │ │ │ - this.triggerRead(options); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapBounds │ │ │ │ │ - * Get the map bounds expressed in the same projection as this layer. │ │ │ │ │ + * 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: │ │ │ │ │ + * size - {} │ │ │ │ │ + */ │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getResolution │ │ │ │ │ + * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Map bounds in the projection of the layer. │ │ │ │ │ + * {Float} The current map's resolution │ │ │ │ │ */ │ │ │ │ │ - getMapBounds: function() { │ │ │ │ │ - if (this.layer.map === null) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - var bounds = this.layer.map.getExtent(); │ │ │ │ │ - if (bounds && !this.layer.projection.equals( │ │ │ │ │ - this.layer.map.getProjectionObject())) { │ │ │ │ │ - bounds = bounds.clone().transform( │ │ │ │ │ - this.layer.map.getProjectionObject(), this.layer.projection │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return bounds; │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ + return this.resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: invalidBounds │ │ │ │ │ - * Determine whether the previously requested set of features is invalid. │ │ │ │ │ - * This occurs when the new map bounds do not contain the previously │ │ │ │ │ - * requested bounds. In addition, if is set, it will be │ │ │ │ │ - * considered. │ │ │ │ │ + * 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: │ │ │ │ │ - * mapBounds - {} the current map extent, will be │ │ │ │ │ - * retrieved from the map object if not provided │ │ │ │ │ - * │ │ │ │ │ + * feature - {} │ │ │ │ │ + * style - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ + * undefined if the feature had no geometry │ │ │ │ │ */ │ │ │ │ │ - invalidBounds: function(mapBounds) { │ │ │ │ │ - if (!mapBounds) { │ │ │ │ │ - mapBounds = this.getMapBounds(); │ │ │ │ │ + drawFeature: function(feature, style) { │ │ │ │ │ + if (style == null) { │ │ │ │ │ + style = feature.style; │ │ │ │ │ } │ │ │ │ │ - var invalid = !this.bounds || !this.bounds.containsBounds(mapBounds); │ │ │ │ │ - if (!invalid && this.resFactor) { │ │ │ │ │ - var ratio = this.resolution / this.layer.map.getResolution(); │ │ │ │ │ - invalid = (ratio >= this.resFactor || ratio <= (1 / this.resFactor)); │ │ │ │ │ + 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) { │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return invalid; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ + * 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: │ │ │ │ │ - * mapBounds - {} the current map extent, will be │ │ │ │ │ - * retrieved from the map object if not provided │ │ │ │ │ + * bounds - {} Bounds of the feature │ │ │ │ │ + * worldBounds - {} Bounds of the world │ │ │ │ │ */ │ │ │ │ │ - calculateBounds: function(mapBounds) { │ │ │ │ │ - if (!mapBounds) { │ │ │ │ │ - mapBounds = this.getMapBounds(); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - var center = mapBounds.getCenterLonLat(); │ │ │ │ │ - var dataWidth = mapBounds.getWidth() * this.ratio; │ │ │ │ │ - var dataHeight = mapBounds.getHeight() * this.ratio; │ │ │ │ │ - this.bounds = new OpenLayers.Bounds( │ │ │ │ │ - center.lon - (dataWidth / 2), │ │ │ │ │ - center.lat - (dataHeight / 2), │ │ │ │ │ - center.lon + (dataWidth / 2), │ │ │ │ │ - center.lat + (dataHeight / 2) │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: triggerRead │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawGeometry │ │ │ │ │ + * │ │ │ │ │ + * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ + * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ + * virtual function │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Additional options for the protocol's read method │ │ │ │ │ - * (optional) │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The protocol response object │ │ │ │ │ - * returned by the layer protocol. │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * featureId - {} │ │ │ │ │ */ │ │ │ │ │ - triggerRead: function(options) { │ │ │ │ │ - if (this.response && !(options && options.noAbort === true)) { │ │ │ │ │ - this.layer.protocol.abort(this.response); │ │ │ │ │ - this.layer.events.triggerEvent("loadend"); │ │ │ │ │ - } │ │ │ │ │ - var evt = { │ │ │ │ │ - filter: this.createFilter() │ │ │ │ │ - }; │ │ │ │ │ - this.layer.events.triggerEvent("loadstart", evt); │ │ │ │ │ - this.response = this.layer.protocol.read( │ │ │ │ │ - OpenLayers.Util.applyDefaults({ │ │ │ │ │ - filter: evt.filter, │ │ │ │ │ - callback: this.merge, │ │ │ │ │ - scope: this │ │ │ │ │ - }, options)); │ │ │ │ │ - }, │ │ │ │ │ + drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createFilter │ │ │ │ │ - * Creates a spatial BBOX filter. If the layer that this strategy belongs │ │ │ │ │ - * to has a filter property, this filter will be combined with the BBOX │ │ │ │ │ - * filter. │ │ │ │ │ + * Method: drawText │ │ │ │ │ + * Function for drawing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ * │ │ │ │ │ - * Returns │ │ │ │ │ - * {} The filter object. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ + * style - │ │ │ │ │ + * location - {} │ │ │ │ │ */ │ │ │ │ │ - createFilter: function() { │ │ │ │ │ - var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ - value: this.bounds, │ │ │ │ │ - projection: this.layer.projection │ │ │ │ │ - }); │ │ │ │ │ - if (this.layer.filter) { │ │ │ │ │ - filter = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.AND, │ │ │ │ │ - filters: [this.layer.filter, filter] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return filter; │ │ │ │ │ - }, │ │ │ │ │ + drawText: function(featureId, style, location) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: merge │ │ │ │ │ - * Given a list of features, determine which ones to add to the layer. │ │ │ │ │ - * If the layer projection differs from the map projection, features │ │ │ │ │ - * will be transformed from the layer projection to the map projection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resp - {} The response object passed │ │ │ │ │ - * by the protocol. │ │ │ │ │ + * Method: removeText │ │ │ │ │ + * Function for removing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - merge: function(resp) { │ │ │ │ │ - this.layer.destroyFeatures(); │ │ │ │ │ - if (resp.success()) { │ │ │ │ │ - var features = resp.features; │ │ │ │ │ - if (features && features.length > 0) { │ │ │ │ │ - var remote = this.layer.projection; │ │ │ │ │ - var local = this.layer.map.getProjectionObject(); │ │ │ │ │ - if (!local.equals(remote)) { │ │ │ │ │ - var geom; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - geom = features[i].geometry; │ │ │ │ │ - if (geom) { │ │ │ │ │ - geom.transform(remote, local); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.layer.addFeatures(features); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ + removeText: function(featureId) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear all vectors from the renderer. │ │ │ │ │ + * virtual function. │ │ │ │ │ + */ │ │ │ │ │ + clear: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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 - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A feature id or undefined. │ │ │ │ │ + */ │ │ │ │ │ + getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: eraseFeatures │ │ │ │ │ + * This is called by the layer to erase features │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - this.response = null; │ │ │ │ │ - this.layer.events.triggerEvent("loadend", { │ │ │ │ │ - response: resp │ │ │ │ │ - }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.BBOX" │ │ │ │ │ + /** │ │ │ │ │ + * Method: eraseGeometry │ │ │ │ │ + * Remove a geometry from the renderer (by id). │ │ │ │ │ + * virtual function. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * featureId - {String} │ │ │ │ │ + */ │ │ │ │ │ + eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ + */ │ │ │ │ │ + moveRoot: function(renderer) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + getRenderLayerId: function() { │ │ │ │ │ + return this.container.id; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: applyDefaultSymbolizer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * symbolizer - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + 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.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/Strategy/Cluster.js │ │ │ │ │ + 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/Strategy.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy.Cluster │ │ │ │ │ - * Strategy for vector feature clustering. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Protocol │ │ │ │ │ + * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the protocol subclasses instead. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: distance │ │ │ │ │ - * {Integer} Pixel distance between features that should be considered a │ │ │ │ │ - * single cluster. Default is 20 pixels. │ │ │ │ │ - */ │ │ │ │ │ - distance: 20, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: threshold │ │ │ │ │ - * {Integer} Optional threshold below which original features will be │ │ │ │ │ - * added to the layer instead of clusters. For example, a threshold │ │ │ │ │ - * of 3 would mean that any time there are 2 or fewer features in │ │ │ │ │ - * a cluster, those features will be added directly to the layer instead │ │ │ │ │ - * of a cluster representing those features. Default is null (which is │ │ │ │ │ - * equivalent to 1 - meaning that clusters may contain just one feature). │ │ │ │ │ - */ │ │ │ │ │ - threshold: null, │ │ │ │ │ +OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: features │ │ │ │ │ - * {Array()} Cached features. │ │ │ │ │ + * Property: format │ │ │ │ │ + * {} The format used by this protocol. │ │ │ │ │ */ │ │ │ │ │ - features: null, │ │ │ │ │ + format: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: clusters │ │ │ │ │ - * {Array()} Calculated clusters. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ */ │ │ │ │ │ - clusters: null, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: clustering │ │ │ │ │ - * {Boolean} The strategy is currently clustering features. │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the protocol can set autoDestroy to false │ │ │ │ │ + * to fully control when the protocol is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - clustering: false, │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The resolution (map units per pixel) of the current cluster set. │ │ │ │ │ + * Property: defaultFilter │ │ │ │ │ + * {} Optional default filter to read requests │ │ │ │ │ */ │ │ │ │ │ - resolution: null, │ │ │ │ │ + defaultFilter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Cluster │ │ │ │ │ - * Create a new clustering strategy. │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully activated. │ │ │ │ │ + * Method: mergeWithDefaultFilter │ │ │ │ │ + * Merge filter passed to the read method with the default one │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "beforefeaturesadded": this.cacheFeatures, │ │ │ │ │ - "featuresremoved": this.clearCache, │ │ │ │ │ - "moveend": this.cluster, │ │ │ │ │ - scope: this │ │ │ │ │ + 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 activated; │ │ │ │ │ + return merged; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The strategy was successfully deactivated. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up the protocol. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - this.clearCache(); │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "beforefeaturesadded": this.cacheFeatures, │ │ │ │ │ - "featuresremoved": this.clearCache, │ │ │ │ │ - "moveend": this.cluster, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.options = null; │ │ │ │ │ + this.format = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cacheFeatures │ │ │ │ │ - * Cache features before they are added to the layer. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Construct a request for reading new features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The event that this was listening for. This will come │ │ │ │ │ - * with a batch of features to be clustered. │ │ │ │ │ - * │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} False to stop features from being added to the layer. │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - cacheFeatures: function(event) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - if (!this.clustering) { │ │ │ │ │ - this.clearCache(); │ │ │ │ │ - this.features = event.features; │ │ │ │ │ - this.cluster(); │ │ │ │ │ - propagate = false; │ │ │ │ │ - } │ │ │ │ │ - return propagate; │ │ │ │ │ + read: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.filter = this.mergeWithDefaultFilter(options.filter); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: clearCache │ │ │ │ │ - * Clear out the cached features. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - clearCache: function() { │ │ │ │ │ - if (!this.clustering) { │ │ │ │ │ - this.features = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + create: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cluster │ │ │ │ │ - * Cluster features based on some threshold distance. │ │ │ │ │ + * APIMethod: update │ │ │ │ │ + * Construct a request updating modified features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The event received when cluster is called as a │ │ │ │ │ - * result of a moveend event. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - cluster: function(event) { │ │ │ │ │ - if ((!event || event.zoomChanged) && this.features) { │ │ │ │ │ - var resolution = this.layer.map.getResolution(); │ │ │ │ │ - if (resolution != this.resolution || !this.clustersExist()) { │ │ │ │ │ - this.resolution = resolution; │ │ │ │ │ - var clusters = []; │ │ │ │ │ - var feature, clustered, cluster; │ │ │ │ │ - for (var i = 0; i < this.features.length; ++i) { │ │ │ │ │ - feature = this.features[i]; │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - clustered = false; │ │ │ │ │ - for (var j = clusters.length - 1; j >= 0; --j) { │ │ │ │ │ - cluster = clusters[j]; │ │ │ │ │ - if (this.shouldCluster(cluster, feature)) { │ │ │ │ │ - this.addToCluster(cluster, feature); │ │ │ │ │ - clustered = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!clustered) { │ │ │ │ │ - clusters.push(this.createCluster(this.features[i])); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.clustering = true; │ │ │ │ │ - this.layer.removeAllFeatures(); │ │ │ │ │ - this.clustering = false; │ │ │ │ │ - if (clusters.length > 0) { │ │ │ │ │ - if (this.threshold > 1) { │ │ │ │ │ - var clone = clusters.slice(); │ │ │ │ │ - clusters = []; │ │ │ │ │ - var candidate; │ │ │ │ │ - for (var i = 0, len = clone.length; i < len; ++i) { │ │ │ │ │ - candidate = clone[i]; │ │ │ │ │ - if (candidate.attributes.count < this.threshold) { │ │ │ │ │ - Array.prototype.push.apply(clusters, candidate.cluster); │ │ │ │ │ - } else { │ │ │ │ │ - clusters.push(candidate); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.clustering = true; │ │ │ │ │ - // A legitimate feature addition could occur during this │ │ │ │ │ - // addFeatures call. For clustering to behave well, features │ │ │ │ │ - // should be removed from a layer before requesting a new batch. │ │ │ │ │ - this.layer.addFeatures(clusters); │ │ │ │ │ - this.clustering = false; │ │ │ │ │ - } │ │ │ │ │ - this.clusters = clusters; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + update: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clustersExist │ │ │ │ │ - * Determine whether calculated clusters are already on the layer. │ │ │ │ │ + * APIMethod: delete │ │ │ │ │ + * Construct a request deleting a removed feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The calculated clusters are already on the layer. │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - clustersExist: function() { │ │ │ │ │ - var exist = false; │ │ │ │ │ - if (this.clusters && this.clusters.length > 0 && │ │ │ │ │ - this.clusters.length == this.layer.features.length) { │ │ │ │ │ - exist = true; │ │ │ │ │ - for (var i = 0; i < this.clusters.length; ++i) { │ │ │ │ │ - if (this.clusters[i] != this.layer.features[i]) { │ │ │ │ │ - exist = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return exist; │ │ │ │ │ - }, │ │ │ │ │ + "delete": function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shouldCluster │ │ │ │ │ - * Determine whether to include a feature in a given cluster. │ │ │ │ │ + * APIMethod: commit │ │ │ │ │ + * Go over the features and for each take action │ │ │ │ │ + * based on the feature state. Possible actions are create, │ │ │ │ │ + * update and delete. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * cluster - {} A cluster. │ │ │ │ │ - * feature - {} A feature. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The feature should be included in the cluster. │ │ │ │ │ + * {Array({})} An array of │ │ │ │ │ + * objects. │ │ │ │ │ */ │ │ │ │ │ - shouldCluster: function(cluster, feature) { │ │ │ │ │ - var cc = cluster.geometry.getBounds().getCenterLonLat(); │ │ │ │ │ - var fc = feature.geometry.getBounds().getCenterLonLat(); │ │ │ │ │ - var distance = ( │ │ │ │ │ - Math.sqrt( │ │ │ │ │ - Math.pow((cc.lon - fc.lon), 2) + Math.pow((cc.lat - fc.lat), 2) │ │ │ │ │ - ) / this.resolution │ │ │ │ │ - ); │ │ │ │ │ - return (distance <= this.distance); │ │ │ │ │ - }, │ │ │ │ │ + commit: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addToCluster │ │ │ │ │ - * Add a feature to a cluster. │ │ │ │ │ + * Method: abort │ │ │ │ │ + * Abort an ongoing request. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * cluster - {} A cluster. │ │ │ │ │ - * feature - {} A feature. │ │ │ │ │ + * response - {} │ │ │ │ │ */ │ │ │ │ │ - addToCluster: function(cluster, feature) { │ │ │ │ │ - cluster.cluster.push(feature); │ │ │ │ │ - cluster.attributes.count += 1; │ │ │ │ │ - }, │ │ │ │ │ + abort: function(response) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createCluster │ │ │ │ │ - * Given a feature, create a cluster. │ │ │ │ │ + * Method: createCallback │ │ │ │ │ + * Returns a function that applies the given public method with resp and │ │ │ │ │ + * options arguments. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A cluster. │ │ │ │ │ + * method - {Function} The method to be applied by the callback. │ │ │ │ │ + * response - {} The protocol response object. │ │ │ │ │ + * options - {Object} Options sent to the protocol method │ │ │ │ │ */ │ │ │ │ │ - createCluster: function(feature) { │ │ │ │ │ - var center = feature.geometry.getBounds().getCenterLonLat(); │ │ │ │ │ - var cluster = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(center.lon, center.lat), { │ │ │ │ │ - count: 1 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - cluster.cluster = [feature]; │ │ │ │ │ - return cluster; │ │ │ │ │ + createCallback: function(method, response, options) { │ │ │ │ │ + return OpenLayers.Function.bind(function() { │ │ │ │ │ + method.apply(this, [response, options]); │ │ │ │ │ + }, this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Cluster" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol" │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy/Refresh.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/Strategy.js │ │ │ │ │ - */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy.Refresh │ │ │ │ │ - * A strategy that refreshes the layer. By default the strategy waits for a │ │ │ │ │ - * call to before refreshing. By configuring the strategy with │ │ │ │ │ - * the option, refreshing can take place automatically. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Protocol.Response │ │ │ │ │ + * Protocols return Response objects to their users. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy.Refresh = OpenLayers.Class(OpenLayers.Strategy, { │ │ │ │ │ - │ │ │ │ │ +OpenLayers.Protocol.Response = OpenLayers.Class({ │ │ │ │ │ /** │ │ │ │ │ - * Property: force │ │ │ │ │ - * {Boolean} Force a refresh on the layer. Default is false. │ │ │ │ │ + * Property: code │ │ │ │ │ + * {Number} - OpenLayers.Protocol.Response.SUCCESS or │ │ │ │ │ + * OpenLayers.Protocol.Response.FAILURE │ │ │ │ │ */ │ │ │ │ │ - force: false, │ │ │ │ │ + code: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Number} Auto-refresh. Default is 0. If > 0, layer will be refreshed │ │ │ │ │ - * every N milliseconds. │ │ │ │ │ + * Property: requestType │ │ │ │ │ + * {String} The type of request this response corresponds to. Either │ │ │ │ │ + * "create", "read", "update" or "delete". │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + requestType: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timer │ │ │ │ │ - * {Number} The id of the timer. │ │ │ │ │ + * Property: last │ │ │ │ │ + * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ + * false otherwise, defaults to true. │ │ │ │ │ */ │ │ │ │ │ - timer: null, │ │ │ │ │ + last: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy.Refresh │ │ │ │ │ - * Create a new Refresh strategy. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully activated. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Strategy.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - if (this.layer.visibility === true) { │ │ │ │ │ - this.start(); │ │ │ │ │ - } │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - "visibilitychanged": this.reset, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ - * tear-down. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the strategy was successfully deactivated. │ │ │ │ │ + * Property: reqFeatures │ │ │ │ │ + * {Array({})} or {} │ │ │ │ │ + * The features provided by the user and placed in the request by the │ │ │ │ │ + * protocol. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - this.stop(); │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - "visibilitychanged": this.reset, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ + reqFeatures: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: reset │ │ │ │ │ - * Start or cancel the refresh interval depending on the visibility of │ │ │ │ │ - * the layer. │ │ │ │ │ + * Property: priv │ │ │ │ │ */ │ │ │ │ │ - reset: function() { │ │ │ │ │ - if (this.layer.visibility === true) { │ │ │ │ │ - this.start(); │ │ │ │ │ - } else { │ │ │ │ │ - this.stop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + priv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: start │ │ │ │ │ - * Start the refresh interval. │ │ │ │ │ + * Property: error │ │ │ │ │ + * {Object} The error object in case a service exception was encountered. │ │ │ │ │ */ │ │ │ │ │ - start: function() { │ │ │ │ │ - if (this.interval && typeof this.interval === "number" && │ │ │ │ │ - this.interval > 0) { │ │ │ │ │ - │ │ │ │ │ - this.timer = window.setInterval( │ │ │ │ │ - OpenLayers.Function.bind(this.refresh, this), │ │ │ │ │ - this.interval); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + error: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: refresh │ │ │ │ │ - * Tell the strategy to refresh which will refresh the layer. │ │ │ │ │ + * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ - refresh: function() { │ │ │ │ │ - if (this.layer && this.layer.refresh && │ │ │ │ │ - typeof this.layer.refresh == "function") { │ │ │ │ │ - │ │ │ │ │ - this.layer.refresh({ │ │ │ │ │ - force: this.force │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: stop │ │ │ │ │ - * Cancels the refresh interval. │ │ │ │ │ + * Method: success │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} - true on success, false otherwise │ │ │ │ │ */ │ │ │ │ │ - stop: function() { │ │ │ │ │ - if (this.timer !== null) { │ │ │ │ │ - window.clearInterval(this.timer); │ │ │ │ │ - this.timer = null; │ │ │ │ │ - } │ │ │ │ │ + success: function() { │ │ │ │ │ + return this.code > 0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy.Refresh" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol.Response" │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Button.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/Control.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Button │ │ │ │ │ - * The Button control is a very simple push-button, for use with │ │ │ │ │ - * . │ │ │ │ │ - * When clicked, the function trigger() is executed. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ - * Use: │ │ │ │ │ - * (code) │ │ │ │ │ - * var button = new OpenLayers.Control.Button({ │ │ │ │ │ - * displayClass: "MyButton", trigger: myFunction │ │ │ │ │ - * }); │ │ │ │ │ - * panel.addControls([button]); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Will create a button with CSS class MyButtonItemInactive, that │ │ │ │ │ - * will call the function MyFunction() when clicked. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Button = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {Integer} OpenLayers.Control.TYPE_BUTTON. │ │ │ │ │ - */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_BUTTON, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ - * Called by a control panel when the button is clicked. │ │ │ │ │ - */ │ │ │ │ │ - trigger: function() {}, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Button" │ │ │ │ │ -}); │ │ │ │ │ +OpenLayers.Protocol.Response.SUCCESS = 1; │ │ │ │ │ +OpenLayers.Protocol.Response.FAILURE = 0; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Click.js │ │ │ │ │ + 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/Handler.js │ │ │ │ │ + * @requires OpenLayers/Layer.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. │ │ │ │ │ + * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - dblclickTolerance: 13, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - stopSingle: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - stopDouble: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ - */ │ │ │ │ │ - timerId: null, │ │ │ │ │ +OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - down: null, │ │ │ │ │ + URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ + * a single url string. │ │ │ │ │ */ │ │ │ │ │ - last: null, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: first │ │ │ │ │ - * {Object} When waiting for double clicks, this object will store │ │ │ │ │ - * information about the first click in a two click sequence. │ │ │ │ │ + * Property: params │ │ │ │ │ + * {Object} Hashtable of key/value parameters │ │ │ │ │ */ │ │ │ │ │ - first: null, │ │ │ │ │ + params: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: rightclickTimerId │ │ │ │ │ - * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ - * . │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - rightclickTimerId: null, │ │ │ │ │ + reproject: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Click │ │ │ │ │ - * Create a new click handler. │ │ │ │ │ + * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Store position of last move, because touchend event can have │ │ │ │ │ - * an empty "touches" property. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ - * touches property from last touchstart or touchmove │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {Array(String) or String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.url = null; │ │ │ │ │ + this.params = null; │ │ │ │ │ + OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.HTTPRequest(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - return propagate; │ │ │ │ │ - }, │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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]); │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ │ │ │ │ │ - var delayedRightCall = OpenLayers.Function.bind( │ │ │ │ │ - this.delayedRightCall, │ │ │ │ │ - this, │ │ │ │ │ - clickEvent │ │ │ │ │ - ); │ │ │ │ │ - this.rightclickTimerId = window.setTimeout( │ │ │ │ │ - delayedRightCall, this.delay │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: delayedRightCall │ │ │ │ │ - * Sets to null. And optionally triggers the │ │ │ │ │ - * rightclick callback if evt is set. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setUrl │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newUrl - {String} │ │ │ │ │ */ │ │ │ │ │ - delayedRightCall: function(evt) { │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback('rightclick', [evt]); │ │ │ │ │ - } │ │ │ │ │ + setUrl: function(newUrl) { │ │ │ │ │ + this.url = newUrl; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - if (!this.last) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ + 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" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - this.handleSingle(evt); │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ + return ret; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - this.handleDouble(evt); │ │ │ │ │ - return !this.stopDouble; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleDouble │ │ │ │ │ - * Handle double-click sequence. │ │ │ │ │ - */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleSingle │ │ │ │ │ - * Handle single click sequence. │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + redraw: function(force) { │ │ │ │ │ + if (force) { │ │ │ │ │ + return this.mergeNewParams({ │ │ │ │ │ + "_olSalt": Math.random() │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * 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). │ │ │ │ │ + * 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: │ │ │ │ │ + * paramString - {String} │ │ │ │ │ + * urls - {Array(String)} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The click is within the pixel tolerance (if specified). │ │ │ │ │ + * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ + * on the paramString. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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 passes; │ │ │ │ │ + return urls[Math.floor(product * urls.length)]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTouchDistance │ │ │ │ │ + * 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 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. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The click is within the double-click pixel tolerance. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - passesDblclickTolerance: function(evt) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.down && this.first) { │ │ │ │ │ - passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ - } │ │ │ │ │ - return passes; │ │ │ │ │ - }, │ │ │ │ │ + getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ - */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.rightclickTimerId != null) { │ │ │ │ │ - window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + // if not altUrl passed in, use layer's url │ │ │ │ │ + var url = altUrl || this.url; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Sets to null. And optionally triggers the click callback if │ │ │ │ │ - * evt is set. │ │ │ │ │ - */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback("click", [evt]); │ │ │ │ │ + // 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); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with event related info. │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + // 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 { │ │ │ │ │ - xy: evt.xy, │ │ │ │ │ - touches: touches │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ + paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ + return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.HTTPRequest" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Hover.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.js │ │ │ │ │ + * @requires OpenLayers/Tile.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * 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.Hover = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: delay │ │ │ │ │ - * {Integer} - Number of milliseconds between mousemoves before │ │ │ │ │ - * the event is considered a hover. Default is 500. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - delay: 500, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ - * an event to be considered a hover. 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. │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: null, │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: imgDiv │ │ │ │ │ + * {HTMLImageElement} The image for this tile. │ │ │ │ │ + */ │ │ │ │ │ + imgDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopMove │ │ │ │ │ - * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - stopMove: false, │ │ │ │ │ + frame: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: imageReloadAttempts │ │ │ │ │ + * {Integer} Attempts to load the image. │ │ │ │ │ + */ │ │ │ │ │ + imageReloadAttempts: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {} - The location of the last mousemove, expressed │ │ │ │ │ - * in pixels. │ │ │ │ │ + * Property: layerAlphaHack │ │ │ │ │ + * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ */ │ │ │ │ │ - px: null, │ │ │ │ │ + layerAlphaHack: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} - The id of the timer. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + asyncRequestId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ - * Construct a hover 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. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: mousemove │ │ │ │ │ - * Called when the mouse moves on the map. │ │ │ │ │ - * │ │ │ │ │ + * Property: canvasContext │ │ │ │ │ + * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ + * the tile image. │ │ │ │ │ + */ │ │ │ │ │ + canvasContext: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + crossOriginKeyword: null, │ │ │ │ │ + │ │ │ │ │ + /** 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. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile.Image │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * layer - {} layer that the tile will go in. │ │ │ │ │ + * position - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ + * size - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return !this.stopMove; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Called when the mouse goes out of the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('move', [evt]); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.imgDiv) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + this.frame = null; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + // don't handle async requests any more │ │ │ │ │ + this.asyncRequestId = null; │ │ │ │ │ + OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Check that a tile should be drawn, and draw it. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ + * {Boolean} Was a tile drawn? Or null if a beforedraw listener returned │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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 passes; │ │ │ │ │ + return shouldDraw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: renderTile │ │ │ │ │ + * Internal function to actually initialize the image tile, │ │ │ │ │ + * position it correctly, and set its url. │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ + 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: delayedCall │ │ │ │ │ - * Triggers pause callback. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.callback('pause', [evt]); │ │ │ │ │ + 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"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - deactivated = 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"); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + this.canvasContext = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Hover" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WMSGetFeatureInfo.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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ - * Class to read GetFeatureInfo responses from Web Mapping Services │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerIdentifier │ │ │ │ │ - * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ - * internal array of layer nodes. │ │ │ │ │ + * Method: getImage │ │ │ │ │ + * Returns or creates and returns the tile image. │ │ │ │ │ */ │ │ │ │ │ - layerIdentifier: '_layer', │ │ │ │ │ + getImage: function() { │ │ │ │ │ + if (!this.imgDiv) { │ │ │ │ │ + this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: featureIdentifier │ │ │ │ │ - * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ - * internal array of feature nodes for each layer node found. │ │ │ │ │ - */ │ │ │ │ │ - featureIdentifier: '_feature', │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ - */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ + return this.imgDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: gmlFormat │ │ │ │ │ - * {} internal GML format for parsing geometries │ │ │ │ │ - * in msGMLOutput │ │ │ │ │ - */ │ │ │ │ │ - gmlFormat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ - * Create a new parser for WMS GetFeatureInfo responses │ │ │ │ │ + * APIMethod: setImage │ │ │ │ │ + * Sets the image element for this tile. This method should only be called │ │ │ │ │ + * from beforeload listeners. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * Parameters │ │ │ │ │ + * img - {HTMLImageElement} The image to use for this tile. │ │ │ │ │ */ │ │ │ │ │ + setImage: function(img) { │ │ │ │ │ + this.imgDiv = img; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read WMS GetFeatureInfo data from a string, and return an array of features │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} An array of features. │ │ │ │ │ + * Method: initImage │ │ │ │ │ + * Creates the content for the frame on the tile. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - var result; │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + initImage: function() { │ │ │ │ │ + if (!this.url && !this.imgDiv) { │ │ │ │ │ + // fast path out - if there is no tile url and no previous image │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - var root = data.documentElement; │ │ │ │ │ - if (root) { │ │ │ │ │ - var scope = this; │ │ │ │ │ - var read = this["read_" + root.nodeName]; │ │ │ │ │ - if (read) { │ │ │ │ │ - result = read.call(this, root); │ │ │ │ │ - } else { │ │ │ │ │ - // fall-back to GML since this is a common output format for WMS │ │ │ │ │ - // GetFeatureInfo responses │ │ │ │ │ - result = new OpenLayers.Format.GML((this.options ? this.options : {})).read(data); │ │ │ │ │ - } │ │ │ │ │ + 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 { │ │ │ │ │ - result = data; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: read_msGMLOutput │ │ │ │ │ - * Parse msGMLOutput nodes. │ │ │ │ │ + * Method: setImgSrc │ │ │ │ │ + * Sets the source for the tile image │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {DOMElement} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} │ │ │ │ │ + * url - {String} or undefined to hide the image │ │ │ │ │ */ │ │ │ │ │ - read_msGMLOutput: function(data) { │ │ │ │ │ - var response = []; │ │ │ │ │ - var layerNodes = this.getSiblingNodesByTagCriteria(data, │ │ │ │ │ - this.layerIdentifier); │ │ │ │ │ - if (layerNodes) { │ │ │ │ │ - for (var i = 0, len = layerNodes.length; i < len; ++i) { │ │ │ │ │ - var node = layerNodes[i]; │ │ │ │ │ - var layerName = node.nodeName; │ │ │ │ │ - if (node.prefix) { │ │ │ │ │ - layerName = layerName.split(':')[1]; │ │ │ │ │ - } │ │ │ │ │ - var layerName = layerName.replace(this.layerIdentifier, ''); │ │ │ │ │ - var featureNodes = this.getSiblingNodesByTagCriteria(node, │ │ │ │ │ - this.featureIdentifier); │ │ │ │ │ - if (featureNodes) { │ │ │ │ │ - for (var j = 0; j < featureNodes.length; j++) { │ │ │ │ │ - var featureNode = featureNodes[j]; │ │ │ │ │ - var geomInfo = this.parseGeometry(featureNode); │ │ │ │ │ - var attributes = this.parseAttributes(featureNode); │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector(geomInfo.geometry, │ │ │ │ │ - attributes, null); │ │ │ │ │ - feature.bounds = geomInfo.bounds; │ │ │ │ │ - feature.type = layerName; │ │ │ │ │ - response.push(feature); │ │ │ │ │ - } │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read_FeatureInfoResponse │ │ │ │ │ - * Parse FeatureInfoResponse nodes. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {DOMElement} │ │ │ │ │ + * Method: getTile │ │ │ │ │ + * Get the tile's markup. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} │ │ │ │ │ + * {DOMElement} The tile's markup │ │ │ │ │ */ │ │ │ │ │ - read_FeatureInfoResponse: function(data) { │ │ │ │ │ - var response = []; │ │ │ │ │ - var featureNodes = this.getElementsByTagNameNS(data, '*', │ │ │ │ │ - 'FIELDS'); │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = featureNodes.length; i < len; i++) { │ │ │ │ │ - var featureNode = featureNodes[i]; │ │ │ │ │ - var geom = null; │ │ │ │ │ - │ │ │ │ │ - // attributes can be actual attributes on the FIELDS tag, │ │ │ │ │ - // or FIELD children │ │ │ │ │ - var attributes = {}; │ │ │ │ │ - var j; │ │ │ │ │ - var jlen = featureNode.attributes.length; │ │ │ │ │ - if (jlen > 0) { │ │ │ │ │ - for (j = 0; j < jlen; j++) { │ │ │ │ │ - var attribute = featureNode.attributes[j]; │ │ │ │ │ - attributes[attribute.nodeName] = attribute.nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - var nodes = featureNode.childNodes; │ │ │ │ │ - for (j = 0, jlen = nodes.length; j < jlen; ++j) { │ │ │ │ │ - var node = nodes[j]; │ │ │ │ │ - if (node.nodeType != 3) { │ │ │ │ │ - attributes[node.getAttribute("name")] = │ │ │ │ │ - node.getAttribute("value"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - response.push( │ │ │ │ │ - new OpenLayers.Feature.Vector(geom, attributes, null) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return response; │ │ │ │ │ + getTile: function() { │ │ │ │ │ + return this.frame ? this.frame : this.getImage(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSiblingNodesByTagCriteria │ │ │ │ │ - * Recursively searches passed xml node and all it's descendant levels for │ │ │ │ │ - * nodes whose tagName contains the passed search string. This returns an │ │ │ │ │ - * array of all sibling nodes which match the criteria from the highest │ │ │ │ │ - * hierarchial level from which a match is found. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {DOMElement} An xml node │ │ │ │ │ - * criteria - {String} Search string which will match some part of a tagName │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * Array({DOMElement}) An array of sibling xml nodes │ │ │ │ │ + * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ + * or if it's currently loading. │ │ │ │ │ */ │ │ │ │ │ - getSiblingNodesByTagCriteria: function(node, criteria) { │ │ │ │ │ - var nodes = []; │ │ │ │ │ - var children, tagName, n, matchNodes, child; │ │ │ │ │ - if (node && node.hasChildNodes()) { │ │ │ │ │ - children = node.childNodes; │ │ │ │ │ - n = children.length; │ │ │ │ │ - │ │ │ │ │ - for (var k = 0; k < n; k++) { │ │ │ │ │ - child = children[k]; │ │ │ │ │ - while (child && child.nodeType != 1) { │ │ │ │ │ - child = child.nextSibling; │ │ │ │ │ - k++; │ │ │ │ │ - } │ │ │ │ │ - tagName = (child ? child.nodeName : ''); │ │ │ │ │ - if (tagName.length > 0 && tagName.indexOf(criteria) > -1) { │ │ │ │ │ - nodes.push(child); │ │ │ │ │ - } else { │ │ │ │ │ - matchNodes = this.getSiblingNodesByTagCriteria( │ │ │ │ │ - child, criteria); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + return backBuffer; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (matchNodes.length > 0) { │ │ │ │ │ - (nodes.length == 0) ? │ │ │ │ │ - nodes = matchNodes: nodes.push(matchNodes); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: onImageLoad │ │ │ │ │ + * Handler for the image onload event │ │ │ │ │ + */ │ │ │ │ │ + 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')"; │ │ │ │ │ } │ │ │ │ │ - return nodes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseAttributes │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An attributes object. │ │ │ │ │ - * │ │ │ │ │ - * Notes: │ │ │ │ │ - * Assumes that attributes are direct child xml nodes of the passed node │ │ │ │ │ - * and contain only a single text node. │ │ │ │ │ + * Method: onImageError │ │ │ │ │ + * Handler for the image onerror event │ │ │ │ │ */ │ │ │ │ │ - parseAttributes: function(node) { │ │ │ │ │ - var attributes = {}; │ │ │ │ │ - if (node.nodeType == 1) { │ │ │ │ │ - var children = node.childNodes; │ │ │ │ │ - var n = children.length; │ │ │ │ │ - for (var i = 0; i < n; ++i) { │ │ │ │ │ - var child = children[i]; │ │ │ │ │ - if (child.nodeType == 1) { │ │ │ │ │ - var grandchildren = child.childNodes; │ │ │ │ │ - var name = (child.prefix) ? │ │ │ │ │ - child.nodeName.split(":")[1] : child.nodeName; │ │ │ │ │ - if (grandchildren.length == 0) { │ │ │ │ │ - attributes[name] = null; │ │ │ │ │ - } else if (grandchildren.length == 1) { │ │ │ │ │ - var grandchild = grandchildren[0]; │ │ │ │ │ - if (grandchild.nodeType == 3 || │ │ │ │ │ - grandchild.nodeType == 4) { │ │ │ │ │ - var value = grandchild.nodeValue.replace( │ │ │ │ │ - this.regExes.trimSpace, ""); │ │ │ │ │ - attributes[name] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return attributes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseGeometry │ │ │ │ │ - * Parse the geometry and the feature bounds out of the node using │ │ │ │ │ - * Format.GML │ │ │ │ │ + * Method: stopLoading │ │ │ │ │ + * Stops a loading sequence so won't be executed. │ │ │ │ │ + */ │ │ │ │ │ + stopLoading: function() { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ + window.clearTimeout(this._loadTimeout); │ │ │ │ │ + delete this._loadTimeout; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} │ │ │ │ │ + * 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: │ │ │ │ │ - * {Object} An object containing the geometry and the feature bounds │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - parseGeometry: function(node) { │ │ │ │ │ - // we need to use the old Format.GML parser since we do not know the │ │ │ │ │ - // geometry name │ │ │ │ │ - if (!this.gmlFormat) { │ │ │ │ │ - this.gmlFormat = new OpenLayers.Format.GML(); │ │ │ │ │ - } │ │ │ │ │ - var feature = this.gmlFormat.parseFeature(node); │ │ │ │ │ - var geometry, bounds = null; │ │ │ │ │ - if (feature) { │ │ │ │ │ - geometry = feature.geometry && feature.geometry.clone(); │ │ │ │ │ - bounds = feature.bounds && feature.bounds.clone(); │ │ │ │ │ - feature.destroy(); │ │ │ │ │ + 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 { │ │ │ │ │ - geometry: geometry, │ │ │ │ │ - bounds: bounds │ │ │ │ │ - }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" │ │ │ │ │ + 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/Control/WMSGetFeatureInfo.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ + * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ + * @requires OpenLayers/Tile/Image.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.WMSGetFeatureInfo │ │ │ │ │ - * The WMSGetFeatureInfo control uses a WMS query to get information about a point on the map. The │ │ │ │ │ - * information may be in a display-friendly format such as HTML, or a machine-friendly format such │ │ │ │ │ - * as GML, depending on the server's capabilities and the client's configuration. This control │ │ │ │ │ - * handles click or hover events, attempts to parse the results using an OpenLayers.Format, and │ │ │ │ │ - * fires a 'getfeatureinfo' event with the click position, the raw body of the response, and an │ │ │ │ │ - * array of features if it successfully read the response. │ │ │ │ │ + * 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.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: tileSize │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + tileSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: drillDown │ │ │ │ │ - * {Boolean} Drill down over all WMS layers in the map. When │ │ │ │ │ - * using drillDown mode, hover is not possible, and an infoFormat that │ │ │ │ │ - * returns parseable features is required. Default is false. │ │ │ │ │ + * 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". │ │ │ │ │ */ │ │ │ │ │ - drillDown: false, │ │ │ │ │ + tileOriginCorner: "bl", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a WMS query. This │ │ │ │ │ - * sets the feature_count parameter on WMS GetFeatureInfo │ │ │ │ │ - * requests. │ │ │ │ │ + * 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``. │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ + tileOrigin: null, │ │ │ │ │ + │ │ │ │ │ + /** APIProperty: tileOptions │ │ │ │ │ + * {Object} optional configuration options for instances │ │ │ │ │ + * created by this Layer, if supported by the tile class. │ │ │ │ │ + */ │ │ │ │ │ + tileOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickCallback │ │ │ │ │ - * {String} The click callback to register in the │ │ │ │ │ - * {} object created when the hover │ │ │ │ │ - * option is set to false. Default is "click". │ │ │ │ │ + * APIProperty: tileClass │ │ │ │ │ + * {} The tile class to use for this layer. │ │ │ │ │ + * Defaults is OpenLayers.Tile.Image. │ │ │ │ │ */ │ │ │ │ │ - clickCallback: "click", │ │ │ │ │ + tileClass: OpenLayers.Tile.Image, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: output │ │ │ │ │ - * {String} Either "features" or "object". When triggering a getfeatureinfo │ │ │ │ │ - * request should we pass on an array of features or an object with with │ │ │ │ │ - * a "features" property and other properties (such as the url of the │ │ │ │ │ - * WMS). Default is "features". │ │ │ │ │ + * Property: grid │ │ │ │ │ + * {Array(Array())} This is an array of rows, each row is │ │ │ │ │ + * an array of tiles. │ │ │ │ │ */ │ │ │ │ │ - output: "features", │ │ │ │ │ + grid: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} The layers to query for feature info. │ │ │ │ │ - * If omitted, all map WMS layers with a url that matches this or │ │ │ │ │ - * will be considered. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + 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: queryVisible │ │ │ │ │ - * {Boolean} If true, filter out hidden layers when searching the map for │ │ │ │ │ - * layers to query. Default is false. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - queryVisible: false, │ │ │ │ │ + buffer: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} The URL of the WMS service to use. If not provided, the url │ │ │ │ │ - * of the first eligible layer will be used. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + transitionEffect: "resize", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerUrls │ │ │ │ │ - * {Array(String)} Optional list of urls for layers that should be queried. │ │ │ │ │ - * This can be used when the layer url differs from the url used for │ │ │ │ │ - * making GetFeatureInfo requests (in the case of a layer using cached │ │ │ │ │ - * tiles). │ │ │ │ │ + * APIProperty: numLoadingTiles │ │ │ │ │ + * {Integer} How many tiles are still loading? │ │ │ │ │ */ │ │ │ │ │ - layerUrls: null, │ │ │ │ │ + numLoadingTiles: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: infoFormat │ │ │ │ │ - * {String} The mimetype to request from the server. If you are using │ │ │ │ │ - * drillDown mode and have multiple servers that do not share a common │ │ │ │ │ - * infoFormat, you can override the control's infoFormat by providing an │ │ │ │ │ - * INFO_FORMAT parameter in your instance(s). │ │ │ │ │ + * Property: serverResolutions │ │ │ │ │ + * {Array(Number}} This property is documented in subclasses as │ │ │ │ │ + * an API property. │ │ │ │ │ */ │ │ │ │ │ - infoFormat: 'text/html', │ │ │ │ │ + serverResolutions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: vendorParams │ │ │ │ │ - * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ - * WMS implementations that support them. This could e.g. look like │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * radius: 5 │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Property: loading │ │ │ │ │ + * {Boolean} Indicates if tiles are being loaded. │ │ │ │ │ */ │ │ │ │ │ - vendorParams: {}, │ │ │ │ │ + loading: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ - * Default is . │ │ │ │ │ + * Property: backBuffer │ │ │ │ │ + * {DOMElement} The back buffer. │ │ │ │ │ */ │ │ │ │ │ - format: null, │ │ │ │ │ + backBuffer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: formatOptions │ │ │ │ │ - * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ - * in the property. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - formatOptions: null, │ │ │ │ │ + gridResolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * "click": {delay: 100}, │ │ │ │ │ - * "hover": {delay: 300} │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Property: backBufferResolution │ │ │ │ │ + * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ + * updated each time a back buffer is created. │ │ │ │ │ */ │ │ │ │ │ + backBufferResolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {Object} Reference to the for this control │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + backBufferLonLat: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverRequest │ │ │ │ │ - * {} contains the currently running hover request │ │ │ │ │ - * (if any). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - hoverRequest: null, │ │ │ │ │ + backBufferTimerId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ + * 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: 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. │ │ │ │ │ + */ │ │ │ │ │ + className: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ * Register a listener for a particular event with the following syntax: │ │ │ │ │ * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ * (end) │ │ │ │ │ * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforegetfeatureinfo - Triggered before the request is sent. │ │ │ │ │ - * The event object has an *xy* property with the position of the │ │ │ │ │ - * mouse click or hover event that triggers the request. │ │ │ │ │ - * nogetfeatureinfo - no queryable layers were found. │ │ │ │ │ - * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ - * The event object has a *text* property with the body of the │ │ │ │ │ - * response (String), a *features* property with an array of the │ │ │ │ │ - * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ - * click or hover event that triggered the request, and a *request* │ │ │ │ │ - * property with the request itself. If drillDown is set to true and │ │ │ │ │ - * multiple requests were issued to collect feature info from all │ │ │ │ │ - * layers, *text* and *request* will only contain the response body │ │ │ │ │ - * and request object of the last request. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: │ │ │ │ │ + * Property: gridLayout │ │ │ │ │ + * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ + * startrow │ │ │ │ │ + */ │ │ │ │ │ + gridLayout: 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. │ │ │ │ │ + */ │ │ │ │ │ + rowSign: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: transitionendEvents │ │ │ │ │ + * {Array} Event names for transitionend │ │ │ │ │ + */ │ │ │ │ │ + transitionendEvents: [ │ │ │ │ │ + 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ + 'oTransitionEnd' │ │ │ │ │ + ], │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Layer.Grid │ │ │ │ │ + * Create a new grid layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + this.grid = []; │ │ │ │ │ + this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.initProperties(); │ │ │ │ │ │ │ │ │ │ - if (!this.format) { │ │ │ │ │ - this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ - options.formatOptions │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.drillDown === true) { │ │ │ │ │ - this.hover = false; │ │ │ │ │ + /** │ │ │ │ │ + * Method: initProperties │ │ │ │ │ + * Set any properties that depend on the value of singleTile. │ │ │ │ │ + * Currently sets removeBackBufferDelay and className │ │ │ │ │ + */ │ │ │ │ │ + initProperties: function() { │ │ │ │ │ + if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ + this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'move': this.cancelHover, │ │ │ │ │ - 'pause': this.getInfoForHover │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.hover || {}, { │ │ │ │ │ - 'delay': 250 │ │ │ │ │ - })); │ │ │ │ │ - } else { │ │ │ │ │ - var callbacks = {}; │ │ │ │ │ - callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, callbacks, this.handlerOptions.click || {}); │ │ │ │ │ + if (this.options.className === undefined) { │ │ │ │ │ + this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ + 'olLayerGrid'; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForClick │ │ │ │ │ - * Called on click │ │ │ │ │ + * Method: setMap │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * map - {} The map. │ │ │ │ │ */ │ │ │ │ │ - getInfoForClick: function(evt) { │ │ │ │ │ - this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: evt.xy │ │ │ │ │ - }); │ │ │ │ │ - // Set the cursor to "wait" to tell the user we're working on their │ │ │ │ │ - // click. │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.request(evt.xy, {}); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForHover │ │ │ │ │ - * Pause callback for the hover handler │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Called when the layer is removed from the map. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - getInfoForHover: function(evt) { │ │ │ │ │ - this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: evt.xy │ │ │ │ │ - }); │ │ │ │ │ - this.request(evt.xy, { │ │ │ │ │ - hover: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: cancelHover │ │ │ │ │ - * Cancel callback for the hover handler │ │ │ │ │ + * map - {} The map. │ │ │ │ │ */ │ │ │ │ │ - cancelHover: function() { │ │ │ │ │ - if (this.hoverRequest) { │ │ │ │ │ - this.hoverRequest.abort(); │ │ │ │ │ - this.hoverRequest = null; │ │ │ │ │ - } │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Deconstruct the layer and clear the grid. │ │ │ │ │ */ │ │ │ │ │ - findLayers: function() { │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ │ │ │ │ │ - var candidates = this.layers || this.map.layers; │ │ │ │ │ - var layers = []; │ │ │ │ │ - var layer, url; │ │ │ │ │ - for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = candidates[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.WMS && │ │ │ │ │ - (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ - url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ - // if the control was not configured with a url, set it │ │ │ │ │ - // to the first layer url │ │ │ │ │ - if (this.drillDown === false && !this.url) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - } │ │ │ │ │ - if (this.drillDown === true || this.urlMatches(url)) { │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return layers; │ │ │ │ │ + this.grid = null; │ │ │ │ │ + this.tileSize = null; │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: urlMatches │ │ │ │ │ - * Test to see if the provided url matches either the control or one │ │ │ │ │ - * of the . │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * url - {String} The url to test. │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The provided url matches the control or one of the │ │ │ │ │ - * . │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - urlMatches: function(url) { │ │ │ │ │ - var matches = OpenLayers.Util.isEquivalentUrl(this.url, url); │ │ │ │ │ - if (!matches && this.layerUrls) { │ │ │ │ │ - for (var i = 0, len = this.layerUrls.length; i < len; ++i) { │ │ │ │ │ - if (OpenLayers.Util.isEquivalentUrl(this.layerUrls[i], url)) { │ │ │ │ │ - matches = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return matches; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildWMSOptions │ │ │ │ │ - * Build an object with the relevant WMS options for the GetFeatureInfo request │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} The url to be used for sending the request │ │ │ │ │ - * layers - {Array(} The position on the map where the mouse │ │ │ │ │ - * event occurred. │ │ │ │ │ - * format - {String} The format from the corresponding GetMap request │ │ │ │ │ + * Method: clearGrid │ │ │ │ │ + * Go through and remove all tiles from the grid, calling │ │ │ │ │ + * destroy() on each of them to kill circular references │ │ │ │ │ */ │ │ │ │ │ - buildWMSOptions: function(url, layers, clickPosition, format) { │ │ │ │ │ - var layerNames = [], │ │ │ │ │ - styleNames = []; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - if (layers[i].params.LAYERS != null) { │ │ │ │ │ - layerNames = layerNames.concat(layers[i].params.LAYERS); │ │ │ │ │ - styleNames = styleNames.concat(this.getStyleNames(layers[i])); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - var firstLayer = layers[0]; │ │ │ │ │ - // use the firstLayer's projection if it matches the map projection - │ │ │ │ │ - // this assumes that all layers will be available in this projection │ │ │ │ │ - var projection = this.map.getProjection(); │ │ │ │ │ - var layerProj = firstLayer.projection; │ │ │ │ │ - if (layerProj && layerProj.equals(this.map.getProjectionObject())) { │ │ │ │ │ - projection = layerProj.getCode(); │ │ │ │ │ - } │ │ │ │ │ - var params = OpenLayers.Util.extend({ │ │ │ │ │ - service: "WMS", │ │ │ │ │ - version: firstLayer.params.VERSION, │ │ │ │ │ - request: "GetFeatureInfo", │ │ │ │ │ - exceptions: firstLayer.params.EXCEPTIONS, │ │ │ │ │ - bbox: this.map.getExtent().toBBOX(null, │ │ │ │ │ - firstLayer.reverseAxisOrder()), │ │ │ │ │ - feature_count: this.maxFeatures, │ │ │ │ │ - height: this.map.getSize().h, │ │ │ │ │ - width: this.map.getSize().w, │ │ │ │ │ - format: format, │ │ │ │ │ - info_format: firstLayer.params.INFO_FORMAT || this.infoFormat │ │ │ │ │ - }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ? { │ │ │ │ │ - crs: projection, │ │ │ │ │ - i: parseInt(clickPosition.x), │ │ │ │ │ - j: parseInt(clickPosition.y) │ │ │ │ │ - } : { │ │ │ │ │ - srs: projection, │ │ │ │ │ - x: parseInt(clickPosition.x), │ │ │ │ │ - y: parseInt(clickPosition.y) │ │ │ │ │ - }); │ │ │ │ │ - if (layerNames.length != 0) { │ │ │ │ │ - params = OpenLayers.Util.extend({ │ │ │ │ │ - layers: layerNames, │ │ │ │ │ - query_layers: layerNames, │ │ │ │ │ - styles: styleNames │ │ │ │ │ - }, params); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ - return { │ │ │ │ │ - url: url, │ │ │ │ │ - params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - this.handleResponse(clickPosition, request, url); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getStyleNames │ │ │ │ │ - * Gets the STYLES parameter for the layer. Make sure the STYLES parameter │ │ │ │ │ - * matches the LAYERS parameter │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array(String)} The STYLES parameter │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getStyleNames: function(layer) { │ │ │ │ │ - // in the event of a WMS layer bundling multiple layers but not │ │ │ │ │ - // specifying styles,we need the same number of commas to specify │ │ │ │ │ - // the default style for each of the layers. We can't just leave it │ │ │ │ │ - // blank as we may be including other layers that do specify styles. │ │ │ │ │ - var styleNames; │ │ │ │ │ - if (layer.params.STYLES) { │ │ │ │ │ - styleNames = layer.params.STYLES; │ │ │ │ │ - } else { │ │ │ │ │ - if (OpenLayers.Util.isArray(layer.params.LAYERS)) { │ │ │ │ │ - styleNames = new Array(layer.params.LAYERS.length); │ │ │ │ │ - } else { // Assume it's a String │ │ │ │ │ - styleNames = layer.params.LAYERS.replace(/[^,]/g, ""); │ │ │ │ │ - } │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return styleNames; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeatureInfo request to the WMS │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a clone of this layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * clickPosition - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ + * obj - {Object} Is this ever used? │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ */ │ │ │ │ │ - request: function(clickPosition, options) { │ │ │ │ │ - var layers = this.findLayers(); │ │ │ │ │ - if (layers.length == 0) { │ │ │ │ │ - this.events.triggerEvent("nogetfeatureinfo"); │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - return; │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - options = options || {}; │ │ │ │ │ - if (this.drillDown === false) { │ │ │ │ │ - var wmsOptions = this.buildWMSOptions(this.url, layers, │ │ │ │ │ - clickPosition, layers[0].params.FORMAT); │ │ │ │ │ - var request = OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); │ │ │ │ │ │ │ │ │ │ - if (options.hover === true) { │ │ │ │ │ - this.hoverRequest = request; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this._requestCount = 0; │ │ │ │ │ - this._numRequests = 0; │ │ │ │ │ - this.features = []; │ │ │ │ │ - // group according to service url to combine requests │ │ │ │ │ - var services = {}, │ │ │ │ │ - url; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - var layer = layers[i]; │ │ │ │ │ - var service, found = false; │ │ │ │ │ - url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ - if (url in services) { │ │ │ │ │ - services[url].push(layer); │ │ │ │ │ - } else { │ │ │ │ │ - this._numRequests++; │ │ │ │ │ - services[url] = [layer]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var layers; │ │ │ │ │ - for (var url in services) { │ │ │ │ │ - layers = services[url]; │ │ │ │ │ - var wmsOptions = this.buildWMSOptions(url, layers, │ │ │ │ │ - clickPosition, layers[0].params.FORMAT); │ │ │ │ │ - OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ - } │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + if (this.tileSize != null) { │ │ │ │ │ + obj.tileSize = this.tileSize.clone(); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: triggerGetFeatureInfo │ │ │ │ │ - * Trigger the getfeatureinfo event when all is done │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * request - {XMLHttpRequest} The request object │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * features - {Array()} or │ │ │ │ │ - * {Array({Object}) when output is "object". The object has a url and a │ │ │ │ │ - * features property which contains an array of features. │ │ │ │ │ - */ │ │ │ │ │ - triggerGetFeatureInfo: function(request, xy, features) { │ │ │ │ │ - this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ - text: request.responseText, │ │ │ │ │ - features: features, │ │ │ │ │ - request: request, │ │ │ │ │ - xy: xy │ │ │ │ │ - }); │ │ │ │ │ + // 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; │ │ │ │ │ │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleResponse │ │ │ │ │ - * Handler for the GetFeatureInfo response. │ │ │ │ │ + * 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: │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * request - {XMLHttpRequest} The request object. │ │ │ │ │ - * url - {String} The url which was used for this request. │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - handleResponse: function(xy, request, url) { │ │ │ │ │ - │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ - } │ │ │ │ │ - var features = this.format.read(doc); │ │ │ │ │ - if (this.drillDown === false) { │ │ │ │ │ - this.triggerGetFeatureInfo(request, xy, features); │ │ │ │ │ - } else { │ │ │ │ │ - this._requestCount++; │ │ │ │ │ - if (this.output === "object") { │ │ │ │ │ - this._features = (this._features || []).concat({ │ │ │ │ │ - url: url, │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - this._features = (this._features || []).concat(features); │ │ │ │ │ - } │ │ │ │ │ - if (this._requestCount === this._numRequests) { │ │ │ │ │ - this.triggerGetFeatureInfo(request, xy, this._features.concat()); │ │ │ │ │ - delete this._features; │ │ │ │ │ - delete this._requestCount; │ │ │ │ │ - delete this._numRequests; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Drag.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ + bounds = bounds || this.map.getExtent(); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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, { │ │ │ │ │ + if (bounds != null) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + // if grid is empty or zoom has changed, we *must* re-tile │ │ │ │ │ + var forceReTile = !this.grid.length || zoomChanged; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ - * on the same element. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ + // total bounds of the tiles │ │ │ │ │ + var tilesBounds = this.getTilesBounds(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - dragging: false, │ │ │ │ │ + // the new map resolution │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {} The last pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ + // the server-supported resolution for the new map resolution │ │ │ │ │ + var serverResolution = this.getServerResolution(resolution); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {} The first pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - start: null, │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastMoveEvt │ │ │ │ │ - * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ - * position the map correctly when our "delay drag" │ │ │ │ │ - * timeout expired. │ │ │ │ │ - */ │ │ │ │ │ - lastMoveEvt: null, │ │ │ │ │ + // 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: oldOnselectstart │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - oldOnselectstart: null, │ │ │ │ │ + if (forceReTile || │ │ │ │ │ + (!dragging && !tilesBounds.containsBounds(bounds))) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + // 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: timeoutId │ │ │ │ │ - * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ - * This is "private", and should be left alone. │ │ │ │ │ - */ │ │ │ │ │ - timeoutId: null, │ │ │ │ │ + if (zoomChanged && this.transitionEffect !== 'resize') { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + if (!zoomChanged || this.transitionEffect === 'resize') { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: documentEvents │ │ │ │ │ - * {Boolean} Are we currently observing document events? │ │ │ │ │ - */ │ │ │ │ │ - documentEvents: null, │ │ │ │ │ + this.initSingleTile(bounds); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ - * Returns OpenLayers.Handler.Drag │ │ │ │ │ - * │ │ │ │ │ - * 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 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 (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 │ │ │ │ │ + if (forceReTile) { │ │ │ │ │ + if (zoomChanged && (this.transitionEffect === 'resize' || │ │ │ │ │ + this.gridResolution === resolution)) { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ + this.initGriddedTiles(bounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: dragstart │ │ │ │ │ - * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ + * 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: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * loc - {} map location │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Object} Object with the following properties: tile ({}), │ │ │ │ │ + * i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel │ │ │ │ │ + * offset from top left). │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ + getTileData: function(loc) { │ │ │ │ │ + var data = null, │ │ │ │ │ + x = loc.lon, │ │ │ │ │ + y = loc.lat, │ │ │ │ │ + numRows = this.grid.length; │ │ │ │ │ │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + 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 (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart ? │ │ │ │ │ - document.onselectstart : OpenLayers.Function.True; │ │ │ │ │ + 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) │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - │ │ │ │ │ - propagate = !this.stopDown; │ │ │ │ │ - } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ } │ │ │ │ │ - return propagate; │ │ │ │ │ + return data; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragmove │ │ │ │ │ - * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ + * Method: destroyTile │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + destroyTile: function(tile) { │ │ │ │ │ + this.removeTileMonitoringHooks(tile); │ │ │ │ │ + tile.destroy(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragend │ │ │ │ │ - * This private method is factorized from mouseup and touchend methods │ │ │ │ │ + * Method: getServerResolution │ │ │ │ │ + * Return the closest server-supported resolution. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * resolution - {Number} The base resolution. If undefined the │ │ │ │ │ + * map resolution is used. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Number} The closest server resolution value. │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + resolution = serverResolution; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ - * to do their own processing related to these mouse events. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ + getServerZoom: function() { │ │ │ │ │ + var resolution = this.getServerResolution(); │ │ │ │ │ + return this.serverResolutions ? │ │ │ │ │ + OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ + this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * This method is called during the handling of the mouse down event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ + * Method: applyBackBuffer │ │ │ │ │ + * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse down event │ │ │ │ │ + * resolution - {Number} The resolution to transition to. │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) {}, │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + 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: 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 │ │ │ │ │ + * Method: createBackBuffer │ │ │ │ │ + * Create a back buffer. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ + * grid isn't initialized yet. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) {}, │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: removeBackBuffer │ │ │ │ │ + * Remove back buffer from DOM. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) {}, │ │ │ │ │ + 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: out │ │ │ │ │ - * This method is called during the handling of the mouse out event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Move the layer based on pixel vector. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse out event │ │ │ │ │ + * dx - {Number} │ │ │ │ │ + * dy - {Number} │ │ │ │ │ */ │ │ │ │ │ - out: function(evt) {}, │ │ │ │ │ + moveByPx: function(dx, dy) { │ │ │ │ │ + if (!this.singleTile) { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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 - {} │ │ │ │ │ */ │ │ │ │ │ + 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: mousedown │ │ │ │ │ - * Handle mousedown events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * APIMethod: getTilesBounds │ │ │ │ │ + * Return the bounds of the tile grid. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} A Bounds object representing the bounds of all the │ │ │ │ │ + * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ + * onscreen). │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ + getTilesBounds: function() { │ │ │ │ │ + var bounds = null; │ │ │ │ │ + │ │ │ │ │ + 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(); │ │ │ │ │ + │ │ │ │ │ + bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ + bottomLeftTileBounds.bottom, │ │ │ │ │ + bottomLeftTileBounds.left + width, │ │ │ │ │ + bottomLeftTileBounds.bottom + height); │ │ │ │ │ + } │ │ │ │ │ + return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ + * Method: initSingleTile │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + */ │ │ │ │ │ + initSingleTile: function(bounds) { │ │ │ │ │ + this.events.triggerEvent("retile"); │ │ │ │ │ + │ │ │ │ │ + //determine new tile bounds │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ + var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ + │ │ │ │ │ + var tileBounds = │ │ │ │ │ + new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ + center.lat - (tileHeight / 2), │ │ │ │ │ + center.lon + (tileWidth / 2), │ │ │ │ │ + center.lat + (tileHeight / 2)); │ │ │ │ │ + │ │ │ │ │ + var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ + lon: tileBounds.left, │ │ │ │ │ + lat: tileBounds.top │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + if (!this.grid.length) { │ │ │ │ │ + this.grid[0] = []; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var tile = this.grid[0][0]; │ │ │ │ │ + if (!tile) { │ │ │ │ │ + tile = this.addTile(tileBounds, px); │ │ │ │ │ + │ │ │ │ │ + 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); │ │ │ │ │ + │ │ │ │ │ + // store the resolution of the grid │ │ │ │ │ + this.gridResolution = this.getServerResolution(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ + 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: mousemove │ │ │ │ │ - * Handle mousemove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * 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} Let the event propagate. │ │ │ │ │ + * {} The tile origin. │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ + 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 origin; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ + * Method: getTileBoundsForGridIndex │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * row - {Number} The row of the grid │ │ │ │ │ + * col - {Number} The column of the grid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} The bounds for the tile at (row, col) │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ + 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: removeTimeout │ │ │ │ │ - * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ + * Method: initGriddedTiles │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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; │ │ │ │ │ + │ │ │ │ │ + var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ + this.gridLayout = tileLayout; │ │ │ │ │ + │ │ │ │ │ + var tilelon = tileLayout.tilelon; │ │ │ │ │ + var tilelat = tileLayout.tilelat; │ │ │ │ │ + │ │ │ │ │ + var layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ + var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + │ │ │ │ │ + var tileData = [], │ │ │ │ │ + center = this.map.getCenter(); │ │ │ │ │ + │ │ │ │ │ + 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: mouseup │ │ │ │ │ - * Handle mouseup events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: getMaxExtent │ │ │ │ │ + * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ + * potential specific implementations in sub-classes.) │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + getMaxExtent: function() { │ │ │ │ │ + return this.maxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ + * APIMethod: addTile │ │ │ │ │ + * Create a tile, initialize it, and add it to the layer div. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Parameters │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * position - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} The added OpenLayers.Tile │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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: mouseout │ │ │ │ │ - * Handle mouseout events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ + addTileMonitoringHooks: function(tile) { │ │ │ │ │ + │ │ │ │ │ + var replacingCls = 'olTileReplacing'; │ │ │ │ │ + │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (document.onselectstart) { │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + 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"); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + tile.onLoadError = function() { │ │ │ │ │ + this.events.triggerEvent("tileerror", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + tile.events.on({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: removeTileMonitoringHooks │ │ │ │ │ + * This function takes a tile as input and removes the tile hooks │ │ │ │ │ + * that were added in addTileMonitoringHooks() │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - // let the click event propagate only if the mouse moved │ │ │ │ │ - return (this.start == this.last); │ │ │ │ │ + removeTileMonitoringHooks: function(tile) { │ │ │ │ │ + tile.unload(); │ │ │ │ │ + tile.events.un({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ + * Method: moveGriddedTiles │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - activated = true; │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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" │ │ │ │ │ - ); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + grid[prepend ? 'unshift' : 'push'](row); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: 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: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * rows - {Integer} Maximum number of rows we want our grid to have. │ │ │ │ │ + * columns - {Integer} Maximum number of columns we want our grid to have. │ │ │ │ │ */ │ │ │ │ │ - adjustXY: function(evt) { │ │ │ │ │ - var pos = OpenLayers.Util.pagePosition(this.map.viewPortDiv); │ │ │ │ │ - evt.xy.x -= pos[0]; │ │ │ │ │ - evt.xy.y -= pos[1]; │ │ │ │ │ + removeExcessTiles: function(rows, columns) { │ │ │ │ │ + var i, l; │ │ │ │ │ + │ │ │ │ │ + // 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: addDocumentEvents │ │ │ │ │ - * Start observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor leaves the map viewport while dragging. │ │ │ │ │ + * Method: onMapResize │ │ │ │ │ + * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ + * dimensions of the map pane. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeDocumentEvents │ │ │ │ │ - * Stops observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor re-enters the map viewport while dragging. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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.Drag" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Box.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/Handler/Drag.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.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. │ │ │ │ │ + * Class: OpenLayers.TileManager │ │ │ │ │ + * Provides queueing of image requests and caching of image elements. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.Handler.Box = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.TileManager = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragHandler │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: cacheSize │ │ │ │ │ + * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ + * cache for fast reuse. Default is 256. │ │ │ │ │ */ │ │ │ │ │ - dragHandler: null, │ │ │ │ │ + cacheSize: 256, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: boxDivClassName │ │ │ │ │ - * {String} The CSS class to use for drawing the box. Default is │ │ │ │ │ - * olHandlerBoxZoomBox │ │ │ │ │ + * APIProperty: tilesPerFrame │ │ │ │ │ + * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ + * Default is 2. │ │ │ │ │ */ │ │ │ │ │ - boxDivClassName: 'olHandlerBoxZoomBox', │ │ │ │ │ + tilesPerFrame: 2, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: boxOffsets │ │ │ │ │ - * {Object} Caches box offsets from css. This is used by the getBoxOffsets │ │ │ │ │ - * method. │ │ │ │ │ + * APIProperty: frameDelay │ │ │ │ │ + * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ + * milliseconds. Default is 16. │ │ │ │ │ */ │ │ │ │ │ - boxOffsets: null, │ │ │ │ │ + frameDelay: 16, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: moveDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ + * tiles. Default is 100. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + moveDelay: 100, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * APIProperty: zoomDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ + * tiles. Default is 200. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.destroy(); │ │ │ │ │ - this.dragHandler = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + zoomDelay: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ + * Property: maps │ │ │ │ │ + * {Array()} The maps to manage tiles on. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Handler.prototype.setMap.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + maps: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: startBox │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} │ │ │ │ │ + * Property: tileQueueId │ │ │ │ │ + * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ */ │ │ │ │ │ - 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" │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + tileQueueId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveBox │ │ │ │ │ + * Property: tileQueue │ │ │ │ │ + * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ + * map id. │ │ │ │ │ */ │ │ │ │ │ - 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"; │ │ │ │ │ - }, │ │ │ │ │ + tileQueue: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: endBox │ │ │ │ │ + * Property: tileCache │ │ │ │ │ + * {Object} Cached image elements, keyed by URL. │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ - }, │ │ │ │ │ + tileCache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeBox │ │ │ │ │ - * Remove the zoombox from the screen and nullify our reference to it. │ │ │ │ │ + * Property: tileCacheIndex │ │ │ │ │ + * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ + * used. │ │ │ │ │ */ │ │ │ │ │ - removeBox: function() { │ │ │ │ │ - this.map.viewPortDiv.removeChild(this.zoomBox); │ │ │ │ │ - this.zoomBox = null; │ │ │ │ │ - this.boxOffsets = null; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ - ); │ │ │ │ │ + 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 = []; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: addMap │ │ │ │ │ + * Binds this instance to a map │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragHandler.activate(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + 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: deactivate │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Unbinds this instance from a map │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - if (this.dragHandler.deactivate()) { │ │ │ │ │ - if (this.zoomBox) { │ │ │ │ │ - this.removeBox(); │ │ │ │ │ + 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: move │ │ │ │ │ + * Handles the map's move event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ + */ │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: zoomEnd │ │ │ │ │ + * Handles the map's zoomEnd event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ + */ │ │ │ │ │ + zoomEnd: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: changeLayer │ │ │ │ │ + * Handles the map's changeLayer event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ + */ │ │ │ │ │ + changeLayer: function(evt) { │ │ │ │ │ + if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ + this.updateTimeout(evt.object, 0); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Handles the map's addlayer event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Handles the map's preremovelayer event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: updateTimeout │ │ │ │ │ + * Applies the or to the loop, │ │ │ │ │ + * and schedules more queue processing after if there are still │ │ │ │ │ + * tiles in the queue. │ │ │ │ │ + * │ │ │ │ │ + * 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 │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ + */ │ │ │ │ │ + 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 { │ │ │ │ │ - return false; │ │ │ │ │ + // Layer has the wrong tile type, so don't handle it any longer │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: evt.tile.layer │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: unloadTile │ │ │ │ │ + * Listener for the tile's unload event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Method: queueTileDraw │ │ │ │ │ + * Adds a tile to the queue that will draw it. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return this.boxOffsets; │ │ │ │ │ + // 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Box" │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawTilesFromQueue │ │ │ │ │ + * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: manageTileCache │ │ │ │ │ + * Adds, updates, removes and fetches cache entries. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addToCache │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ + */ │ │ │ │ │ + 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: 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomBox.js │ │ │ │ │ + OpenLayers/Control/Button.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Box.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomBox │ │ │ │ │ - * The ZoomBox control enables zooming directly to a given extent, by drawing │ │ │ │ │ - * a box on the map. The box is drawn by holding down shift, whilst dragging │ │ │ │ │ - * the mouse. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.Button │ │ │ │ │ + * The Button control is a very simple push-button, for use with │ │ │ │ │ + * . │ │ │ │ │ + * When clicked, the function trigger() is executed. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ + * │ │ │ │ │ + * Use: │ │ │ │ │ + * (code) │ │ │ │ │ + * var button = new OpenLayers.Control.Button({ │ │ │ │ │ + * displayClass: "MyButton", trigger: myFunction │ │ │ │ │ + * }); │ │ │ │ │ + * panel.addControls([button]); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Will create a button with CSS class MyButtonItemInactive, that │ │ │ │ │ + * will call the function MyFunction() when clicked. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.Button = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ /** │ │ │ │ │ * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPE} │ │ │ │ │ + * {Integer} OpenLayers.Control.TYPE_BUTTON. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + type: OpenLayers.Control.TYPE_BUTTON, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: out │ │ │ │ │ - * {Boolean} Should the control be used for zooming out? │ │ │ │ │ + * Method: trigger │ │ │ │ │ + * Called by a control panel when the button is clicked. │ │ │ │ │ */ │ │ │ │ │ - out: false, │ │ │ │ │ + trigger: function() {}, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Button" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomIn.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/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomIn │ │ │ │ │ + * The ZoomIn control is a button to increase the zoom level of a map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomIn = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: keyMask │ │ │ │ │ - * {Integer} Zoom only occurs if the keyMask matches the combination of │ │ │ │ │ - * keys down. Use bitwise operators and one or more of the │ │ │ │ │ - * constants to construct a keyMask. Leave null if │ │ │ │ │ - * not used mask. Default is null. │ │ │ │ │ + * Method: trigger │ │ │ │ │ */ │ │ │ │ │ - keyMask: null, │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomIn" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: alwaysZoom │ │ │ │ │ - * {Boolean} Always zoom in/out when box drawn, even if the zoom level does │ │ │ │ │ - * not change. │ │ │ │ │ + * Property: observeElement │ │ │ │ │ + * {DOMElement|String} The DOM element on which we listen for │ │ │ │ │ + * key events. Default to the document. │ │ │ │ │ */ │ │ │ │ │ - alwaysZoom: false, │ │ │ │ │ + observeElement: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOnClick │ │ │ │ │ - * {Boolean} Should we zoom when no box was dragged, i.e. the user only │ │ │ │ │ - * clicked? Default is true. │ │ │ │ │ + * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ + * Returns a new keyboard handler. │ │ │ │ │ + * │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - zoomOnClick: true, │ │ │ │ │ + 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 │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Box(this, { │ │ │ │ │ - done: this.zoomBox │ │ │ │ │ - }, { │ │ │ │ │ - keyMask: this.keyMask │ │ │ │ │ - }); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.eventListener = null; │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: zoomBox │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * position - {} or {} │ │ │ │ │ + * Method: activate │ │ │ │ │ */ │ │ │ │ │ - zoomBox: function(position) { │ │ │ │ │ - if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ - var bounds, │ │ │ │ │ - targetCenterPx = position.getCenterPixel(); │ │ │ │ │ - if (!this.out) { │ │ │ │ │ - var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.left, │ │ │ │ │ - y: position.bottom │ │ │ │ │ - }); │ │ │ │ │ - var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.right, │ │ │ │ │ - y: position.top │ │ │ │ │ - }); │ │ │ │ │ - bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, │ │ │ │ │ - maxXY.lon, maxXY.lat); │ │ │ │ │ - } else { │ │ │ │ │ - var pixWidth = position.right - position.left; │ │ │ │ │ - var pixHeight = position.bottom - position.top; │ │ │ │ │ - var zoomFactor = Math.min((this.map.size.h / pixHeight), │ │ │ │ │ - (this.map.size.w / pixWidth)); │ │ │ │ │ - var extent = this.map.getExtent(); │ │ │ │ │ - var center = this.map.getLonLatFromPixel(targetCenterPx); │ │ │ │ │ - var xmin = center.lon - (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ - var xmax = center.lon + (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ - var ymin = center.lat - (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ - var ymax = center.lat + (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ - bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); │ │ │ │ │ - } │ │ │ │ │ - // always zoom in/out │ │ │ │ │ - var lastZoom = this.map.getZoom(), │ │ │ │ │ - size = this.map.getSize(), │ │ │ │ │ - centerPx = { │ │ │ │ │ - x: size.w / 2, │ │ │ │ │ - y: size.h / 2 │ │ │ │ │ - }, │ │ │ │ │ - zoom = this.map.getZoomForExtent(bounds), │ │ │ │ │ - oldRes = this.map.getResolution(), │ │ │ │ │ - newRes = this.map.getResolutionForZoom(zoom); │ │ │ │ │ - if (oldRes == newRes) { │ │ │ │ │ - this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx)); │ │ │ │ │ - } else { │ │ │ │ │ - var zoomOriginPx = { │ │ │ │ │ - x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / │ │ │ │ │ - (oldRes - newRes), │ │ │ │ │ - y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / │ │ │ │ │ - (oldRes - newRes) │ │ │ │ │ - }; │ │ │ │ │ - this.map.zoomTo(zoom, zoomOriginPx); │ │ │ │ │ - } │ │ │ │ │ - if (lastZoom == this.map.getZoom() && this.alwaysZoom == true) { │ │ │ │ │ - this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - } else if (this.zoomOnClick) { // it's a pixel │ │ │ │ │ - if (!this.out) { │ │ │ │ │ - this.map.zoomTo(this.map.getZoom() + 1, position); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.zoomTo(this.map.getZoom() - 1, position); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomBox" │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleKeyEvent │ │ │ │ │ + */ │ │ │ │ │ + handleKeyEvent: function(evt) { │ │ │ │ │ + if (this.checkModifiers(evt)) { │ │ │ │ │ + this.callback(evt.type, [evt]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Keyboard" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/NavigationHistory.js │ │ │ │ │ + OpenLayers/Control/KeyboardDefaults.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ + * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.NavigationHistory │ │ │ │ │ - * A navigation history control. This is a meta-control, that creates two │ │ │ │ │ - * dependent controls: and . Call the trigger method │ │ │ │ │ - * on the and controls to restore previous and next │ │ │ │ │ - * history states. The previous and next controls will become active │ │ │ │ │ - * when there are available states to restore and will become deactive │ │ │ │ │ - * when there are no states to restore. │ │ │ │ │ + * Class: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ + * The KeyboardDefaults control adds panning and zooming functions, controlled │ │ │ │ │ + * with the keyboard. By default arrow keys pan, +/- keys zoom & Page Up/Page │ │ │ │ │ + * Down/Home/End scroll by three quarters of a page. │ │ │ │ │ + * │ │ │ │ │ + * This control has no visible appearance. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {String} Note that this control is not intended to be added directly │ │ │ │ │ - * to a control panel. Instead, add the sub-controls previous and │ │ │ │ │ - * next. These sub-controls are button type controls that activate │ │ │ │ │ - * and deactivate themselves. If this parent control is added to │ │ │ │ │ - * a panel, it will act as a toggle. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOGGLE, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: previous │ │ │ │ │ - * {} A button type control whose trigger method restores │ │ │ │ │ - * the previous state managed by this control. │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * Pixels to slide by. │ │ │ │ │ */ │ │ │ │ │ - previous: null, │ │ │ │ │ + slideFactor: 75, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: previousOptions │ │ │ │ │ - * {Object} Set this property on the options argument of the constructor │ │ │ │ │ - * to set optional properties on the control. │ │ │ │ │ + * APIProperty: observeElement │ │ │ │ │ + * {DOMelement|String} The DOM element to handle keys for. You │ │ │ │ │ + * can use the map div here, to have the navigation keys │ │ │ │ │ + * work when the map div has the focus. If undefined the │ │ │ │ │ + * document is used. │ │ │ │ │ */ │ │ │ │ │ - previousOptions: null, │ │ │ │ │ + observeElement: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: next │ │ │ │ │ - * {} A button type control whose trigger method restores │ │ │ │ │ - * the next state managed by this control. │ │ │ │ │ + * Constructor: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ */ │ │ │ │ │ - next: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: nextOptions │ │ │ │ │ - * {Object} Set this property on the options argument of the constructor │ │ │ │ │ - * to set optional properties on the control. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Create handler. │ │ │ │ │ */ │ │ │ │ │ - nextOptions: null, │ │ │ │ │ + draw: function() { │ │ │ │ │ + var observeElement = this.observeElement || document; │ │ │ │ │ + this.handler = new OpenLayers.Handler.Keyboard(this, { │ │ │ │ │ + "keydown": this.defaultKeyPress │ │ │ │ │ + }, { │ │ │ │ │ + observeElement: observeElement │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: limit │ │ │ │ │ - * {Integer} Optional limit on the number of history items to retain. If │ │ │ │ │ - * null, there is no limit. Default is 50. │ │ │ │ │ + * Method: defaultKeyPress │ │ │ │ │ + * When handling the key event, we only use evt.keyCode. This holds │ │ │ │ │ + * some drawbacks, though we get around them below. When interpretting │ │ │ │ │ + * the keycodes below (including the comments associated with them), │ │ │ │ │ + * consult the URL below. For instance, the Safari browser returns │ │ │ │ │ + * "IE keycodes", and so is supported by any keycode labeled "IE". │ │ │ │ │ + * │ │ │ │ │ + * Very informative URL: │ │ │ │ │ + * http://unixpapa.com/js/key.html │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - limit: 50, │ │ │ │ │ + defaultKeyPress: function(evt) { │ │ │ │ │ + var size, handled = true; │ │ │ │ │ + │ │ │ │ │ + var target = OpenLayers.Event.element(evt); │ │ │ │ │ + if (target && │ │ │ │ │ + (target.tagName == 'INPUT' || │ │ │ │ │ + target.tagName == 'TEXTAREA' || │ │ │ │ │ + target.tagName == 'SELECT')) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + switch (evt.keyCode) { │ │ │ │ │ + case OpenLayers.Event.KEY_LEFT: │ │ │ │ │ + this.map.pan(-this.slideFactor, 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_RIGHT: │ │ │ │ │ + this.map.pan(this.slideFactor, 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_UP: │ │ │ │ │ + this.map.pan(0, -this.slideFactor); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_DOWN: │ │ │ │ │ + this.map.pan(0, this.slideFactor); │ │ │ │ │ + break; │ │ │ │ │ + │ │ │ │ │ + case 33: // Page Up. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0, -0.75 * size.h); │ │ │ │ │ + break; │ │ │ │ │ + case 34: // Page Down. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0, 0.75 * size.h); │ │ │ │ │ + break; │ │ │ │ │ + case 35: // End. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0.75 * size.w, 0); │ │ │ │ │ + break; │ │ │ │ │ + case 36: // Home. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(-0.75 * size.w, 0); │ │ │ │ │ + break; │ │ │ │ │ + │ │ │ │ │ + case 43: // +/= (ASCII), keypad + (ASCII, Opera) │ │ │ │ │ + case 61: // +/= (Mozilla, Opera, some ASCII) │ │ │ │ │ + case 187: // +/= (IE) │ │ │ │ │ + case 107: // keypad + (IE, Mozilla) │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + break; │ │ │ │ │ + case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) │ │ │ │ │ + case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) │ │ │ │ │ + case 189: // -/_ (IE) │ │ │ │ │ + case 95: // -/_ (some ASCII) │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + handled = false; │ │ │ │ │ + } │ │ │ │ │ + if (handled) { │ │ │ │ │ + // prevent browser default not to move the page │ │ │ │ │ + // when moving the page with the keyboard │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: stopDown │ │ │ │ │ + * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ + * on the same element. Default is true. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: 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: clearOnDeactivate │ │ │ │ │ - * {Boolean} Clear the history when the control is deactivated. Default │ │ │ │ │ - * is false. │ │ │ │ │ + * Property: lastMoveEvt │ │ │ │ │ + * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ + * position the map correctly when our "delay drag" │ │ │ │ │ + * timeout expired. │ │ │ │ │ */ │ │ │ │ │ - clearOnDeactivate: false, │ │ │ │ │ + lastMoveEvt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: registry │ │ │ │ │ - * {Object} An object with keys corresponding to event types. Values │ │ │ │ │ - * are functions that return an object representing the current state. │ │ │ │ │ + * Property: oldOnselectstart │ │ │ │ │ + * {Function} │ │ │ │ │ */ │ │ │ │ │ - registry: null, │ │ │ │ │ + oldOnselectstart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: nextStack │ │ │ │ │ - * {Array} Array of items in the history. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - nextStack: null, │ │ │ │ │ + interval: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: previousStack │ │ │ │ │ - * {Array} List of items in the history. First item represents the current │ │ │ │ │ - * state. │ │ │ │ │ + * Property: timeoutId │ │ │ │ │ + * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ + * This is "private", and should be left alone. │ │ │ │ │ */ │ │ │ │ │ - previousStack: null, │ │ │ │ │ + timeoutId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: listeners │ │ │ │ │ - * {Object} An object containing properties corresponding to event types. │ │ │ │ │ - * This object is used to configure the control and is modified on │ │ │ │ │ - * construction. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - listeners: null, │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: restoring │ │ │ │ │ - * {Boolean} Currently restoring a history state. This is set to true │ │ │ │ │ - * before calling restore and set to false after restore returns. │ │ │ │ │ + * Property: documentEvents │ │ │ │ │ + * {Boolean} Are we currently observing document events? │ │ │ │ │ */ │ │ │ │ │ - restoring: false, │ │ │ │ │ + documentEvents: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.NavigationHistory │ │ │ │ │ + * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ + * Returns OpenLayers.Handler.Drag │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * 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(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - this.registry = OpenLayers.Util.extend({ │ │ │ │ │ - "moveend": this.getState │ │ │ │ │ - }, this.registry); │ │ │ │ │ + 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 │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var previousOptions = { │ │ │ │ │ - trigger: OpenLayers.Function.bind(this.previousTrigger, this), │ │ │ │ │ - displayClass: this.displayClass + " " + this.displayClass + "Previous" │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(previousOptions, this.previousOptions); │ │ │ │ │ - this.previous = new OpenLayers.Control.Button(previousOptions); │ │ │ │ │ │ │ │ │ │ - var nextOptions = { │ │ │ │ │ - trigger: OpenLayers.Function.bind(this.nextTrigger, this), │ │ │ │ │ - displayClass: this.displayClass + " " + this.displayClass + "Next" │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(nextOptions, this.nextOptions); │ │ │ │ │ - this.next = new OpenLayers.Control.Button(nextOptions); │ │ │ │ │ + /** │ │ │ │ │ + * Method: dragstart │ │ │ │ │ + * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ + */ │ │ │ │ │ + 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]); │ │ │ │ │ │ │ │ │ │ - this.clear(); │ │ │ │ │ + // 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onPreviousChange │ │ │ │ │ - * Called when the previous history stack changes. │ │ │ │ │ + * Method: dragmove │ │ │ │ │ + * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to be restored │ │ │ │ │ - * if previous is triggered again or null if no previous states remain. │ │ │ │ │ - * length - {Integer} The number of remaining previous states that can │ │ │ │ │ - * be restored. │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - onPreviousChange: function(state, length) { │ │ │ │ │ - if (state && !this.previous.active) { │ │ │ │ │ - this.previous.activate(); │ │ │ │ │ - } else if (!state && this.previous.active) { │ │ │ │ │ - this.previous.deactivate(); │ │ │ │ │ + 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: onNextChange │ │ │ │ │ - * Called when the next history stack changes. │ │ │ │ │ + * Method: dragend │ │ │ │ │ + * This private method is factorized from mouseup and touchend methods │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to be restored │ │ │ │ │ - * if next is triggered again or null if no next states remain. │ │ │ │ │ - * length - {Integer} The number of remaining next states that can │ │ │ │ │ - * be restored. │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - onNextChange: function(state, length) { │ │ │ │ │ - if (state && !this.next.active) { │ │ │ │ │ - this.next.activate(); │ │ │ │ │ - } else if (!state && this.next.active) { │ │ │ │ │ - this.next.deactivate(); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy the control. │ │ │ │ │ + * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ + * to do their own processing related to these mouse events. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ - this.previous.destroy(); │ │ │ │ │ - this.next.destroy(); │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - for (var prop in this) { │ │ │ │ │ - this[prop] = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control and and child │ │ │ │ │ - * controls. │ │ │ │ │ + /** │ │ │ │ │ + * Method: down │ │ │ │ │ + * This method is called during the handling of the mouse down event. │ │ │ │ │ + * Subclasses can do their own processing here. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * evt - {Event} The mouse down event │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - this.next.setMap(map); │ │ │ │ │ - this.previous.setMap(map); │ │ │ │ │ + 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: draw │ │ │ │ │ - * Called when the control is added to the map. │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - this.next.draw(); │ │ │ │ │ - this.previous.draw(); │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + return this.dragstart(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: previousTrigger │ │ │ │ │ - * Restore the previous state. If no items are in the previous history │ │ │ │ │ - * stack, this has no effect. │ │ │ │ │ + * Method: mousemove │ │ │ │ │ + * Handle mousemove events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ - * items are in the previous history stack. │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - previousTrigger: function() { │ │ │ │ │ - var current = this.previousStack.shift(); │ │ │ │ │ - var state = this.previousStack.shift(); │ │ │ │ │ - if (state != undefined) { │ │ │ │ │ - this.nextStack.unshift(current); │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - this.restoring = true; │ │ │ │ │ - this.restore(state); │ │ │ │ │ - this.restoring = false; │ │ │ │ │ - this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.previousStack.unshift(current); │ │ │ │ │ - } │ │ │ │ │ - return state; │ │ │ │ │ + mousemove: function(evt) { │ │ │ │ │ + return this.dragmove(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: nextTrigger │ │ │ │ │ - * Restore the next state. If no items are in the next history │ │ │ │ │ - * stack, this has no effect. The next history stack is populated │ │ │ │ │ - * as states are restored from the previous history stack. │ │ │ │ │ + * Method: touchmove │ │ │ │ │ + * Handle touchmove events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ - * items are in the next history stack. │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - nextTrigger: function() { │ │ │ │ │ - var state = this.nextStack.shift(); │ │ │ │ │ - if (state != undefined) { │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - this.restoring = true; │ │ │ │ │ - this.restore(state); │ │ │ │ │ - this.restoring = false; │ │ │ │ │ - this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return state; │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + return this.dragmove(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clear │ │ │ │ │ - * Clear history. │ │ │ │ │ + * Method: removeTimeout │ │ │ │ │ + * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - this.previousStack = []; │ │ │ │ │ - this.previous.deactivate(); │ │ │ │ │ - this.nextStack = []; │ │ │ │ │ - this.next.deactivate(); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getState │ │ │ │ │ - * Get the current state and return it. │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouseup events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} An object representing the current state. │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - getState: function() { │ │ │ │ │ - return { │ │ │ │ │ - center: this.map.getCenter(), │ │ │ │ │ - resolution: this.map.getResolution(), │ │ │ │ │ - projection: this.map.getProjectionObject(), │ │ │ │ │ - units: this.map.getProjectionObject().getUnits() || │ │ │ │ │ - this.map.units || this.map.baseLayer.units │ │ │ │ │ - }; │ │ │ │ │ + mouseup: function(evt) { │ │ │ │ │ + return this.dragend(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: restore │ │ │ │ │ - * Update the state with the given object. │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Handle touchend events │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to restore. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - restore: function(state) { │ │ │ │ │ - var center, zoom; │ │ │ │ │ - if (this.map.getProjectionObject() == state.projection) { │ │ │ │ │ - zoom = this.map.getZoomForResolution(state.resolution); │ │ │ │ │ - center = state.center; │ │ │ │ │ - } else { │ │ │ │ │ - center = state.center.clone(); │ │ │ │ │ - center.transform(state.projection, this.map.getProjectionObject()); │ │ │ │ │ - var sourceUnits = state.units; │ │ │ │ │ - var targetUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ - this.map.units || this.map.baseLayer.units; │ │ │ │ │ - var resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ - OpenLayers.INCHES_PER_UNIT[sourceUnits] / OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ - zoom = this.map.getZoomForResolution(resolutionFactor * state.resolution); │ │ │ │ │ - } │ │ │ │ │ - this.map.setCenter(center, zoom); │ │ │ │ │ + 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setListeners │ │ │ │ │ - * Sets functions to be registered in the listeners object. │ │ │ │ │ + * Method: mouseout │ │ │ │ │ + * Handle mouseout events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - setListeners: function() { │ │ │ │ │ - this.listeners = {}; │ │ │ │ │ - for (var type in this.registry) { │ │ │ │ │ - this.listeners[type] = OpenLayers.Function.bind(function() { │ │ │ │ │ - if (!this.restoring) { │ │ │ │ │ - var state = this.registry[type].apply(this, arguments); │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - if (this.previousStack.length > 1) { │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.previousStack.length > (this.limit + 1)) { │ │ │ │ │ - this.previousStack.pop(); │ │ │ │ │ - } │ │ │ │ │ - if (this.nextStack.length > 0) { │ │ │ │ │ - this.nextStack = []; │ │ │ │ │ - this.onNextChange(null, 0); │ │ │ │ │ - } │ │ │ │ │ + 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]); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ - }, this); │ │ │ │ │ + if (document.onselectstart) { │ │ │ │ │ + document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. This registers any listeners. │ │ │ │ │ - * │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Control successfully activated. │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ + */ │ │ │ │ │ + click: function(evt) { │ │ │ │ │ + // let the click event propagate only if the mouse moved │ │ │ │ │ + return (this.start == this.last); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully activated. │ │ │ │ │ */ │ │ │ │ │ activate: function() { │ │ │ │ │ var activated = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this)) { │ │ │ │ │ - if (this.listeners == null) { │ │ │ │ │ - this.setListeners(); │ │ │ │ │ - } │ │ │ │ │ - for (var type in this.listeners) { │ │ │ │ │ - this.map.events.register(type, this, this.listeners[type]); │ │ │ │ │ - } │ │ │ │ │ - activated = true; │ │ │ │ │ - if (this.previousStack.length == 0) { │ │ │ │ │ - this.initStack(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + activated = true; │ │ │ │ │ } │ │ │ │ │ return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initStack │ │ │ │ │ - * Called after the control is activated if the previous history stack is │ │ │ │ │ - * empty. │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ */ │ │ │ │ │ - initStack: function() { │ │ │ │ │ - if (this.map.getCenter()) { │ │ │ │ │ - this.listeners.moveend(); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. This unregisters any listeners. │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * 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/Control/DragPan.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.DragPan │ │ │ │ │ + * The DragPan control pans the map with a drag of the mouse. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: type │ │ │ │ │ + * {OpenLayers.Control.TYPES} │ │ │ │ │ + */ │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: panned │ │ │ │ │ + * {Boolean} The map moved. │ │ │ │ │ + */ │ │ │ │ │ + panned: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: interval │ │ │ │ │ + * {Integer} The number of milliseconds that should ellapse before │ │ │ │ │ + * panning the map again. Defaults to 0 milliseconds, which means that │ │ │ │ │ + * no separate cycle is used for panning. In most cases you won't want │ │ │ │ │ + * to change this value. For slow machines/devices larger values can be │ │ │ │ │ + * tried out. │ │ │ │ │ + */ │ │ │ │ │ + interval: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ + * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + documentDrag: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: kinetic │ │ │ │ │ + * {} The OpenLayers.Kinetic object. │ │ │ │ │ + */ │ │ │ │ │ + kinetic: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: enableKinetic │ │ │ │ │ + * {Boolean} Set this option to enable "kinetic dragging". Can be │ │ │ │ │ + * set to true or to an object. If set to an object this │ │ │ │ │ + * object will be passed to the {} │ │ │ │ │ + * constructor. Defaults to true. │ │ │ │ │ + * To get kinetic dragging, ensure that OpenLayers/Kinetic.js is │ │ │ │ │ + * included in your build config. │ │ │ │ │ + */ │ │ │ │ │ + enableKinetic: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: kineticInterval │ │ │ │ │ + * {Integer} Interval in milliseconds between 2 steps in the "kinetic │ │ │ │ │ + * scrolling". Applies only if enableKinetic is set. Defaults │ │ │ │ │ + * to 10 milliseconds. │ │ │ │ │ + */ │ │ │ │ │ + kineticInterval: 10, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Creates a Drag handler, using and │ │ │ │ │ + * as callbacks. │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + if (this.enableKinetic && OpenLayers.Kinetic) { │ │ │ │ │ + var config = { │ │ │ │ │ + interval: this.kineticInterval │ │ │ │ │ + }; │ │ │ │ │ + if (typeof this.enableKinetic === "object") { │ │ │ │ │ + config = OpenLayers.Util.extend(config, this.enableKinetic); │ │ │ │ │ + } │ │ │ │ │ + this.kinetic = new OpenLayers.Kinetic(config); │ │ │ │ │ + } │ │ │ │ │ + this.handler = new OpenLayers.Handler.Drag(this, { │ │ │ │ │ + "move": this.panMap, │ │ │ │ │ + "done": this.panMapDone, │ │ │ │ │ + "down": this.panMapStart │ │ │ │ │ + }, { │ │ │ │ │ + interval: this.interval, │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: panMapStart │ │ │ │ │ + */ │ │ │ │ │ + panMapStart: function() { │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + this.kinetic.begin(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: panMap │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Control successfully deactivated. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} Pixel of the mouse position │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this)) { │ │ │ │ │ - for (var type in this.listeners) { │ │ │ │ │ - this.map.events.unregister( │ │ │ │ │ - type, this, this.listeners[type] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.clearOnDeactivate) { │ │ │ │ │ - this.clear(); │ │ │ │ │ + panMap: function(xy) { │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + this.kinetic.update(xy); │ │ │ │ │ + } │ │ │ │ │ + this.panned = true; │ │ │ │ │ + this.map.pan( │ │ │ │ │ + this.handler.last.x - xy.x, │ │ │ │ │ + this.handler.last.y - xy.y, { │ │ │ │ │ + dragging: true, │ │ │ │ │ + animate: false │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: panMapDone │ │ │ │ │ + * Finish the panning operation. Only call setCenter (through ) │ │ │ │ │ + * if the map has actually been moved. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} Pixel of the mouse position │ │ │ │ │ + */ │ │ │ │ │ + panMapDone: function(xy) { │ │ │ │ │ + if (this.panned) { │ │ │ │ │ + var res = null; │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + res = this.kinetic.end(xy); │ │ │ │ │ + } │ │ │ │ │ + this.map.pan( │ │ │ │ │ + this.handler.last.x - xy.x, │ │ │ │ │ + this.handler.last.y - xy.y, { │ │ │ │ │ + dragging: !!res, │ │ │ │ │ + animate: false │ │ │ │ │ } │ │ │ │ │ - deactivated = true; │ │ │ │ │ + ); │ │ │ │ │ + if (res) { │ │ │ │ │ + var self = this; │ │ │ │ │ + this.kinetic.move(res, function(x, y, end) { │ │ │ │ │ + self.map.pan(x, y, { │ │ │ │ │ + dragging: !end, │ │ │ │ │ + animate: false │ │ │ │ │ + }); │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + this.panned = false; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.NavigationHistory" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.DragPan" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Handler/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 │ │ │ │ │ @@ -40858,618 +36674,1375 @@ │ │ │ │ │ } │ │ │ │ │ OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.Split" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Pinch.js │ │ │ │ │ + OpenLayers/Control/Measure.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Class: OpenLayers.Control.Measure │ │ │ │ │ + * Allows for drawing of features for measurements. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * measure - Triggered when a measurement sketch is complete. Listeners │ │ │ │ │ + * will receive an event with measure, units, order, and geometry │ │ │ │ │ + * properties. │ │ │ │ │ + * measurepartial - Triggered when a new point is added to the │ │ │ │ │ + * measurement sketch or if the property is true and the │ │ │ │ │ + * measurement sketch is modified. Listeners receive an event with measure, │ │ │ │ │ + * units, order, and geometry. │ │ │ │ │ */ │ │ │ │ │ - started: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of touchstart events from getting to │ │ │ │ │ - * listeners on the same element. Default is false. │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - stopDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinching │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Property: callbacks │ │ │ │ │ + * {Object} The functions that are sent to the handler for callback │ │ │ │ │ */ │ │ │ │ │ - pinching: false, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Object} Object that store informations related to pinch last touch. │ │ │ │ │ + * APIProperty: displaySystem │ │ │ │ │ + * {String} Display system for output measurements. Supported values │ │ │ │ │ + * are 'english', 'metric', and 'geographic'. Default is 'metric'. │ │ │ │ │ */ │ │ │ │ │ - last: null, │ │ │ │ │ + displaySystem: 'metric', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {Object} Object that store informations related to pinch touchstart. │ │ │ │ │ + * APIProperty: geodesic │ │ │ │ │ + * {Boolean} Calculate geodesic metrics instead of planar metrics. This │ │ │ │ │ + * requires that geometries can be transformed into Geographic/WGS84 │ │ │ │ │ + * (if that is not already the map projection). Default is false. │ │ │ │ │ */ │ │ │ │ │ - start: null, │ │ │ │ │ + geodesic: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Pinch │ │ │ │ │ - * Returns OpenLayers.Handler.Pinch │ │ │ │ │ + * Property: displaySystemUnits │ │ │ │ │ + * {Object} Units for various measurement systems. Values are arrays │ │ │ │ │ + * of unit abbreviations (from OpenLayers.INCHES_PER_UNIT) in decreasing │ │ │ │ │ + * order of length. │ │ │ │ │ + */ │ │ │ │ │ + displaySystemUnits: { │ │ │ │ │ + geographic: ['dd'], │ │ │ │ │ + english: ['mi', 'ft', 'in'], │ │ │ │ │ + metric: ['km', 'm'] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: delay │ │ │ │ │ + * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ + * considered a double-click. The "measurepartial" event will not │ │ │ │ │ + * be triggered if the sketch is completed within this time. This │ │ │ │ │ + * is required for IE where creating a browser reflow (if a listener │ │ │ │ │ + * is modifying the DOM by displaying the measurement values) messes │ │ │ │ │ + * with the dblclick listener in the sketch handler. │ │ │ │ │ + */ │ │ │ │ │ + partialDelay: 300, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: delayedTrigger │ │ │ │ │ + * {Number} Timeout id of trigger for measurepartial. │ │ │ │ │ + */ │ │ │ │ │ + delayedTrigger: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: persist │ │ │ │ │ + * {Boolean} Keep the temporary measurement sketch drawn after the │ │ │ │ │ + * measurement is complete. The geometry will persist until a new │ │ │ │ │ + * measurement is started, the control is deactivated, or is │ │ │ │ │ + * called. │ │ │ │ │ + */ │ │ │ │ │ + persist: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: immediate │ │ │ │ │ + * {Boolean} Activates the immediate measurement so that the "measurepartial" │ │ │ │ │ + * event is also fired once the measurement sketch is modified. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + immediate: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Measure │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * handler - {} │ │ │ │ │ * options - {Object} │ │ │ │ │ */ │ │ │ │ │ + initialize: function(handler, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + var callbacks = { │ │ │ │ │ + done: this.measureComplete, │ │ │ │ │ + point: this.measurePartial │ │ │ │ │ + }; │ │ │ │ │ + if (this.immediate) { │ │ │ │ │ + callbacks.modify = this.measureImmediate; │ │ │ │ │ + } │ │ │ │ │ + this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); │ │ │ │ │ + │ │ │ │ │ + // let the handler options override, so old code that passes 'persist' │ │ │ │ │ + // directly to the handler does not need an update │ │ │ │ │ + this.handlerOptions = OpenLayers.Util.extend({ │ │ │ │ │ + persist: this.persist │ │ │ │ │ + }, this.handlerOptions); │ │ │ │ │ + this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Stop the control from measuring. If is true, the temporary │ │ │ │ │ + * sketch will be erased. │ │ │ │ │ + */ │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.handler.cancel(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setImmediate │ │ │ │ │ + * Sets the property. Changes the activity of immediate │ │ │ │ │ + * measurement. │ │ │ │ │ + */ │ │ │ │ │ + setImmediate: function(immediate) { │ │ │ │ │ + this.immediate = immediate; │ │ │ │ │ + if (this.immediate) { │ │ │ │ │ + this.callbacks.modify = this.measureImmediate; │ │ │ │ │ + } else { │ │ │ │ │ + delete this.callbacks.modify; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: updateHandler │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * handler - {Function} One of the sketch handler constructors. │ │ │ │ │ + * options - {Object} Options for the handler. │ │ │ │ │ + */ │ │ │ │ │ + updateHandler: function(handler, options) { │ │ │ │ │ + var active = this.active; │ │ │ │ │ + if (active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + this.handler = new handler(this, this.callbacks, options); │ │ │ │ │ + if (active) { │ │ │ │ │ + this.activate(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: measureComplete │ │ │ │ │ + * Called when the measurement sketch is done. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + measureComplete: function(geometry) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.measure(geometry, "measure"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: measurePartial │ │ │ │ │ + * Called each time a new point is added to the measurement sketch. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} The last point added. │ │ │ │ │ + * geometry - {} The sketch geometry. │ │ │ │ │ + */ │ │ │ │ │ + measurePartial: function(point, geometry) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + geometry = geometry.clone(); │ │ │ │ │ + // when we're wating for a dblclick, we have to trigger measurepartial │ │ │ │ │ + // after some delay to deal with reflow issues in IE │ │ │ │ │ + if (this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ + // no dblclick in freehand mode │ │ │ │ │ + this.measure(geometry, "measurepartial"); │ │ │ │ │ } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ + this.delayedTrigger = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.delayedTrigger = null; │ │ │ │ │ + this.measure(geometry, "measurepartial"); │ │ │ │ │ + }, this), │ │ │ │ │ + this.partialDelay │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - return propagate; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ + * Method: measureImmediate │ │ │ │ │ + * Called each time the measurement sketch is modified. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * point - {} The point at the mouse position. │ │ │ │ │ + * feature - {} The sketch feature. │ │ │ │ │ + * drawing - {Boolean} Indicates whether we're currently drawing. │ │ │ │ │ + */ │ │ │ │ │ + measureImmediate: function(point, feature, drawing) { │ │ │ │ │ + if (drawing && !this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.measure(feature.geometry, "measurepartial"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: cancelDelay │ │ │ │ │ + * Cancels the delay measurement that measurePartial began. │ │ │ │ │ + */ │ │ │ │ │ + cancelDelay: function() { │ │ │ │ │ + if (this.delayedTrigger !== null) { │ │ │ │ │ + window.clearTimeout(this.delayedTrigger); │ │ │ │ │ + this.delayedTrigger = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: measure │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * eventType - {String} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + measure: function(geometry, eventType) { │ │ │ │ │ + var stat, order; │ │ │ │ │ + if (geometry.CLASS_NAME.indexOf('LineString') > -1) { │ │ │ │ │ + stat = this.getBestLength(geometry); │ │ │ │ │ + order = 1; │ │ │ │ │ + } else { │ │ │ │ │ + stat = this.getBestArea(geometry); │ │ │ │ │ + order = 2; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + this.events.triggerEvent(eventType, { │ │ │ │ │ + measure: stat[0], │ │ │ │ │ + units: stat[1], │ │ │ │ │ + order: order, │ │ │ │ │ + geometry: geometry │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ + * Method: getBestArea │ │ │ │ │ + * Based on the returns the area of a geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * geometry - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ + * area and the units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getBestArea: function(geometry) { │ │ │ │ │ + var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ + var unit, area; │ │ │ │ │ + for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ + unit = units[i]; │ │ │ │ │ + area = this.getArea(geometry, unit); │ │ │ │ │ + if (area > 1) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return [area, unit]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ + * Method: getArea │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * units - {String} Unit abbreviation │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ + * {Float} The geometry area in the given units. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - activated = true; │ │ │ │ │ + getArea: function(geometry, units) { │ │ │ │ │ + var area, geomUnits; │ │ │ │ │ + if (this.geodesic) { │ │ │ │ │ + area = geometry.getGeodesicArea(this.map.getProjectionObject()); │ │ │ │ │ + geomUnits = "m"; │ │ │ │ │ + } else { │ │ │ │ │ + area = geometry.getArea(); │ │ │ │ │ + geomUnits = this.map.getUnits(); │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ + var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ + if (inPerDisplayUnit) { │ │ │ │ │ + var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ + area *= Math.pow((inPerMapUnit / inPerDisplayUnit), 2); │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + * Method: getBestLength │ │ │ │ │ + * Based on the returns the length of a geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ + * length and the units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getBestLength: function(geometry) { │ │ │ │ │ + var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ + var unit, length; │ │ │ │ │ + for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ + unit = units[i]; │ │ │ │ │ + length = this.getLength(geometry, unit); │ │ │ │ │ + if (length > 1) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + return [length, unit]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getDistance │ │ │ │ │ - * Get the distance in pixels between two touches. │ │ │ │ │ + * Method: getLength │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * touches - {Array(Object)} │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * units - {String} Unit abbreviation │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Number} The distance in pixels. │ │ │ │ │ + * {Float} The geometry length in the given units. │ │ │ │ │ */ │ │ │ │ │ - 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) │ │ │ │ │ - ); │ │ │ │ │ + getLength: function(geometry, units) { │ │ │ │ │ + var length, geomUnits; │ │ │ │ │ + if (this.geodesic) { │ │ │ │ │ + length = geometry.getGeodesicLength(this.map.getProjectionObject()); │ │ │ │ │ + geomUnits = "m"; │ │ │ │ │ + } else { │ │ │ │ │ + length = geometry.getLength(); │ │ │ │ │ + geomUnits = this.map.getUnits(); │ │ │ │ │ + } │ │ │ │ │ + var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ + if (inPerDisplayUnit) { │ │ │ │ │ + var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ + length *= (inPerMapUnit / inPerDisplayUnit); │ │ │ │ │ + } │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Measure" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Pan.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/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Pan │ │ │ │ │ + * The Pan control is a single button to pan the map in one direction. For │ │ │ │ │ + * a more complete control see . │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ + * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ + * by some ratio of the map dimensions, use instead. │ │ │ │ │ + */ │ │ │ │ │ + slideFactor: 50, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideRatio │ │ │ │ │ + * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ + * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ + * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ + * pan up half the map height. │ │ │ │ │ + */ │ │ │ │ │ + slideRatio: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: direction │ │ │ │ │ + * {String} in {'North', 'South', 'East', 'West'} │ │ │ │ │ + */ │ │ │ │ │ + direction: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getPinchData │ │ │ │ │ - * Get informations about the pinch event. │ │ │ │ │ + * Constructor: OpenLayers.Control.Pan │ │ │ │ │ + * Control which handles the panning (in any of the cardinal directions) │ │ │ │ │ + * of the map by a set px distance. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Object that contains data about the current pinch. │ │ │ │ │ + * direction - {String} The direction this button should pan. │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + initialize: function(direction, options) { │ │ │ │ │ + │ │ │ │ │ + this.direction = direction; │ │ │ │ │ + this.CLASS_NAME += this.direction; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Pinch" │ │ │ │ │ + /** │ │ │ │ │ + * Method: trigger │ │ │ │ │ + */ │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var getSlideFactor = OpenLayers.Function.bind(function(dim) { │ │ │ │ │ + return this.slideRatio ? │ │ │ │ │ + this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ + this.slideFactor; │ │ │ │ │ + }, this); │ │ │ │ │ + │ │ │ │ │ + switch (this.direction) { │ │ │ │ │ + case OpenLayers.Control.Pan.NORTH: │ │ │ │ │ + this.map.pan(0, -getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.SOUTH: │ │ │ │ │ + this.map.pan(0, getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.WEST: │ │ │ │ │ + this.map.pan(-getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.EAST: │ │ │ │ │ + this.map.pan(getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Pan" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ +OpenLayers.Control.Pan.NORTH = "North"; │ │ │ │ │ +OpenLayers.Control.Pan.SOUTH = "South"; │ │ │ │ │ +OpenLayers.Control.Pan.EAST = "East"; │ │ │ │ │ +OpenLayers.Control.Pan.WEST = "West"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PinchZoom.js │ │ │ │ │ + OpenLayers/Control/ModifyFeature.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/Pinch.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.PinchZoom │ │ │ │ │ + * Class: OpenLayers.Control.ModifyFeature │ │ │ │ │ + * Control to modify features. When activated, a click renders the vertices │ │ │ │ │ + * of a feature - these vertices can then be dragged. By default, the │ │ │ │ │ + * delete key will delete the vertex under the mouse. New features are │ │ │ │ │ + * added by dragging "virtual vertices" between vertices. Create a new │ │ │ │ │ + * control with the constructor. │ │ │ │ │ * │ │ │ │ │ - * Inherits: │ │ │ │ │ + * Inherits From: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPES} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} If set to true, dragging vertices will continue even if the │ │ │ │ │ + * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinchOrigin │ │ │ │ │ - * {Object} Cached object representing the pinch start (in pixels). │ │ │ │ │ + * APIProperty: geometryTypes │ │ │ │ │ + * {Array(String)} To restrict modification to a limited set of geometry │ │ │ │ │ + * types, send a list of strings corresponding to the geometry class │ │ │ │ │ + * names. │ │ │ │ │ */ │ │ │ │ │ - pinchOrigin: null, │ │ │ │ │ + geometryTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: currentCenter │ │ │ │ │ - * {Object} Cached object representing the latest pinch center (in pixels). │ │ │ │ │ + * APIProperty: clickout │ │ │ │ │ + * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ + * Default is true. │ │ │ │ │ */ │ │ │ │ │ - currentCenter: null, │ │ │ │ │ + clickout: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * APIProperty: toggle │ │ │ │ │ + * {Boolean} Unselect a selected feature on click. │ │ │ │ │ + * Default is true. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + toggle: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: preserveCenter │ │ │ │ │ - * {Boolean} Set this to true if you don't want the map center to change │ │ │ │ │ - * while pinching. For example you may want to set preserveCenter to │ │ │ │ │ - * true when the user location is being watched and you want to preserve │ │ │ │ │ - * the user location at the center of the map even if he zooms in or │ │ │ │ │ - * out using pinch. This property's value can be changed any time on an │ │ │ │ │ - * existing instance. Default is false. │ │ │ │ │ + * APIProperty: standalone │ │ │ │ │ + * {Boolean} Set to true to create a control without SelectFeature │ │ │ │ │ + * capabilities. Default is false. If standalone is true, to modify │ │ │ │ │ + * a feature, call the method with the target feature. │ │ │ │ │ + * Note that you must call the method to finish │ │ │ │ │ + * feature modification in standalone mode (before starting to modify │ │ │ │ │ + * another feature). │ │ │ │ │ */ │ │ │ │ │ - preserveCenter: false, │ │ │ │ │ + standalone: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the pinch handler │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PinchZoom │ │ │ │ │ - * Create a control for zooming with pinch gestures. This works on devices │ │ │ │ │ - * with multi-touch support. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} Feature currently available for modification. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.handler = new OpenLayers.Handler.Pinch(this, { │ │ │ │ │ - start: this.pinchStart, │ │ │ │ │ - move: this.pinchMove, │ │ │ │ │ - done: this.pinchDone │ │ │ │ │ - }, this.handlerOptions); │ │ │ │ │ - }, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: pinchStart │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ - * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ + * Property: vertex │ │ │ │ │ + * {} Vertex currently being modified. │ │ │ │ │ */ │ │ │ │ │ - pinchStart: function(evt, pinchData) { │ │ │ │ │ - var xy = (this.preserveCenter) ? │ │ │ │ │ - this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ - this.pinchOrigin = xy; │ │ │ │ │ - this.currentCenter = xy; │ │ │ │ │ - }, │ │ │ │ │ + vertex: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: pinchMove │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ - * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ + * Property: vertices │ │ │ │ │ + * {Array()} Verticies currently available │ │ │ │ │ + * for dragging. │ │ │ │ │ */ │ │ │ │ │ - pinchMove: function(evt, pinchData) { │ │ │ │ │ - var scale = pinchData.scale; │ │ │ │ │ - var containerOrigin = this.map.layerContainerOriginPx; │ │ │ │ │ - var pinchOrigin = this.pinchOrigin; │ │ │ │ │ - var current = (this.preserveCenter) ? │ │ │ │ │ - this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ + vertices: null, │ │ │ │ │ │ │ │ │ │ - var dx = Math.round((containerOrigin.x + current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x)); │ │ │ │ │ - var dy = Math.round((containerOrigin.y + current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y)); │ │ │ │ │ + /** │ │ │ │ │ + * Property: virtualVertices │ │ │ │ │ + * {Array()} Virtual vertices in the middle │ │ │ │ │ + * of each edge. │ │ │ │ │ + */ │ │ │ │ │ + virtualVertices: null, │ │ │ │ │ │ │ │ │ │ - this.map.applyTransform(dx, dy, scale); │ │ │ │ │ - this.currentCenter = current; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: handlers │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + handlers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: pinchDone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * start - {Object} pinch data object related to the touchstart event that │ │ │ │ │ - * started the pinch gesture. │ │ │ │ │ - * last - {Object} pinch data object related to the last touchmove event │ │ │ │ │ - * of the pinch gesture. This give us the final scale of the pinch. │ │ │ │ │ + * APIProperty: deleteCodes │ │ │ │ │ + * {Array(Integer)} Keycodes for deleting verticies. Set to null to disable │ │ │ │ │ + * vertex deltion by keypress. If non-null, keypresses with codes │ │ │ │ │ + * in this array will delete vertices under the mouse. Default │ │ │ │ │ + * is 46 and 68, the 'delete' and lowercase 'd' keys. │ │ │ │ │ */ │ │ │ │ │ - pinchDone: function(evt, start, last) { │ │ │ │ │ - this.map.applyTransform(); │ │ │ │ │ - var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true); │ │ │ │ │ - if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) { │ │ │ │ │ - var resolution = this.map.getResolutionForZoom(zoom); │ │ │ │ │ + deleteCodes: null, │ │ │ │ │ │ │ │ │ │ - var location = this.map.getLonLatFromPixel(this.pinchOrigin); │ │ │ │ │ - var zoomPixel = this.currentCenter; │ │ │ │ │ - var size = this.map.getSize(); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: virtualStyle │ │ │ │ │ + * {Object} A symbolizer to be used for virtual vertices. │ │ │ │ │ + */ │ │ │ │ │ + virtualStyle: null, │ │ │ │ │ │ │ │ │ │ - location.lon += resolution * ((size.w / 2) - zoomPixel.x); │ │ │ │ │ - location.lat -= resolution * ((size.h / 2) - zoomPixel.y); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: vertexRenderIntent │ │ │ │ │ + * {String} The renderIntent to use for vertices. If no is │ │ │ │ │ + * provided, this renderIntent will also be used for virtual vertices, with │ │ │ │ │ + * a fillOpacity and strokeOpacity of 0.3. Default is null, which means │ │ │ │ │ + * that the layer's default style will be used for vertices. │ │ │ │ │ + */ │ │ │ │ │ + vertexRenderIntent: null, │ │ │ │ │ │ │ │ │ │ - // Force a reflow before calling setCenter. This is to work │ │ │ │ │ - // around an issue occuring in iOS. │ │ │ │ │ - // │ │ │ │ │ - // See https://github.com/openlayers/openlayers/pull/351. │ │ │ │ │ - // │ │ │ │ │ - // Without a reflow setting the layer container div's top left │ │ │ │ │ - // style properties to "0px" - as done in Map.moveTo when zoom │ │ │ │ │ - // is changed - won't actually correctly reposition the layer │ │ │ │ │ - // container div. │ │ │ │ │ - // │ │ │ │ │ - // Also, we need to use a statement that the Google Closure │ │ │ │ │ - // compiler won't optimize away. │ │ │ │ │ - this.map.div.clientWidth = this.map.div.clientWidth; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: mode │ │ │ │ │ + * {Integer} Bitfields specifying the modification mode. Defaults to │ │ │ │ │ + * OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a │ │ │ │ │ + * combination of options, use the | operator. For example, to allow │ │ │ │ │ + * the control to both resize and rotate features, use the following │ │ │ │ │ + * syntax │ │ │ │ │ + * (code) │ │ │ │ │ + * control.mode = OpenLayers.Control.ModifyFeature.RESIZE | │ │ │ │ │ + * OpenLayers.Control.ModifyFeature.ROTATE; │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + mode: null, │ │ │ │ │ │ │ │ │ │ - this.map.setCenter(location, zoom); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: createVertices │ │ │ │ │ + * {Boolean} Create new vertices by dragging the virtual vertices │ │ │ │ │ + * in the middle of each edge. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + createVertices: true, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PinchZoom" │ │ │ │ │ + /** │ │ │ │ │ + * Property: modified │ │ │ │ │ + * {Boolean} The currently selected feature has been modified. │ │ │ │ │ + */ │ │ │ │ │ + modified: false, │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomIn.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: radiusHandle │ │ │ │ │ + * {} A handle for rotating/resizing a feature. │ │ │ │ │ + */ │ │ │ │ │ + radiusHandle: 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: dragHandle │ │ │ │ │ + * {} A handle for dragging a feature. │ │ │ │ │ + */ │ │ │ │ │ + dragHandle: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: onModificationStart │ │ │ │ │ + * {Function} *Deprecated*. Register for "beforefeaturemodified" instead. │ │ │ │ │ + * The "beforefeaturemodified" event is triggered on the layer before │ │ │ │ │ + * any modification begins. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature is selected │ │ │ │ │ + * to be modified. The function should expect to be called with a │ │ │ │ │ + * feature. This could be used for example to allow to lock the │ │ │ │ │ + * feature on server-side. │ │ │ │ │ + */ │ │ │ │ │ + onModificationStart: function() {}, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomIn │ │ │ │ │ - * The ZoomIn control is a button to increase the zoom level of a map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomIn = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: onModification │ │ │ │ │ + * {Function} *Deprecated*. Register for "featuremodified" instead. │ │ │ │ │ + * The "featuremodified" event is triggered on the layer with each │ │ │ │ │ + * feature modification. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature has been │ │ │ │ │ + * modified. The function should expect to be called with a feature. │ │ │ │ │ + */ │ │ │ │ │ + onModification: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ + * APIProperty: onModificationEnd │ │ │ │ │ + * {Function} *Deprecated*. Register for "afterfeaturemodified" instead. │ │ │ │ │ + * The "afterfeaturemodified" event is triggered on the layer after │ │ │ │ │ + * a feature has been modified. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature is finished │ │ │ │ │ + * being modified. The function should expect to be called with a │ │ │ │ │ + * feature. │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + onModificationEnd: function() {}, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomIn" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DragPan.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.ModifyFeature │ │ │ │ │ + * Create a new modify feature control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} Layer that contains features that │ │ │ │ │ + * will be modified. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * control. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + this.virtualStyle = OpenLayers.Util.extend({}, │ │ │ │ │ + this.layer.style || │ │ │ │ │ + this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent) │ │ │ │ │ + ); │ │ │ │ │ + this.virtualStyle.fillOpacity = 0.3; │ │ │ │ │ + this.virtualStyle.strokeOpacity = 0.3; │ │ │ │ │ + this.deleteCodes = [46, 68]; │ │ │ │ │ + this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + if (!(OpenLayers.Util.isArray(this.deleteCodes))) { │ │ │ │ │ + this.deleteCodes = [this.deleteCodes]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + // configure the drag handler │ │ │ │ │ + var dragCallbacks = { │ │ │ │ │ + down: function(pixel) { │ │ │ │ │ + this.vertex = null; │ │ │ │ │ + var feature = this.layer.getFeatureFromEvent( │ │ │ │ │ + this.handlers.drag.evt); │ │ │ │ │ + if (feature) { │ │ │ │ │ + this.dragStart(feature); │ │ │ │ │ + } else if (this.clickout) { │ │ │ │ │ + this._unselect = this.feature; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + move: function(pixel) { │ │ │ │ │ + delete this._unselect; │ │ │ │ │ + if (this.vertex) { │ │ │ │ │ + this.dragVertex(this.vertex, pixel); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + up: function() { │ │ │ │ │ + this.handlers.drag.stopDown = false; │ │ │ │ │ + if (this._unselect) { │ │ │ │ │ + this.unselectFeature(this._unselect); │ │ │ │ │ + delete this._unselect; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + done: function(pixel) { │ │ │ │ │ + if (this.vertex) { │ │ │ │ │ + this.dragComplete(this.vertex); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + var dragOptions = { │ │ │ │ │ + documentDrag: this.documentDrag, │ │ │ │ │ + stopDown: false │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - */ │ │ │ │ │ + // configure the keyboard handler │ │ │ │ │ + var keyboardOptions = { │ │ │ │ │ + keydown: this.handleKeypress │ │ │ │ │ + }; │ │ │ │ │ + this.handlers = { │ │ │ │ │ + keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions), │ │ │ │ │ + drag: new OpenLayers.Handler.Drag(this, dragCallbacks, dragOptions) │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.DragPan │ │ │ │ │ - * The DragPan control pans the map with a drag of the mouse. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Take care of things that are not handled in superclass. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + this.layer = null; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPES} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully activated the control. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + activate: function() { │ │ │ │ │ + this.moveLayerToTop(); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + return (this.handlers.keyboard.activate() && │ │ │ │ │ + this.handlers.drag.activate() && │ │ │ │ │ + OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: panned │ │ │ │ │ - * {Boolean} The map moved. │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully deactivated the control. │ │ │ │ │ */ │ │ │ │ │ - panned: false, │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + // the return from the controls is unimportant in this case │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.moveLayerBack(); │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + this.handlers.keyboard.deactivate(); │ │ │ │ │ + var feature = this.feature; │ │ │ │ │ + if (feature && feature.geometry && feature.layer) { │ │ │ │ │ + this.unselectFeature(feature); │ │ │ │ │ + } │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} The number of milliseconds that should ellapse before │ │ │ │ │ - * panning the map again. Defaults to 0 milliseconds, which means that │ │ │ │ │ - * no separate cycle is used for panning. In most cases you won't want │ │ │ │ │ - * to change this value. For slow machines/devices larger values can be │ │ │ │ │ - * tried out. │ │ │ │ │ + * Method: beforeSelectFeature │ │ │ │ │ + * Called before a feature is selected. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature about to be selected. │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + beforeSelectFeature: function(feature) { │ │ │ │ │ + return this.layer.events.triggerEvent( │ │ │ │ │ + "beforefeaturemodified", { │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ - * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ + * APIMethod: selectFeature │ │ │ │ │ + * Select a feature for modification in standalone mode. In non-standalone │ │ │ │ │ + * mode, this method is called when a feature is selected by clicking. │ │ │ │ │ + * Register a listener to the beforefeaturemodified event and return false │ │ │ │ │ + * to prevent feature modification. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} the selected feature. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + selectFeature: function(feature) { │ │ │ │ │ + if (this.feature === feature || │ │ │ │ │ + (this.geometryTypes && OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ + feature.geometry.CLASS_NAME) == -1)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.beforeSelectFeature(feature) !== false) { │ │ │ │ │ + if (this.feature) { │ │ │ │ │ + this.unselectFeature(this.feature); │ │ │ │ │ + } │ │ │ │ │ + this.feature = feature; │ │ │ │ │ + this.layer.selectedFeatures.push(feature); │ │ │ │ │ + this.layer.drawFeature(feature, 'select'); │ │ │ │ │ + this.modified = false; │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.onModificationStart(this.feature); │ │ │ │ │ + } │ │ │ │ │ + // keep track of geometry modifications │ │ │ │ │ + var modified = feature.modified; │ │ │ │ │ + if (feature.geometry && !(modified && modified.geometry)) { │ │ │ │ │ + this._originalGeometry = feature.geometry.clone(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: kinetic │ │ │ │ │ - * {} The OpenLayers.Kinetic object. │ │ │ │ │ + * APIMethod: unselectFeature │ │ │ │ │ + * Called when the select feature control unselects a feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The unselected feature. │ │ │ │ │ */ │ │ │ │ │ - kinetic: null, │ │ │ │ │ + unselectFeature: function(feature) { │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + if (this.dragHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + delete this.dragHandle; │ │ │ │ │ + } │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + delete this.radiusHandle; │ │ │ │ │ + } │ │ │ │ │ + this.layer.drawFeature(this.feature, 'default'); │ │ │ │ │ + this.feature = null; │ │ │ │ │ + OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); │ │ │ │ │ + this.onModificationEnd(feature); │ │ │ │ │ + this.layer.events.triggerEvent("afterfeaturemodified", { │ │ │ │ │ + feature: feature, │ │ │ │ │ + modified: this.modified │ │ │ │ │ + }); │ │ │ │ │ + this.modified = false; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: enableKinetic │ │ │ │ │ - * {Boolean} Set this option to enable "kinetic dragging". Can be │ │ │ │ │ - * set to true or to an object. If set to an object this │ │ │ │ │ - * object will be passed to the {} │ │ │ │ │ - * constructor. Defaults to true. │ │ │ │ │ - * To get kinetic dragging, ensure that OpenLayers/Kinetic.js is │ │ │ │ │ - * included in your build config. │ │ │ │ │ + * Method: dragStart │ │ │ │ │ + * Called by the drag handler before a feature is dragged. This method is │ │ │ │ │ + * used to differentiate between points and vertices │ │ │ │ │ + * of higher order geometries. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The point or vertex about to be │ │ │ │ │ + * dragged. │ │ │ │ │ */ │ │ │ │ │ - enableKinetic: true, │ │ │ │ │ + dragStart: function(feature) { │ │ │ │ │ + var isPoint = feature.geometry.CLASS_NAME == │ │ │ │ │ + 'OpenLayers.Geometry.Point'; │ │ │ │ │ + if (!this.standalone && │ │ │ │ │ + ((!feature._sketch && isPoint) || !feature._sketch)) { │ │ │ │ │ + if (this.toggle && this.feature === feature) { │ │ │ │ │ + // mark feature for unselection │ │ │ │ │ + this._unselect = feature; │ │ │ │ │ + } │ │ │ │ │ + this.selectFeature(feature); │ │ │ │ │ + } │ │ │ │ │ + if (feature._sketch || isPoint) { │ │ │ │ │ + // feature is a drag or virtual handle or point │ │ │ │ │ + this.vertex = feature; │ │ │ │ │ + this.handlers.drag.stopDown = true; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: kineticInterval │ │ │ │ │ - * {Integer} Interval in milliseconds between 2 steps in the "kinetic │ │ │ │ │ - * scrolling". Applies only if enableKinetic is set. Defaults │ │ │ │ │ - * to 10 milliseconds. │ │ │ │ │ + * Method: dragVertex │ │ │ │ │ + * Called by the drag handler with each drag move of a vertex. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * vertex - {} The vertex being dragged. │ │ │ │ │ + * pixel - {} Pixel location of the mouse event. │ │ │ │ │ */ │ │ │ │ │ - kineticInterval: 10, │ │ │ │ │ + dragVertex: function(vertex, pixel) { │ │ │ │ │ + var pos = this.map.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + var geom = vertex.geometry; │ │ │ │ │ + geom.move(pos.lon - geom.x, pos.lat - geom.y); │ │ │ │ │ + this.modified = true; │ │ │ │ │ + /** │ │ │ │ │ + * Five cases: │ │ │ │ │ + * 1) dragging a simple point │ │ │ │ │ + * 2) dragging a virtual vertex │ │ │ │ │ + * 3) dragging a drag handle │ │ │ │ │ + * 4) dragging a real vertex │ │ │ │ │ + * 5) dragging a radius handle │ │ │ │ │ + */ │ │ │ │ │ + if (this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + // dragging a simple point │ │ │ │ │ + this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: pixel │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + if (vertex._index) { │ │ │ │ │ + // dragging a virtual vertex │ │ │ │ │ + vertex.geometry.parent.addComponent(vertex.geometry, │ │ │ │ │ + vertex._index); │ │ │ │ │ + // move from virtual to real vertex │ │ │ │ │ + delete vertex._index; │ │ │ │ │ + OpenLayers.Util.removeItem(this.virtualVertices, vertex); │ │ │ │ │ + this.vertices.push(vertex); │ │ │ │ │ + } else if (vertex == this.dragHandle) { │ │ │ │ │ + // dragging a drag handle │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.radiusHandle = null; │ │ │ │ │ + } │ │ │ │ │ + } else if (vertex !== this.radiusHandle) { │ │ │ │ │ + // dragging a real vertex │ │ │ │ │ + this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: pixel │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + // dragging a radius handle - no special treatment │ │ │ │ │ + if (this.virtualVertices.length > 0) { │ │ │ │ │ + this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + } │ │ │ │ │ + this.layer.drawFeature(this.feature, this.standalone ? undefined : │ │ │ │ │ + 'select'); │ │ │ │ │ + } │ │ │ │ │ + // keep the vertex on top so it gets the mouseout after dragging │ │ │ │ │ + // this should be removed in favor of an option to draw under or │ │ │ │ │ + // maintain node z-index │ │ │ │ │ + this.layer.drawFeature(vertex); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Method: dragComplete │ │ │ │ │ + * Called by the drag handler when the feature dragging is complete. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * vertex - {} The vertex being dragged. │ │ │ │ │ + */ │ │ │ │ │ + dragComplete: function(vertex) { │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.setFeatureState(); │ │ │ │ │ + this.onModification(this.feature); │ │ │ │ │ + this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ + feature: this.feature │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Creates a Drag handler, using and │ │ │ │ │ - * as callbacks. │ │ │ │ │ + * Method: setFeatureState │ │ │ │ │ + * Called when the feature is modified. If the current state is not │ │ │ │ │ + * INSERT or DELETE, the state is set to UPDATE. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - if (this.enableKinetic && OpenLayers.Kinetic) { │ │ │ │ │ - var config = { │ │ │ │ │ - interval: this.kineticInterval │ │ │ │ │ - }; │ │ │ │ │ - if (typeof this.enableKinetic === "object") { │ │ │ │ │ - config = OpenLayers.Util.extend(config, this.enableKinetic); │ │ │ │ │ + setFeatureState: function() { │ │ │ │ │ + if (this.feature.state != OpenLayers.State.INSERT && │ │ │ │ │ + this.feature.state != OpenLayers.State.DELETE) { │ │ │ │ │ + this.feature.state = OpenLayers.State.UPDATE; │ │ │ │ │ + if (this.modified && this._originalGeometry) { │ │ │ │ │ + var feature = this.feature; │ │ │ │ │ + feature.modified = OpenLayers.Util.extend(feature.modified, { │ │ │ │ │ + geometry: this._originalGeometry │ │ │ │ │ + }); │ │ │ │ │ + delete this._originalGeometry; │ │ │ │ │ } │ │ │ │ │ - this.kinetic = new OpenLayers.Kinetic(config); │ │ │ │ │ } │ │ │ │ │ - this.handler = new OpenLayers.Handler.Drag(this, { │ │ │ │ │ - "move": this.panMap, │ │ │ │ │ - "done": this.panMapDone, │ │ │ │ │ - "down": this.panMapStart │ │ │ │ │ - }, { │ │ │ │ │ - interval: this.interval, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMapStart │ │ │ │ │ + * Method: resetVertices │ │ │ │ │ */ │ │ │ │ │ - panMapStart: function() { │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - this.kinetic.begin(); │ │ │ │ │ + resetVertices: function() { │ │ │ │ │ + if (this.vertices.length > 0) { │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + } │ │ │ │ │ + if (this.virtualVertices.length > 0) { │ │ │ │ │ + this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + } │ │ │ │ │ + if (this.dragHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.dragHandle = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.radiusHandle = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.feature && │ │ │ │ │ + this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { │ │ │ │ │ + if ((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { │ │ │ │ │ + this.collectDragHandle(); │ │ │ │ │ + } │ │ │ │ │ + if ((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | │ │ │ │ │ + OpenLayers.Control.ModifyFeature.RESIZE))) { │ │ │ │ │ + this.collectRadiusHandle(); │ │ │ │ │ + } │ │ │ │ │ + if (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE) { │ │ │ │ │ + // Don't collect vertices when we're resizing │ │ │ │ │ + if (!(this.mode & OpenLayers.Control.ModifyFeature.RESIZE)) { │ │ │ │ │ + this.collectVertices(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMap │ │ │ │ │ + * Method: handleKeypress │ │ │ │ │ + * Called by the feature handler on keypress. This is used to delete │ │ │ │ │ + * vertices. If the property is set, vertices will │ │ │ │ │ + * be deleted when a feature is selected for modification and │ │ │ │ │ + * the mouse is over a vertex. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} Pixel of the mouse position │ │ │ │ │ + * evt - {Event} Keypress event. │ │ │ │ │ */ │ │ │ │ │ - panMap: function(xy) { │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - this.kinetic.update(xy); │ │ │ │ │ + handleKeypress: function(evt) { │ │ │ │ │ + var code = evt.keyCode; │ │ │ │ │ + │ │ │ │ │ + // check for delete key │ │ │ │ │ + if (this.feature && │ │ │ │ │ + OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { │ │ │ │ │ + var vertex = this.layer.getFeatureFromEvent(this.handlers.drag.evt); │ │ │ │ │ + if (vertex && │ │ │ │ │ + OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && │ │ │ │ │ + !this.handlers.drag.dragging && vertex.geometry.parent) { │ │ │ │ │ + // remove the vertex │ │ │ │ │ + vertex.geometry.parent.removeComponent(vertex.geometry); │ │ │ │ │ + this.layer.events.triggerEvent("vertexremoved", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: evt.xy │ │ │ │ │ + }); │ │ │ │ │ + this.layer.drawFeature(this.feature, this.standalone ? │ │ │ │ │ + undefined : 'select'); │ │ │ │ │ + this.modified = true; │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.setFeatureState(); │ │ │ │ │ + this.onModification(this.feature); │ │ │ │ │ + this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ + feature: this.feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.panned = true; │ │ │ │ │ - this.map.pan( │ │ │ │ │ - this.handler.last.x - xy.x, │ │ │ │ │ - this.handler.last.y - xy.y, { │ │ │ │ │ - dragging: true, │ │ │ │ │ - animate: false │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: collectVertices │ │ │ │ │ + * Collect the vertices from the modifiable feature's geometry and push │ │ │ │ │ + * them on to the control's vertices array. │ │ │ │ │ + */ │ │ │ │ │ + collectVertices: function() { │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + var control = this; │ │ │ │ │ + │ │ │ │ │ + function collectComponentVertices(geometry) { │ │ │ │ │ + var i, vertex, component, len; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + vertex = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + vertex._sketch = true; │ │ │ │ │ + vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ + control.vertices.push(vertex); │ │ │ │ │ + } else { │ │ │ │ │ + var numVert = geometry.components.length; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ + numVert -= 1; │ │ │ │ │ + } │ │ │ │ │ + for (i = 0; i < numVert; ++i) { │ │ │ │ │ + component = geometry.components[i]; │ │ │ │ │ + if (component.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + vertex = new OpenLayers.Feature.Vector(component); │ │ │ │ │ + vertex._sketch = true; │ │ │ │ │ + vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ + control.vertices.push(vertex); │ │ │ │ │ + } else { │ │ │ │ │ + collectComponentVertices(component); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // add virtual vertices in the middle of each edge │ │ │ │ │ + if (control.createVertices && geometry.CLASS_NAME != "OpenLayers.Geometry.MultiPoint") { │ │ │ │ │ + for (i = 0, len = geometry.components.length; i < len - 1; ++i) { │ │ │ │ │ + var prevVertex = geometry.components[i]; │ │ │ │ │ + var nextVertex = geometry.components[i + 1]; │ │ │ │ │ + if (prevVertex.CLASS_NAME == "OpenLayers.Geometry.Point" && │ │ │ │ │ + nextVertex.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + var x = (prevVertex.x + nextVertex.x) / 2; │ │ │ │ │ + var y = (prevVertex.y + nextVertex.y) / 2; │ │ │ │ │ + var point = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ + null, control.virtualStyle │ │ │ │ │ + ); │ │ │ │ │ + // set the virtual parent and intended index │ │ │ │ │ + point.geometry.parent = geometry; │ │ │ │ │ + point._index = i + 1; │ │ │ │ │ + point._sketch = true; │ │ │ │ │ + control.virtualVertices.push(point); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + } │ │ │ │ │ + collectComponentVertices.call(this, this.feature.geometry); │ │ │ │ │ + this.layer.addFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.layer.addFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: collectDragHandle │ │ │ │ │ + * Collect the drag handle for the selected geometry. │ │ │ │ │ + */ │ │ │ │ │ + collectDragHandle: function() { │ │ │ │ │ + var geometry = this.feature.geometry; │ │ │ │ │ + var center = geometry.getBounds().getCenterLonLat(); │ │ │ │ │ + var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ ); │ │ │ │ │ + var origin = new OpenLayers.Feature.Vector(originGeometry); │ │ │ │ │ + originGeometry.move = function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + geometry.move(x, y); │ │ │ │ │ + }; │ │ │ │ │ + origin._sketch = true; │ │ │ │ │ + this.dragHandle = origin; │ │ │ │ │ + this.dragHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ + this.layer.addFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMapDone │ │ │ │ │ - * Finish the panning operation. Only call setCenter (through ) │ │ │ │ │ - * if the map has actually been moved. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} Pixel of the mouse position │ │ │ │ │ + * Method: collectRadiusHandle │ │ │ │ │ + * Collect the radius handle for the selected geometry. │ │ │ │ │ */ │ │ │ │ │ - panMapDone: function(xy) { │ │ │ │ │ - if (this.panned) { │ │ │ │ │ - var res = null; │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - res = this.kinetic.end(xy); │ │ │ │ │ + collectRadiusHandle: function() { │ │ │ │ │ + var geometry = this.feature.geometry; │ │ │ │ │ + var bounds = geometry.getBounds(); │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ + ); │ │ │ │ │ + var radiusGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + bounds.right, bounds.bottom │ │ │ │ │ + ); │ │ │ │ │ + var radius = new OpenLayers.Feature.Vector(radiusGeometry); │ │ │ │ │ + var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE); │ │ │ │ │ + var reshape = (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE); │ │ │ │ │ + var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE); │ │ │ │ │ + │ │ │ │ │ + radiusGeometry.move = function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + var dx1 = this.x - originGeometry.x; │ │ │ │ │ + var dy1 = this.y - originGeometry.y; │ │ │ │ │ + var dx0 = dx1 - x; │ │ │ │ │ + var dy0 = dy1 - y; │ │ │ │ │ + if (rotate) { │ │ │ │ │ + var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ + var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ + var angle = a1 - a0; │ │ │ │ │ + angle *= 180 / Math.PI; │ │ │ │ │ + geometry.rotate(angle, originGeometry); │ │ │ │ │ } │ │ │ │ │ - this.map.pan( │ │ │ │ │ - this.handler.last.x - xy.x, │ │ │ │ │ - this.handler.last.y - xy.y, { │ │ │ │ │ - dragging: !!res, │ │ │ │ │ - animate: false │ │ │ │ │ + if (resize) { │ │ │ │ │ + var scale, ratio; │ │ │ │ │ + // 'resize' together with 'reshape' implies that the aspect │ │ │ │ │ + // ratio of the geometry will not be preserved whilst resizing │ │ │ │ │ + if (reshape) { │ │ │ │ │ + scale = dy1 / dy0; │ │ │ │ │ + ratio = (dx1 / dx0) / scale; │ │ │ │ │ + } else { │ │ │ │ │ + var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ + var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ + scale = l1 / l0; │ │ │ │ │ } │ │ │ │ │ - ); │ │ │ │ │ - if (res) { │ │ │ │ │ - var self = this; │ │ │ │ │ - this.kinetic.move(res, function(x, y, end) { │ │ │ │ │ - self.map.pan(x, y, { │ │ │ │ │ - dragging: !end, │ │ │ │ │ - animate: false │ │ │ │ │ - }); │ │ │ │ │ - }); │ │ │ │ │ + geometry.resize(scale, originGeometry, ratio); │ │ │ │ │ } │ │ │ │ │ - this.panned = false; │ │ │ │ │ + }; │ │ │ │ │ + radius._sketch = true; │ │ │ │ │ + this.radiusHandle = radius; │ │ │ │ │ + this.radiusHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ + this.layer.addFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control and all handlers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} The control's map. │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.handlers.drag.setMap(map); │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleMapEvents │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} │ │ │ │ │ + */ │ │ │ │ │ + handleMapEvents: function(evt) { │ │ │ │ │ + if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ + this.moveLayerToTop(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DragPan" │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveLayerToTop │ │ │ │ │ + * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ + * it. │ │ │ │ │ + */ │ │ │ │ │ + moveLayerToTop: function() { │ │ │ │ │ + var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ + this.layer.getZIndex()) + 1; │ │ │ │ │ + this.layer.setZIndex(index); │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveLayerBack │ │ │ │ │ + * Moves the layer back to the position determined by the map's layers │ │ │ │ │ + * array. │ │ │ │ │ + */ │ │ │ │ │ + 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)); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ModifyFeature" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: RESHAPE │ │ │ │ │ + * {Integer} Constant used to make the control work in reshape mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.RESHAPE = 1; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: RESIZE │ │ │ │ │ + * {Integer} Constant used to make the control work in resize mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.RESIZE = 2; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: ROTATE │ │ │ │ │ + * {Integer} Constant used to make the control work in rotate mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.ROTATE = 4; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: DRAG │ │ │ │ │ + * {Integer} Constant used to make the control work in drag mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.DRAG = 8; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Events/buttonclick.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 │ │ │ │ │ @@ -42110,113 +38683,14 @@ │ │ │ │ │ return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.Panel" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Pan.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/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Pan │ │ │ │ │ - * The Pan control is a single button to pan the map in one direction. For │ │ │ │ │ - * a more complete control see . │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ - * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ - * by some ratio of the map dimensions, use instead. │ │ │ │ │ - */ │ │ │ │ │ - slideFactor: 50, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideRatio │ │ │ │ │ - * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ - * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ - * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ - * pan up half the map height. │ │ │ │ │ - */ │ │ │ │ │ - slideRatio: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: direction │ │ │ │ │ - * {String} in {'North', 'South', 'East', 'West'} │ │ │ │ │ - */ │ │ │ │ │ - direction: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Pan │ │ │ │ │ - * Control which handles the panning (in any of the cardinal directions) │ │ │ │ │ - * of the map by a set px distance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * direction - {String} The direction this button should pan. │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(direction, options) { │ │ │ │ │ - │ │ │ │ │ - this.direction = direction; │ │ │ │ │ - this.CLASS_NAME += this.direction; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ - */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var getSlideFactor = OpenLayers.Function.bind(function(dim) { │ │ │ │ │ - return this.slideRatio ? │ │ │ │ │ - this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ - this.slideFactor; │ │ │ │ │ - }, this); │ │ │ │ │ - │ │ │ │ │ - switch (this.direction) { │ │ │ │ │ - case OpenLayers.Control.Pan.NORTH: │ │ │ │ │ - this.map.pan(0, -getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.SOUTH: │ │ │ │ │ - this.map.pan(0, getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.WEST: │ │ │ │ │ - this.map.pan(-getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.EAST: │ │ │ │ │ - this.map.pan(getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Pan" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Control.Pan.NORTH = "North"; │ │ │ │ │ -OpenLayers.Control.Pan.SOUTH = "South"; │ │ │ │ │ -OpenLayers.Control.Pan.EAST = "East"; │ │ │ │ │ -OpenLayers.Control.Pan.WEST = "West"; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/Control/PanPanel.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. */ │ │ │ │ │ @@ -42286,6768 +38760,3458 @@ │ │ │ │ │ new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST, options) │ │ │ │ │ ]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.PanPanel" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomOut.js │ │ │ │ │ + OpenLayers/Handler/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/Control/Button.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomOut │ │ │ │ │ - * The ZoomOut control is a button to decrease the zoom level of a map. │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * This handler stops event propagation for mousedown and mouseup if those │ │ │ │ │ + * browser events target features that can be selected. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ZoomOut = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ +OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ + * Property: EVENTMAP │ │ │ │ │ + * {Object} A object mapping the browser events to objects with callback │ │ │ │ │ + * keys for in and out. │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + 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' │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomOut" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} The last feature that was hovered. │ │ │ │ │ + */ │ │ │ │ │ + feature: 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: lastFeature │ │ │ │ │ + * {} The last feature that was handled. │ │ │ │ │ + */ │ │ │ │ │ + lastFeature: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: down │ │ │ │ │ + * {} The location of the last mousedown. │ │ │ │ │ + */ │ │ │ │ │ + down: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomToMaxExtent │ │ │ │ │ - * The ZoomToMaxExtent control is a button that zooms out to the maximum │ │ │ │ │ - * extent of the map. It is designed to be used with a │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomToMaxExtent = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: up │ │ │ │ │ + * {} The location of the last mouseup. │ │ │ │ │ + */ │ │ │ │ │ + up: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ - * │ │ │ │ │ - * Called whenever this control is being rendered inside of a panel and a │ │ │ │ │ - * click occurs on this controls element. Actually zooms to the maximum │ │ │ │ │ - * extent of this controls map. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomToMaxExtent(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + clickTolerance: 4, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomToMaxExtent" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomPanel.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + */ │ │ │ │ │ + geometryTypes: 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: 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. │ │ │ │ │ + */ │ │ │ │ │ + stopClick: true, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomIn.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomOut.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + stopDown: true, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomPanel │ │ │ │ │ - * The ZoomPanel control is a compact collecton of 3 zoom controls: a │ │ │ │ │ - * , a , and a │ │ │ │ │ - * . By default it is drawn in the upper left │ │ │ │ │ - * corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you wish to use this class with the default images and you want │ │ │ │ │ - * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ - * added css stylesheet to your HTML file: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + stopUp: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ZoomPanel │ │ │ │ │ - * Add the three zooming controls. │ │ │ │ │ + * Constructor: OpenLayers.Handler.Feature │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.addControls([ │ │ │ │ │ - new OpenLayers.Control.ZoomIn(), │ │ │ │ │ - new OpenLayers.Control.ZoomToMaxExtent(), │ │ │ │ │ - new OpenLayers.Control.ZoomOut() │ │ │ │ │ - ]); │ │ │ │ │ + initialize: function(control, layer, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, [control, callbacks, options]); │ │ │ │ │ + this.layer = layer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomPanel" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Zoom.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Zoom │ │ │ │ │ - * The Zoom control is a pair of +/- links for zooming in and out. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Zoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomInText │ │ │ │ │ - * {String} │ │ │ │ │ - * Text for zoom-in link. Default is "+". │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - zoomInText: "+", │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + return OpenLayers.Event.isMultiTouch(evt) ? │ │ │ │ │ + true : this.mousedown(evt); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomInId │ │ │ │ │ - * {String} │ │ │ │ │ - * Instead of having the control create a zoom in link, you can provide │ │ │ │ │ - * the identifier for an anchor element already added to the document. │ │ │ │ │ - * By default, an element with id "olZoomInLink" will be searched for │ │ │ │ │ - * and used if it exists. │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - zoomInId: "olZoomInLink", │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOutText │ │ │ │ │ - * {String} │ │ │ │ │ - * Text for zoom-out link. Default is "\u2212". │ │ │ │ │ + * Method: mousedown │ │ │ │ │ + * Handle mouse down. Stop propagation if a feature is targeted by this │ │ │ │ │ + * event (stops map dragging during feature selection). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - zoomOutText: "\u2212", │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOutId │ │ │ │ │ - * {String} │ │ │ │ │ - * Instead of having the control create a zoom out link, you can provide │ │ │ │ │ - * the identifier for an anchor element already added to the document. │ │ │ │ │ - * By default, an element with id "olZoomOutLink" will be searched for │ │ │ │ │ - * and used if it exists. │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouse up. Stop propagation if a feature is targeted by this │ │ │ │ │ + * event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - zoomOutId: "olZoomOutLink", │ │ │ │ │ + mouseup: function(evt) { │ │ │ │ │ + this.up = evt.xy; │ │ │ │ │ + return this.handle(evt) ? !this.stopUp : true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * 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} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DOMElement containing the zoom links. │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.prototype.draw.apply(this), │ │ │ │ │ - links = this.getOrCreateLinks(div), │ │ │ │ │ - zoomIn = links.zoomIn, │ │ │ │ │ - zoomOut = links.zoomOut, │ │ │ │ │ - eventsInstance = this.map.events; │ │ │ │ │ + click: function(evt) { │ │ │ │ │ + return this.handle(evt) ? !this.stopClick : true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (zoomOut.parentNode !== div) { │ │ │ │ │ - eventsInstance = this.events; │ │ │ │ │ - eventsInstance.attachToElement(zoomOut.parentNode); │ │ │ │ │ + /** │ │ │ │ │ + * 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} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + mousemove: function(evt) { │ │ │ │ │ + if (!this.callbacks['over'] && !this.callbacks['out']) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - eventsInstance.register("buttonclick", this, this.onZoomClick); │ │ │ │ │ + this.handle(evt); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.zoomInLink = zoomIn; │ │ │ │ │ - this.zoomOutLink = zoomOut; │ │ │ │ │ - return div; │ │ │ │ │ + /** │ │ │ │ │ + * Method: dblclick │ │ │ │ │ + * Handle dblclick. Call the "dblclick" callback if dblclick on a feature. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + dblclick: function(evt) { │ │ │ │ │ + return !this.handle(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getOrCreateLinks │ │ │ │ │ - * │ │ │ │ │ + * Method: geometryTypeMatches │ │ │ │ │ + * Return true if the geometry type of the passed feature matches │ │ │ │ │ + * one of the geometry types in the geometryTypes array. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * el - {DOMElement} │ │ │ │ │ + * feature - {} │ │ │ │ │ * │ │ │ │ │ - * Return: │ │ │ │ │ - * {Object} Object with zoomIn and zoomOut properties referencing links. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - getOrCreateLinks: function(el) { │ │ │ │ │ - var zoomIn = document.getElementById(this.zoomInId), │ │ │ │ │ - zoomOut = document.getElementById(this.zoomOutId); │ │ │ │ │ - if (!zoomIn) { │ │ │ │ │ - zoomIn = document.createElement("a"); │ │ │ │ │ - zoomIn.href = "#zoomIn"; │ │ │ │ │ - zoomIn.appendChild(document.createTextNode(this.zoomInText)); │ │ │ │ │ - zoomIn.className = "olControlZoomIn"; │ │ │ │ │ - el.appendChild(zoomIn); │ │ │ │ │ + geometryTypeMatches: function(feature) { │ │ │ │ │ + return this.geometryTypes == null || │ │ │ │ │ + OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ + feature.geometry.CLASS_NAME) > -1; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: handle │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The event occurred over a relevant feature. │ │ │ │ │ + */ │ │ │ │ │ + handle: function(evt) { │ │ │ │ │ + if (this.feature && !this.feature.layer) { │ │ │ │ │ + // feature has been destroyed │ │ │ │ │ + this.feature = null; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.addClass(zoomIn, "olButton"); │ │ │ │ │ - if (!zoomOut) { │ │ │ │ │ - zoomOut = document.createElement("a"); │ │ │ │ │ - zoomOut.href = "#zoomOut"; │ │ │ │ │ - zoomOut.appendChild(document.createTextNode(this.zoomOutText)); │ │ │ │ │ - zoomOut.className = "olControlZoomOut"; │ │ │ │ │ - el.appendChild(zoomOut); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.addClass(zoomOut, "olButton"); │ │ │ │ │ - return { │ │ │ │ │ - zoomIn: zoomIn, │ │ │ │ │ - zoomOut: zoomOut │ │ │ │ │ - }; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onZoomClick │ │ │ │ │ - * Called when zoomin/out link is clicked. │ │ │ │ │ + * Method: triggerCallback │ │ │ │ │ + * Call the callback keyed in the event map with the supplied arguments. │ │ │ │ │ + * For click and clickout, the is checked first. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ */ │ │ │ │ │ - onZoomClick: function(evt) { │ │ │ │ │ - var button = evt.buttonElement; │ │ │ │ │ - if (button === this.zoomInLink) { │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - } else if (button === this.zoomOutLink) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.unregister("buttonclick", this, this.onZoomClick); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - delete this.zoomInLink; │ │ │ │ │ - delete this.zoomOutLink; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Zoom" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Attribution.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/Control.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Attribution │ │ │ │ │ - * The attribution control adds attribution from layers to the map display. │ │ │ │ │ - * It uses 'attribution' property of each layer. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Attribution = │ │ │ │ │ - OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: separator │ │ │ │ │ - * {String} String used to separate layers. │ │ │ │ │ - */ │ │ │ │ │ - separator: ", ", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: template │ │ │ │ │ - * {String} Template for the attribution. This has to include the substring │ │ │ │ │ - * "${layers}", which will be replaced by the layer specific │ │ │ │ │ - * attributions, separated by . The default is "${layers}". │ │ │ │ │ - */ │ │ │ │ │ - template: "${layers}", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Attribution │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Options for control. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy control. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Turn off the handler. Returns false if the handler was already active. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + 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.updateAttribution, │ │ │ │ │ - "addlayer": this.updateAttribution, │ │ │ │ │ - "changelayer": this.updateAttribution, │ │ │ │ │ - "changebaselayer": this.updateAttribution, │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ scope: this │ │ │ │ │ }); │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Initialize control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleMapEvents │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} │ │ │ │ │ + */ │ │ │ │ │ + handleMapEvents: function(evt) { │ │ │ │ │ + if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ + this.moveLayerToTop(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - 'changebaselayer': this.updateAttribution, │ │ │ │ │ - 'changelayer': this.updateAttribution, │ │ │ │ │ - 'addlayer': this.updateAttribution, │ │ │ │ │ - 'removelayer': this.updateAttribution, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.updateAttribution(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveLayerToTop │ │ │ │ │ + * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ + * it. │ │ │ │ │ + */ │ │ │ │ │ + moveLayerToTop: function() { │ │ │ │ │ + var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ + this.layer.getZIndex()) + 1; │ │ │ │ │ + this.layer.setZIndex(index); │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateAttribution │ │ │ │ │ - * Update attribution string. │ │ │ │ │ - */ │ │ │ │ │ - updateAttribution: function() { │ │ │ │ │ - var attributions = []; │ │ │ │ │ - if (this.map && this.map.layers) { │ │ │ │ │ - for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if (layer.attribution && layer.getVisibility()) { │ │ │ │ │ - // add attribution only if attribution text is unique │ │ │ │ │ - if (OpenLayers.Util.indexOf( │ │ │ │ │ - attributions, layer.attribution) === -1) { │ │ │ │ │ - attributions.push(layer.attribution); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.div.innerHTML = OpenLayers.String.format(this.template, { │ │ │ │ │ - layers: attributions.join(this.separator) │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveLayerBack │ │ │ │ │ + * Moves the layer back to the position determined by the map's layers │ │ │ │ │ + * array. │ │ │ │ │ + */ │ │ │ │ │ + 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)); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Attribution" │ │ │ │ │ - }); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Feature" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/TouchNavigation.js │ │ │ │ │ + OpenLayers/Control/DragFeature.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/Control/DragPan.js │ │ │ │ │ - * @requires OpenLayers/Control/PinchZoom.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/Handler/Feature.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.TouchNavigation │ │ │ │ │ - * The navigation control handles map browsing with touch events (dragging, │ │ │ │ │ - * double-tapping, tap with two fingers, and pinch zoom). Create a new │ │ │ │ │ - * control with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * If you’re only targeting touch enabled devices with your mapping application, │ │ │ │ │ - * you can create a map with only a TouchNavigation control. The │ │ │ │ │ - * control is mobile ready by default, but │ │ │ │ │ - * you can generate a smaller build of the library by only including this │ │ │ │ │ - * touch navigation control if you aren't concerned about mouse interaction. │ │ │ │ │ + * Class: OpenLayers.Control.DragFeature │ │ │ │ │ + * The DragFeature control moves a feature with a drag of the mouse. Create a │ │ │ │ │ + * new control with the constructor. │ │ │ │ │ * │ │ │ │ │ - * Inherits: │ │ │ │ │ + * Inherits From: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dragPan │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: geometryTypes │ │ │ │ │ + * {Array(String)} To restrict dragging to a limited set of geometry types, │ │ │ │ │ + * send a list of strings corresponding to the geometry class names. │ │ │ │ │ */ │ │ │ │ │ - dragPan: null, │ │ │ │ │ + geometryTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dragPanOptions │ │ │ │ │ - * {Object} Options passed to the DragPan control. │ │ │ │ │ + * APIProperty: onStart │ │ │ │ │ + * {Function} Define this function if you want to know when a drag starts. │ │ │ │ │ + * The function should expect to receive two arguments: the feature │ │ │ │ │ + * that is about to be dragged and the pixel location of the mouse. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that is about to be │ │ │ │ │ + * dragged. │ │ │ │ │ + * pixel - {} The pixel location of the mouse. │ │ │ │ │ */ │ │ │ │ │ - dragPanOptions: null, │ │ │ │ │ + onStart: function(feature, pixel) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinchZoom │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: onDrag │ │ │ │ │ + * {Function} Define this function if you want to know about each move of a │ │ │ │ │ + * feature. The function should expect to receive two arguments: the │ │ │ │ │ + * feature that is being dragged and the pixel location of the mouse. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that was dragged. │ │ │ │ │ + * pixel - {} The pixel location of the mouse. │ │ │ │ │ */ │ │ │ │ │ - pinchZoom: null, │ │ │ │ │ + onDrag: function(feature, pixel) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pinchZoomOptions │ │ │ │ │ - * {Object} Options passed to the PinchZoom control. │ │ │ │ │ + * APIProperty: onComplete │ │ │ │ │ + * {Function} Define this function if you want to know when a feature is │ │ │ │ │ + * done dragging. The function should expect to receive two arguments: │ │ │ │ │ + * the feature that is being dragged and the pixel location of the │ │ │ │ │ + * mouse. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that was dragged. │ │ │ │ │ + * pixel - {} The pixel location of the mouse. │ │ │ │ │ */ │ │ │ │ │ - pinchZoomOptions: null, │ │ │ │ │ + onComplete: function(feature, pixel) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickHandlerOptions │ │ │ │ │ - * {Object} Options passed to the Click handler. │ │ │ │ │ + * APIProperty: onEnter │ │ │ │ │ + * {Function} Define this function if you want to know when the mouse │ │ │ │ │ + * goes over a feature and thereby makes this feature a candidate │ │ │ │ │ + * for dragging. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that is ready │ │ │ │ │ + * to be dragged. │ │ │ │ │ */ │ │ │ │ │ - clickHandlerOptions: null, │ │ │ │ │ + onEnter: function(feature) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: onLeave │ │ │ │ │ + * {Function} Define this function if you want to know when the mouse │ │ │ │ │ + * goes out of the feature that was dragged. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that was dragged. │ │ │ │ │ + */ │ │ │ │ │ + onLeave: function(feature) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ + * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ */ │ │ │ │ │ documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.TouchNavigation │ │ │ │ │ - * Create a new navigation control │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: dragCallbacks │ │ │ │ │ + * {Object} The functions that are sent to the drag handler for callback. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - if (this.dragPan) { │ │ │ │ │ - this.dragPan.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.dragPan = null; │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.destroy(); │ │ │ │ │ - delete this.pinchZoom; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + dragCallbacks: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Property: featureCallbacks │ │ │ │ │ + * {Object} The functions that are sent to the feature handler for callback. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragPan.activate(); │ │ │ │ │ - this.handlers.click.activate(); │ │ │ │ │ - this.pinchZoom.activate(); │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + featureCallbacks: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Property: lastPixel │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.dragPan.deactivate(); │ │ │ │ │ - this.handlers.click.deactivate(); │ │ │ │ │ - this.pinchZoom.deactivate(); │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + lastPixel: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Constructor: OpenLayers.Control.DragFeature │ │ │ │ │ + * Create a new control to drag features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} The layer containing features to be │ │ │ │ │ + * dragged. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * control. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var clickCallbacks = { │ │ │ │ │ - click: this.defaultClick, │ │ │ │ │ - dblclick: this.defaultDblClick │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.handlers = { │ │ │ │ │ + drag: new OpenLayers.Handler.Drag( │ │ │ │ │ + this, OpenLayers.Util.extend({ │ │ │ │ │ + down: this.downFeature, │ │ │ │ │ + move: this.moveFeature, │ │ │ │ │ + up: this.upFeature, │ │ │ │ │ + out: this.cancel, │ │ │ │ │ + done: this.doneDragging │ │ │ │ │ + }, this.dragCallbacks), { │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + } │ │ │ │ │ + ), │ │ │ │ │ + feature: new OpenLayers.Handler.Feature( │ │ │ │ │ + this, this.layer, OpenLayers.Util.extend({ │ │ │ │ │ + // 'click' and 'clickout' callback are for the mobile │ │ │ │ │ + // support: no 'over' or 'out' in touch based browsers. │ │ │ │ │ + click: this.clickFeature, │ │ │ │ │ + clickout: this.clickoutFeature, │ │ │ │ │ + over: this.overFeature, │ │ │ │ │ + out: this.outFeature │ │ │ │ │ + }, this.featureCallbacks), { │ │ │ │ │ + geometryTypes: this.geometryTypes │ │ │ │ │ + } │ │ │ │ │ + ) │ │ │ │ │ }; │ │ │ │ │ - var clickOptions = OpenLayers.Util.extend({ │ │ │ │ │ - "double": true, │ │ │ │ │ - stopDouble: true, │ │ │ │ │ - pixelTolerance: 2 │ │ │ │ │ - }, this.clickHandlerOptions); │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ - this, clickCallbacks, clickOptions │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }, this.dragPanOptions) │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan.draw(); │ │ │ │ │ - this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map │ │ │ │ │ - }, this.pinchZoomOptions) │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultClick │ │ │ │ │ + * Method: clickFeature │ │ │ │ │ + * Called when the feature handler detects a click-in on a feature. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * feature - {} │ │ │ │ │ */ │ │ │ │ │ - defaultClick: function(evt) { │ │ │ │ │ - if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + clickFeature: function(feature) { │ │ │ │ │ + if (this.handlers.feature.touch && !this.over && this.overFeature(feature)) { │ │ │ │ │ + this.handlers.drag.dragstart(this.handlers.feature.evt); │ │ │ │ │ + // to let the events propagate to the feature handler (click callback) │ │ │ │ │ + this.handlers.drag.stopDown = false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblClick │ │ │ │ │ + * Method: clickoutFeature │ │ │ │ │ + * Called when the feature handler detects a click-out on a feature. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * feature - {} │ │ │ │ │ */ │ │ │ │ │ - defaultDblClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + clickoutFeature: function(feature) { │ │ │ │ │ + if (this.handlers.feature.touch && this.over) { │ │ │ │ │ + this.outFeature(feature); │ │ │ │ │ + this.handlers.drag.stopDown = true; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.TouchNavigation" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DrawFeature.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.DrawFeature │ │ │ │ │ - * The DrawFeature control draws point, line or polygon features on a vector │ │ │ │ │ - * layer when active. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ - */ │ │ │ │ │ - callbacks: 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) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * featureadded - Triggered when a feature is added │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multi │ │ │ │ │ - * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ - * layer. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - multi: false, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureAdded │ │ │ │ │ - * {Function} Called after each feature is added │ │ │ │ │ - */ │ │ │ │ │ - featureAdded: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Take care of things that are not handled in superclass │ │ │ │ │ */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.layer = null; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.DrawFeature │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control and the feature handler. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * handler - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully activated the control and feature handler. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(layer, handler, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.callbacks = OpenLayers.Util.extend({ │ │ │ │ │ - done: this.drawFeature, │ │ │ │ │ - modify: function(vertex, feature) { │ │ │ │ │ - this.layer.events.triggerEvent( │ │ │ │ │ - "sketchmodified", { │ │ │ │ │ - vertex: vertex, │ │ │ │ │ - feature: feature │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - create: function(vertex, feature) { │ │ │ │ │ - this.layer.events.triggerEvent( │ │ │ │ │ - "sketchstarted", { │ │ │ │ │ - vertex: vertex, │ │ │ │ │ - feature: feature │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - this.callbacks │ │ │ │ │ - ); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.handlerOptions = this.handlerOptions || {}; │ │ │ │ │ - this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.handlerOptions.layerOptions, { │ │ │ │ │ - renderers: layer.renderers, │ │ │ │ │ - rendererOptions: layer.rendererOptions │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - if (!("multi" in this.handlerOptions)) { │ │ │ │ │ - this.handlerOptions.multi = this.multi; │ │ │ │ │ - } │ │ │ │ │ - var sketchStyle = this.layer.styleMap && this.layer.styleMap.styles.temporary; │ │ │ │ │ - if (sketchStyle) { │ │ │ │ │ - this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.handlerOptions.layerOptions, { │ │ │ │ │ - styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ - "default": sketchStyle │ │ │ │ │ - }) │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ + activate: function() { │ │ │ │ │ + return (this.handlers.feature.activate() && │ │ │ │ │ + OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control and all handlers. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully deactivated the control. │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function(geometry) { │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - var proceed = this.layer.events.triggerEvent( │ │ │ │ │ - "sketchcomplete", { │ │ │ │ │ - feature: feature │ │ │ │ │ - } │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + // the return from the handlers is unimportant in this case │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + this.handlers.feature.deactivate(); │ │ │ │ │ + this.feature = null; │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.lastPixel = null; │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, this.displayClass + "Over" │ │ │ │ │ ); │ │ │ │ │ - if (proceed !== false) { │ │ │ │ │ - feature.state = OpenLayers.State.INSERT; │ │ │ │ │ - this.layer.addFeatures([feature]); │ │ │ │ │ - this.featureAdded(feature); │ │ │ │ │ - this.events.triggerEvent("featureadded", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertXY │ │ │ │ │ - * Insert a point in the current sketch given x & y coordinates. │ │ │ │ │ + * Method: overFeature │ │ │ │ │ + * Called when the feature handler detects a mouse-over on a feature. │ │ │ │ │ + * This activates the drag handler. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * x - {Number} The x-coordinate of the point. │ │ │ │ │ - * y - {Number} The y-coordinate of the point. │ │ │ │ │ + * feature - {} The selected feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully activated the drag handler. │ │ │ │ │ */ │ │ │ │ │ - insertXY: function(x, y) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertXY(x, y); │ │ │ │ │ + overFeature: function(feature) { │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (!this.handlers.drag.dragging) { │ │ │ │ │ + this.feature = feature; │ │ │ │ │ + this.handlers.drag.activate(); │ │ │ │ │ + activated = true; │ │ │ │ │ + this.over = true; │ │ │ │ │ + OpenLayers.Element.addClass(this.map.viewPortDiv, this.displayClass + "Over"); │ │ │ │ │ + this.onEnter(feature); │ │ │ │ │ + } else { │ │ │ │ │ + if (this.feature.id == feature.id) { │ │ │ │ │ + this.over = true; │ │ │ │ │ + } else { │ │ │ │ │ + this.over = false; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertDeltaXY │ │ │ │ │ - * Insert a point given offsets from the previously inserted point. │ │ │ │ │ + * Method: downFeature │ │ │ │ │ + * Called when the drag handler detects a mouse-down. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Number} The x-coordinate offset of the point. │ │ │ │ │ - * dy - {Number} The y-coordinate offset of the point. │ │ │ │ │ + * pixel - {} Location of the mouse event. │ │ │ │ │ */ │ │ │ │ │ - insertDeltaXY: function(dx, dy) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeltaXY(dx, dy); │ │ │ │ │ - } │ │ │ │ │ + downFeature: function(pixel) { │ │ │ │ │ + this.lastPixel = pixel; │ │ │ │ │ + this.onStart(this.feature, pixel); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertDirectionLength │ │ │ │ │ - * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ - * │ │ │ │ │ + * Method: moveFeature │ │ │ │ │ + * Called when the drag handler detects a mouse-move. Also calls the │ │ │ │ │ + * optional onDrag method. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * pixel - {} Location of the mouse event. │ │ │ │ │ */ │ │ │ │ │ - insertDirectionLength: function(direction, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDirectionLength(direction, length); │ │ │ │ │ - } │ │ │ │ │ + moveFeature: function(pixel) { │ │ │ │ │ + var res = this.map.getResolution(); │ │ │ │ │ + this.feature.geometry.move(res * (pixel.x - this.lastPixel.x), │ │ │ │ │ + res * (this.lastPixel.y - pixel.y)); │ │ │ │ │ + this.layer.drawFeature(this.feature); │ │ │ │ │ + this.lastPixel = pixel; │ │ │ │ │ + this.onDrag(this.feature, pixel); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: 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. │ │ │ │ │ - * │ │ │ │ │ + * Method: upFeature │ │ │ │ │ + * Called when the drag handler detects a mouse-up. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * deflection - {Number} Degrees clockwise from the previous segment. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * pixel - {} Location of the mouse event. │ │ │ │ │ */ │ │ │ │ │ - insertDeflectionLength: function(deflection, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeflectionLength(deflection, length); │ │ │ │ │ + upFeature: function(pixel) { │ │ │ │ │ + if (!this.over) { │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: undo │ │ │ │ │ - * Remove the most recently added point in the current sketch geometry. │ │ │ │ │ + * Method: doneDragging │ │ │ │ │ + * Called when the drag handler is done dragging. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was undone. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The last event pixel location. If this event │ │ │ │ │ + * came from a mouseout, this may not be in the map viewport. │ │ │ │ │ */ │ │ │ │ │ - undo: function() { │ │ │ │ │ - return this.handler.undo && this.handler.undo(); │ │ │ │ │ + doneDragging: function(pixel) { │ │ │ │ │ + this.onComplete(this.feature, pixel); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: redo │ │ │ │ │ - * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ - * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ + * Method: outFeature │ │ │ │ │ + * Called when the feature handler detects a mouse-out on a feature. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was redone. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature that the mouse left. │ │ │ │ │ */ │ │ │ │ │ - redo: function() { │ │ │ │ │ - return this.handler.redo && this.handler.redo(); │ │ │ │ │ + outFeature: function(feature) { │ │ │ │ │ + if (!this.handlers.drag.dragging) { │ │ │ │ │ + this.over = false; │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, this.displayClass + "Over" │ │ │ │ │ + ); │ │ │ │ │ + this.onLeave(feature); │ │ │ │ │ + this.feature = null; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.feature.id == feature.id) { │ │ │ │ │ + this.over = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: finishSketch │ │ │ │ │ - * Finishes the sketch without including the currently drawn point. │ │ │ │ │ - * This method can be called to terminate drawing programmatically │ │ │ │ │ - * instead of waiting for the user to end the sketch. │ │ │ │ │ + * Method: cancel │ │ │ │ │ + * Called when the drag handler detects a mouse-out (from the map viewport). │ │ │ │ │ */ │ │ │ │ │ - finishSketch: function() { │ │ │ │ │ - this.handler.finishGeometry(); │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + this.over = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Cancel the current sketch. This removes the current sketch and keeps │ │ │ │ │ - * the drawing control active. │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control and all handlers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} The control's map. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.handler.cancel(); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.handlers.drag.setMap(map); │ │ │ │ │ + this.handlers.feature.setMap(map); │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DrawFeature" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.DragFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Snapping.js │ │ │ │ │ + OpenLayers/Control/TransformFeature.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + * @requires OpenLayers/Control/DragFeature.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Snapping │ │ │ │ │ - * Acts as a snapping agent while editing vector features. │ │ │ │ │ + * Class: OpenLayers.Control.TransformFeature │ │ │ │ │ + * Control to transform features with a standard transformation box. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ + * Inherits From: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * 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) │ │ │ │ │ * │ │ │ │ │ * Supported event types (in addition to those from ): │ │ │ │ │ - * beforesnap - Triggered before a snap occurs. Listeners receive an │ │ │ │ │ - * event object with *point*, *x*, *y*, *distance*, *layer*, and │ │ │ │ │ - * *snapType* properties. The point property will be original point │ │ │ │ │ - * geometry considered for snapping. The x and y properties represent │ │ │ │ │ - * coordinates the point will receive. The distance is the distance │ │ │ │ │ - * of the snap. The layer is the target layer. The snapType property │ │ │ │ │ - * will be one of "node", "vertex", or "edge". Return false to stop │ │ │ │ │ - * snapping from occurring. │ │ │ │ │ - * snap - Triggered when a snap occurs. Listeners receive an event with │ │ │ │ │ - * *point*, *snapType*, *layer*, and *distance* properties. The point │ │ │ │ │ - * will be the location snapped to. The snapType will be one of "node", │ │ │ │ │ - * "vertex", or "edge". The layer will be the target layer. The │ │ │ │ │ - * distance will be the distance of the snap in map units. │ │ │ │ │ - * unsnap - Triggered when a vertex is unsnapped. Listeners receive an │ │ │ │ │ - * event with a *point* property. │ │ │ │ │ + * beforesetfeature - Triggered before a feature is set for │ │ │ │ │ + * tranformation. The feature will not be set if a listener returns │ │ │ │ │ + * false. Listeners receive a *feature* property, with the feature │ │ │ │ │ + * that will be set for transformation. Listeners are allowed to │ │ │ │ │ + * set the control's *scale*, *ratio* and *rotation* properties, │ │ │ │ │ + * which will set the initial scale, ratio and rotation of the │ │ │ │ │ + * feature, like the method's initialParams argument. │ │ │ │ │ + * setfeature - Triggered when a feature is set for tranformation. │ │ │ │ │ + * Listeners receive a *feature* property, with the feature that │ │ │ │ │ + * is now set for transformation. │ │ │ │ │ + * beforetransform - Triggered while dragging, before a feature is │ │ │ │ │ + * transformed. The feature will not be transformed if a listener │ │ │ │ │ + * returns false (but the box still will). Listeners receive one or │ │ │ │ │ + * more of *center*, *scale*, *ratio* and *rotation*. The *center* │ │ │ │ │ + * property is an object with the new │ │ │ │ │ + * center of the transformed feature, the others are Floats with the │ │ │ │ │ + * scale, ratio or rotation change since the last transformation. │ │ │ │ │ + * transform - Triggered while dragging, when a feature is transformed. │ │ │ │ │ + * Listeners receive an event object with one or more of *center*, │ │ │ │ │ + * scale*, *ratio* and *rotation*. The *center* property is an │ │ │ │ │ + * object with the new center of the │ │ │ │ │ + * transformed feature, the others are Floats with the scale, ratio │ │ │ │ │ + * or rotation change of the feature since the last transformation. │ │ │ │ │ + * transformcomplete - Triggered after dragging. Listeners receive │ │ │ │ │ + * an event object with the transformed *feature*. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * CONSTANT: DEFAULTS │ │ │ │ │ - * Default target properties. │ │ │ │ │ + * APIProperty: geometryTypes │ │ │ │ │ + * {Array(String)} To restrict transformation to a limited set of geometry │ │ │ │ │ + * types, send a list of strings corresponding to the geometry class │ │ │ │ │ + * names. │ │ │ │ │ */ │ │ │ │ │ - DEFAULTS: { │ │ │ │ │ - tolerance: 10, │ │ │ │ │ - node: true, │ │ │ │ │ - edge: true, │ │ │ │ │ - vertex: true │ │ │ │ │ - }, │ │ │ │ │ + geometryTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: greedy │ │ │ │ │ - * {Boolean} Snap to closest feature in first layer with an eligible │ │ │ │ │ - * feature. Default is true. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - greedy: true, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: precedence │ │ │ │ │ - * {Array} List representing precedence of different snapping types. │ │ │ │ │ - * Default is "node", "vertex", "edge". │ │ │ │ │ + * APIProperty: preserveAspectRatio │ │ │ │ │ + * {Boolean} set to true to not change the feature's aspect ratio. │ │ │ │ │ */ │ │ │ │ │ - precedence: ["node", "vertex", "edge"], │ │ │ │ │ + preserveAspectRatio: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The map resolution for the previously considered snap. │ │ │ │ │ + * APIProperty: rotate │ │ │ │ │ + * {Boolean} set to false if rotation should be disabled. Default is true. │ │ │ │ │ + * To be passed with the constructor or set when the control is not │ │ │ │ │ + * active. │ │ │ │ │ */ │ │ │ │ │ - resolution: null, │ │ │ │ │ + rotate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: geoToleranceCache │ │ │ │ │ - * {Object} A cache of geo-tolerances. Tolerance values (in map units) are │ │ │ │ │ - * calculated when the map resolution changes. │ │ │ │ │ + * APIProperty: feature │ │ │ │ │ + * {} Feature currently available for │ │ │ │ │ + * transformation. Read-only, use to set it manually. │ │ │ │ │ */ │ │ │ │ │ - geoToleranceCache: null, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The current editable layer. Set at │ │ │ │ │ - * construction or after construction with . │ │ │ │ │ + * APIProperty: renderIntent │ │ │ │ │ + * {String|Object} Render intent for the transformation box and │ │ │ │ │ + * handles. A symbolizer object can also be provided here. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + renderIntent: "temporary", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The current editable feature. │ │ │ │ │ + * APIProperty: rotationHandleSymbolizer │ │ │ │ │ + * {Object|String} Optional. A custom symbolizer for the rotation handles. │ │ │ │ │ + * A render intent can also be provided here. Defaults to │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * stroke: false, │ │ │ │ │ + * pointRadius: 10, │ │ │ │ │ + * fillOpacity: 0, │ │ │ │ │ + * cursor: "pointer" │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - feature: null, │ │ │ │ │ + rotationHandleSymbolizer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: point │ │ │ │ │ - * {} The currently snapped vertex. │ │ │ │ │ + * APIProperty: box │ │ │ │ │ + * {} The transformation box rectangle. │ │ │ │ │ + * Read-only. │ │ │ │ │ */ │ │ │ │ │ - point: null, │ │ │ │ │ + box: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Snapping │ │ │ │ │ - * Creates a new snapping control. A control is constructed with an editable │ │ │ │ │ - * layer and a set of configuration objects for target layers. While the │ │ │ │ │ - * control is active, dragging vertices while drawing new features or │ │ │ │ │ - * modifying existing features on the editable layer will engage │ │ │ │ │ - * snapping to features on the target layers. Whether a vertex snaps to │ │ │ │ │ - * a feature on a target layer depends on the target layer configuration. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An object containing all configuration properties for │ │ │ │ │ - * the control. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * layer - {} The editable layer. Features from this │ │ │ │ │ - * layer that are digitized or modified may have vertices snapped to │ │ │ │ │ - * features from any of the target layers. │ │ │ │ │ - * targets - {Array(Object | OpenLayers.Layer.Vector)} A list of objects for │ │ │ │ │ - * configuring target layers. See valid properties of the target │ │ │ │ │ - * objects below. If the items in the targets list are vector layers │ │ │ │ │ - * (instead of configuration objects), the defaults from the │ │ │ │ │ - * property will apply. The editable layer itself may be a target │ │ │ │ │ - * layer, allowing newly created or edited features to be snapped to │ │ │ │ │ - * existing features from the same layer. If no targets are provided │ │ │ │ │ - * the layer given in the constructor (as ) will become the │ │ │ │ │ - * initial target. │ │ │ │ │ - * defaults - {Object} An object with default properties to be applied │ │ │ │ │ - * to all target objects. │ │ │ │ │ - * greedy - {Boolean} Snap to closest feature in first target layer that │ │ │ │ │ - * applies. Default is true. If false, all features in all target │ │ │ │ │ - * layers will be checked and the closest feature in all target layers │ │ │ │ │ - * will be chosen. The greedy property determines if the order of the │ │ │ │ │ - * target layers is significant. By default, the order of the target │ │ │ │ │ - * layers is significant where layers earlier in the target layer list │ │ │ │ │ - * have precedence over layers later in the list. Within a single │ │ │ │ │ - * layer, the closest feature is always chosen for snapping. This │ │ │ │ │ - * property only determines whether the search for a closer feature │ │ │ │ │ - * continues after an eligible feature is found in a target layer. │ │ │ │ │ - * │ │ │ │ │ - * Valid target properties: │ │ │ │ │ - * layer - {} A target layer. Features from this │ │ │ │ │ - * layer will be eligible to act as snapping target for the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * tolerance - {Float} The distance (in pixels) at which snapping may occur. │ │ │ │ │ - * Default is 10. │ │ │ │ │ - * node - {Boolean} Snap to nodes (first or last point in a geometry) in │ │ │ │ │ - * target layer. Default is true. │ │ │ │ │ - * nodeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for nodes specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * vertex - {Boolean} Snap to vertices in target layer. Default is true. │ │ │ │ │ - * vertexTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for vertices specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * edge - {Boolean} Snap to edges in target layer. Default is true. │ │ │ │ │ - * edgeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for edges specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * filter - {} Optional filter to evaluate to determine if │ │ │ │ │ - * feature is eligible for snapping. If filter evaluates to true for a │ │ │ │ │ - * target feature a vertex may be snapped to the feature. │ │ │ │ │ - * minResolution - {Number} If a minResolution is provided, snapping to this │ │ │ │ │ - * target will only be considered if the map resolution is greater than │ │ │ │ │ - * or equal to this value (the minResolution is inclusive). Default is │ │ │ │ │ - * no minimum resolution limit. │ │ │ │ │ - * maxResolution - {Number} If a maxResolution is provided, snapping to this │ │ │ │ │ - * target will only be considered if the map resolution is strictly │ │ │ │ │ - * less than this value (the maxResolution is exclusive). Default is │ │ │ │ │ - * no maximum resolution limit. │ │ │ │ │ + * APIProperty: center │ │ │ │ │ + * {} The center of the feature bounds. │ │ │ │ │ + * Read-only. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ + center: null, │ │ │ │ │ │ │ │ │ │ - // set the editable layer if provided │ │ │ │ │ - if (this.options.layer) { │ │ │ │ │ - this.setLayer(this.options.layer); │ │ │ │ │ - } │ │ │ │ │ - // configure target layers │ │ │ │ │ - var defaults = OpenLayers.Util.extend({}, this.options.defaults); │ │ │ │ │ - this.defaults = OpenLayers.Util.applyDefaults(defaults, this.DEFAULTS); │ │ │ │ │ - this.setTargets(this.options.targets); │ │ │ │ │ - if (this.targets.length === 0 && this.layer) { │ │ │ │ │ - this.addTargetLayer(this.layer); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: scale │ │ │ │ │ + * {Float} The scale of the feature, relative to the scale the time the │ │ │ │ │ + * feature was set. Read-only, except for *beforesetfeature* │ │ │ │ │ + * listeners. │ │ │ │ │ + */ │ │ │ │ │ + scale: 1, │ │ │ │ │ │ │ │ │ │ - this.geoToleranceCache = {}; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: ratio │ │ │ │ │ + * {Float} The ratio of the feature relative to the ratio the time the │ │ │ │ │ + * feature was set. Read-only, except for *beforesetfeature* │ │ │ │ │ + * listeners. │ │ │ │ │ + */ │ │ │ │ │ + ratio: 1, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setLayer │ │ │ │ │ - * Set the editable layer. Call the setLayer method if the editable layer │ │ │ │ │ - * changes and the same control should be used on a new editable layer. │ │ │ │ │ - * If the control is already active, it will be active after the new │ │ │ │ │ - * layer is set. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The new editable layer. │ │ │ │ │ + * Property: rotation │ │ │ │ │ + * {Integer} the current rotation angle of the box. Read-only, except for │ │ │ │ │ + * *beforesetfeature* listeners. │ │ │ │ │ */ │ │ │ │ │ - setLayer: function(layer) { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.activate(); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + rotation: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setTargets │ │ │ │ │ - * Set the targets for the snapping agent. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * targets - {Array} An array of target configs or target layers. │ │ │ │ │ + * APIProperty: handles │ │ │ │ │ + * {Array()} The 8 handles currently available │ │ │ │ │ + * for scaling/resizing. Numbered counterclockwise, starting from the │ │ │ │ │ + * southwest corner. Read-only. │ │ │ │ │ */ │ │ │ │ │ - setTargets: function(targets) { │ │ │ │ │ - this.targets = []; │ │ │ │ │ - if (targets && targets.length) { │ │ │ │ │ - var target; │ │ │ │ │ - for (var i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ - target = targets[i]; │ │ │ │ │ - if (target instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ - this.addTargetLayer(target); │ │ │ │ │ - } else { │ │ │ │ │ - this.addTarget(target); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + handles: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addTargetLayer │ │ │ │ │ - * Add a target layer with the default target config. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} A target layer. │ │ │ │ │ + * APIProperty: rotationHandles │ │ │ │ │ + * {Array()} The 4 rotation handles currently │ │ │ │ │ + * available for rotating. Numbered counterclockwise, starting from │ │ │ │ │ + * the southwest corner. Read-only. │ │ │ │ │ */ │ │ │ │ │ - addTargetLayer: function(layer) { │ │ │ │ │ - this.addTarget({ │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + rotationHandles: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addTarget │ │ │ │ │ - * Add a configured target layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {Object} A target config. │ │ │ │ │ + * Property: dragControl │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - addTarget: function(target) { │ │ │ │ │ - target = OpenLayers.Util.applyDefaults(target, this.defaults); │ │ │ │ │ - target.nodeTolerance = target.nodeTolerance || target.tolerance; │ │ │ │ │ - target.vertexTolerance = target.vertexTolerance || target.tolerance; │ │ │ │ │ - target.edgeTolerance = target.edgeTolerance || target.tolerance; │ │ │ │ │ - this.targets.push(target); │ │ │ │ │ - }, │ │ │ │ │ + dragControl: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeTargetLayer │ │ │ │ │ - * Remove a target layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The target layer to remove. │ │ │ │ │ + * APIProperty: irregular │ │ │ │ │ + * {Boolean} Make scaling/resizing work irregularly. If true then │ │ │ │ │ + * dragging a handle causes the feature to resize in the direction │ │ │ │ │ + * of movement. If false then the feature resizes symetrically │ │ │ │ │ + * about it's center. │ │ │ │ │ */ │ │ │ │ │ - removeTargetLayer: function(layer) { │ │ │ │ │ - var target; │ │ │ │ │ - for (var i = this.targets.length - 1; i >= 0; --i) { │ │ │ │ │ - target = this.targets[i]; │ │ │ │ │ - if (target.layer === layer) { │ │ │ │ │ - this.removeTarget(target); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + irregular: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeTarget │ │ │ │ │ - * Remove a target. │ │ │ │ │ + * Constructor: OpenLayers.Control.TransformFeature │ │ │ │ │ + * Create a new transform feature control. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * target - {Object} A target config. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} The targets array. │ │ │ │ │ + * layer - {} Layer that contains features that │ │ │ │ │ + * will be transformed. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * control. │ │ │ │ │ */ │ │ │ │ │ - removeTarget: function(target) { │ │ │ │ │ - return OpenLayers.Util.removeItem(this.targets, target); │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + │ │ │ │ │ + if (!this.rotationHandleSymbolizer) { │ │ │ │ │ + this.rotationHandleSymbolizer = { │ │ │ │ │ + stroke: false, │ │ │ │ │ + pointRadius: 10, │ │ │ │ │ + fillOpacity: 0, │ │ │ │ │ + cursor: "pointer" │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.createBox(); │ │ │ │ │ + this.createControl(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: activate │ │ │ │ │ - * Activate the control. Activating the control registers listeners for │ │ │ │ │ - * editing related events so that during feature creation and │ │ │ │ │ - * modification, moving vertices will trigger snapping. │ │ │ │ │ + * Activates the control. │ │ │ │ │ */ │ │ │ │ │ activate: function() { │ │ │ │ │ - var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - if (this.layer && this.layer.events) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - sketchstarted: this.onSketchModified, │ │ │ │ │ - sketchmodified: this.onSketchModified, │ │ │ │ │ - vertexmodified: this.onVertexModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragControl.activate(); │ │ │ │ │ + this.layer.addFeatures([this.box]); │ │ │ │ │ + this.rotate && this.layer.addFeatures(this.rotationHandles); │ │ │ │ │ + this.layer.addFeatures(this.handles); │ │ │ │ │ + activated = true; │ │ │ │ │ } │ │ │ │ │ return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ - * so feature editing may proceed without engaging the snapping agent. │ │ │ │ │ + * Deactivates the control. │ │ │ │ │ */ │ │ │ │ │ deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - if (this.layer && this.layer.events) { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - sketchstarted: this.onSketchModified, │ │ │ │ │ - sketchmodified: this.onSketchModified, │ │ │ │ │ - vertexmodified: this.onVertexModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.layer.removeFeatures(this.handles); │ │ │ │ │ + this.rotate && this.layer.removeFeatures(this.rotationHandles); │ │ │ │ │ + this.layer.removeFeatures([this.box]); │ │ │ │ │ + this.dragControl.deactivate(); │ │ │ │ │ + deactivated = true; │ │ │ │ │ } │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.point = null; │ │ │ │ │ return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onSketchModified │ │ │ │ │ - * Registered as a listener for the sketchmodified event on the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The sketch modified event. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - onSketchModified: function(event) { │ │ │ │ │ - this.feature = event.feature; │ │ │ │ │ - this.considerSnapping(event.vertex, event.vertex); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.dragControl.setMap(map); │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onVertexModified │ │ │ │ │ - * Registered as a listener for the vertexmodified event on the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setFeature │ │ │ │ │ + * Place the transformation box on a feature and start transforming it. │ │ │ │ │ + * If the control is not active, it will be activated. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The vertex modified event. │ │ │ │ │ + * feature - {} │ │ │ │ │ + * initialParams - {Object} Initial values for rotation, scale or ratio. │ │ │ │ │ + * Setting a rotation value here will cause the transformation box to │ │ │ │ │ + * start rotated. Setting a scale or ratio will not affect the │ │ │ │ │ + * transormation box, but applications may use this to keep track of │ │ │ │ │ + * scale and ratio of a feature across multiple transforms. │ │ │ │ │ */ │ │ │ │ │ - onVertexModified: function(event) { │ │ │ │ │ - this.feature = event.feature; │ │ │ │ │ - var loc = this.layer.map.getLonLatFromViewPortPx(event.pixel); │ │ │ │ │ - this.considerSnapping( │ │ │ │ │ - event.vertex, new OpenLayers.Geometry.Point(loc.lon, loc.lat) │ │ │ │ │ - ); │ │ │ │ │ + setFeature: function(feature, initialParams) { │ │ │ │ │ + initialParams = OpenLayers.Util.applyDefaults(initialParams, { │ │ │ │ │ + rotation: 0, │ │ │ │ │ + scale: 1, │ │ │ │ │ + ratio: 1 │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + var oldRotation = this.rotation; │ │ │ │ │ + var oldCenter = this.center; │ │ │ │ │ + OpenLayers.Util.extend(this, initialParams); │ │ │ │ │ + │ │ │ │ │ + var cont = this.events.triggerEvent("beforesetfeature", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + if (cont === false) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.feature = feature; │ │ │ │ │ + this.activate(); │ │ │ │ │ + │ │ │ │ │ + this._setfeature = true; │ │ │ │ │ + │ │ │ │ │ + var featureBounds = this.feature.geometry.getBounds(); │ │ │ │ │ + this.box.move(featureBounds.getCenterLonLat()); │ │ │ │ │ + this.box.geometry.rotate(-oldRotation, oldCenter); │ │ │ │ │ + this._angle = 0; │ │ │ │ │ + │ │ │ │ │ + var ll; │ │ │ │ │ + if (this.rotation) { │ │ │ │ │ + var geom = feature.geometry.clone(); │ │ │ │ │ + geom.rotate(-this.rotation, this.center); │ │ │ │ │ + var box = new OpenLayers.Feature.Vector( │ │ │ │ │ + geom.getBounds().toGeometry()); │ │ │ │ │ + box.geometry.rotate(this.rotation, this.center); │ │ │ │ │ + this.box.geometry.rotate(this.rotation, this.center); │ │ │ │ │ + this.box.move(box.geometry.getBounds().getCenterLonLat()); │ │ │ │ │ + var llGeom = box.geometry.components[0].components[0]; │ │ │ │ │ + ll = llGeom.getBounds().getCenterLonLat(); │ │ │ │ │ + } else { │ │ │ │ │ + ll = new OpenLayers.LonLat(featureBounds.left, featureBounds.bottom); │ │ │ │ │ + } │ │ │ │ │ + this.handles[0].move(ll); │ │ │ │ │ + │ │ │ │ │ + delete this._setfeature; │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("setfeature", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: considerSnapping │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} The vertex to be snapped (or │ │ │ │ │ - * unsnapped). │ │ │ │ │ - * loc - {} The location of the mouse in map │ │ │ │ │ - * coords. │ │ │ │ │ + * APIMethod: unsetFeature │ │ │ │ │ + * Remove the transformation box off any feature. │ │ │ │ │ + * If the control is active, it will be deactivated first. │ │ │ │ │ */ │ │ │ │ │ - considerSnapping: function(point, loc) { │ │ │ │ │ - var best = { │ │ │ │ │ - rank: Number.POSITIVE_INFINITY, │ │ │ │ │ - dist: Number.POSITIVE_INFINITY, │ │ │ │ │ - x: null, │ │ │ │ │ - y: null │ │ │ │ │ + unsetFeature: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + } else { │ │ │ │ │ + this.feature = null; │ │ │ │ │ + this.rotation = 0; │ │ │ │ │ + this.scale = 1; │ │ │ │ │ + this.ratio = 1; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createBox │ │ │ │ │ + * Creates the box with all handles and transformation handles. │ │ │ │ │ + */ │ │ │ │ │ + createBox: function() { │ │ │ │ │ + var control = this; │ │ │ │ │ + │ │ │ │ │ + this.center = new OpenLayers.Geometry.Point(0, 0); │ │ │ │ │ + this.box = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.LineString([ │ │ │ │ │ + new OpenLayers.Geometry.Point(-1, -1), │ │ │ │ │ + new OpenLayers.Geometry.Point(0, -1), │ │ │ │ │ + new OpenLayers.Geometry.Point(1, -1), │ │ │ │ │ + new OpenLayers.Geometry.Point(1, 0), │ │ │ │ │ + new OpenLayers.Geometry.Point(1, 1), │ │ │ │ │ + new OpenLayers.Geometry.Point(0, 1), │ │ │ │ │ + new OpenLayers.Geometry.Point(-1, 1), │ │ │ │ │ + new OpenLayers.Geometry.Point(-1, 0), │ │ │ │ │ + new OpenLayers.Geometry.Point(-1, -1) │ │ │ │ │ + ]), null, │ │ │ │ │ + typeof this.renderIntent == "string" ? null : this.renderIntent │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + // Override for box move - make sure that the center gets updated │ │ │ │ │ + this.box.geometry.move = function(x, y) { │ │ │ │ │ + control._moving = true; │ │ │ │ │ + OpenLayers.Geometry.LineString.prototype.move.apply(this, arguments); │ │ │ │ │ + control.center.move(x, y); │ │ │ │ │ + delete control._moving; │ │ │ │ │ }; │ │ │ │ │ - var snapped = false; │ │ │ │ │ - var result, target; │ │ │ │ │ - for (var i = 0, len = this.targets.length; i < len; ++i) { │ │ │ │ │ - target = this.targets[i]; │ │ │ │ │ - result = this.testTarget(target, loc); │ │ │ │ │ - if (result) { │ │ │ │ │ - if (this.greedy) { │ │ │ │ │ - best = result; │ │ │ │ │ - best.target = target; │ │ │ │ │ - snapped = true; │ │ │ │ │ - break; │ │ │ │ │ - } else { │ │ │ │ │ - if ((result.rank < best.rank) || │ │ │ │ │ - (result.rank === best.rank && result.dist < best.dist)) { │ │ │ │ │ - best = result; │ │ │ │ │ - best.target = target; │ │ │ │ │ - snapped = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + // Overrides for vertex move, resize and rotate - make sure that │ │ │ │ │ + // handle and rotationHandle geometries are also moved, resized and │ │ │ │ │ + // rotated. │ │ │ │ │ + var vertexMoveFn = function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.apply(this, arguments); │ │ │ │ │ + this._rotationHandle && this._rotationHandle.geometry.move(x, y); │ │ │ │ │ + this._handle.geometry.move(x, y); │ │ │ │ │ + }; │ │ │ │ │ + var vertexResizeFn = function(scale, center, ratio) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.resize.apply(this, arguments); │ │ │ │ │ + this._rotationHandle && this._rotationHandle.geometry.resize( │ │ │ │ │ + scale, center, ratio); │ │ │ │ │ + this._handle.geometry.resize(scale, center, ratio); │ │ │ │ │ + }; │ │ │ │ │ + var vertexRotateFn = function(angle, center) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.rotate.apply(this, arguments); │ │ │ │ │ + this._rotationHandle && this._rotationHandle.geometry.rotate( │ │ │ │ │ + angle, center); │ │ │ │ │ + this._handle.geometry.rotate(angle, center); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Override for handle move - make sure that the box and other handles │ │ │ │ │ + // are updated, and finally transform the feature. │ │ │ │ │ + var handleMoveFn = function(x, y) { │ │ │ │ │ + var oldX = this.x, │ │ │ │ │ + oldY = this.y; │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + if (control._moving) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - if (snapped) { │ │ │ │ │ - var proceed = this.events.triggerEvent("beforesnap", { │ │ │ │ │ - point: point, │ │ │ │ │ - x: best.x, │ │ │ │ │ - y: best.y, │ │ │ │ │ - distance: best.dist, │ │ │ │ │ - layer: best.target.layer, │ │ │ │ │ - snapType: this.precedence[best.rank] │ │ │ │ │ - }); │ │ │ │ │ - if (proceed !== false) { │ │ │ │ │ - point.x = best.x; │ │ │ │ │ - point.y = best.y; │ │ │ │ │ - this.point = point; │ │ │ │ │ - this.events.triggerEvent("snap", { │ │ │ │ │ - point: point, │ │ │ │ │ - snapType: this.precedence[best.rank], │ │ │ │ │ - layer: best.target.layer, │ │ │ │ │ - distance: best.dist │ │ │ │ │ - }); │ │ │ │ │ + var evt = control.dragControl.handlers.drag.evt; │ │ │ │ │ + var preserveAspectRatio = !control._setfeature && │ │ │ │ │ + control.preserveAspectRatio; │ │ │ │ │ + var reshape = !preserveAspectRatio && !(evt && evt.shiftKey); │ │ │ │ │ + var oldGeom = new OpenLayers.Geometry.Point(oldX, oldY); │ │ │ │ │ + var centerGeometry = control.center; │ │ │ │ │ + this.rotate(-control.rotation, centerGeometry); │ │ │ │ │ + oldGeom.rotate(-control.rotation, centerGeometry); │ │ │ │ │ + var dx1 = this.x - centerGeometry.x; │ │ │ │ │ + var dy1 = this.y - centerGeometry.y; │ │ │ │ │ + var dx0 = dx1 - (this.x - oldGeom.x); │ │ │ │ │ + var dy0 = dy1 - (this.y - oldGeom.y); │ │ │ │ │ + if (control.irregular && !control._setfeature) { │ │ │ │ │ + dx1 -= (this.x - oldGeom.x) / 2; │ │ │ │ │ + dy1 -= (this.y - oldGeom.y) / 2; │ │ │ │ │ + } │ │ │ │ │ + this.x = oldX; │ │ │ │ │ + this.y = oldY; │ │ │ │ │ + var scale, ratio = 1; │ │ │ │ │ + if (reshape) { │ │ │ │ │ + scale = Math.abs(dy0) < 0.00001 ? 1 : dy1 / dy0; │ │ │ │ │ + ratio = (Math.abs(dx0) < 0.00001 ? 1 : (dx1 / dx0)) / scale; │ │ │ │ │ } else { │ │ │ │ │ - snapped = false; │ │ │ │ │ + var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ + var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ + scale = l1 / l0; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - if (this.point && !snapped) { │ │ │ │ │ - point.x = loc.x; │ │ │ │ │ - point.y = loc.y; │ │ │ │ │ - this.point = null; │ │ │ │ │ - this.events.triggerEvent("unsnap", { │ │ │ │ │ - point: point │ │ │ │ │ + │ │ │ │ │ + // rotate the box to 0 before resizing - saves us some │ │ │ │ │ + // calculations and is inexpensive because we don't drawFeature. │ │ │ │ │ + control._moving = true; │ │ │ │ │ + control.box.geometry.rotate(-control.rotation, centerGeometry); │ │ │ │ │ + delete control._moving; │ │ │ │ │ + │ │ │ │ │ + control.box.geometry.resize(scale, centerGeometry, ratio); │ │ │ │ │ + control.box.geometry.rotate(control.rotation, centerGeometry); │ │ │ │ │ + control.transformFeature({ │ │ │ │ │ + scale: scale, │ │ │ │ │ + ratio: ratio │ │ │ │ │ }); │ │ │ │ │ + if (control.irregular && !control._setfeature) { │ │ │ │ │ + var newCenter = centerGeometry.clone(); │ │ │ │ │ + newCenter.x += Math.abs(oldX - centerGeometry.x) < 0.00001 ? 0 : (this.x - oldX); │ │ │ │ │ + newCenter.y += Math.abs(oldY - centerGeometry.y) < 0.00001 ? 0 : (this.y - oldY); │ │ │ │ │ + control.box.geometry.move(this.x - oldX, this.y - oldY); │ │ │ │ │ + control.transformFeature({ │ │ │ │ │ + center: newCenter │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // Override for rotation handle move - make sure that the box and │ │ │ │ │ + // other handles are updated, and finally transform the feature. │ │ │ │ │ + var rotationHandleMoveFn = function(x, y) { │ │ │ │ │ + var oldX = this.x, │ │ │ │ │ + oldY = this.y; │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + if (control._moving) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + var evt = control.dragControl.handlers.drag.evt; │ │ │ │ │ + var constrain = (evt && evt.shiftKey) ? 45 : 1; │ │ │ │ │ + var centerGeometry = control.center; │ │ │ │ │ + var dx1 = this.x - centerGeometry.x; │ │ │ │ │ + var dy1 = this.y - centerGeometry.y; │ │ │ │ │ + var dx0 = dx1 - x; │ │ │ │ │ + var dy0 = dy1 - y; │ │ │ │ │ + this.x = oldX; │ │ │ │ │ + this.y = oldY; │ │ │ │ │ + var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ + var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ + var angle = a1 - a0; │ │ │ │ │ + angle *= 180 / Math.PI; │ │ │ │ │ + control._angle = (control._angle + angle) % 360; │ │ │ │ │ + var diff = control.rotation % constrain; │ │ │ │ │ + if (Math.abs(control._angle) >= constrain || diff !== 0) { │ │ │ │ │ + angle = Math.round(control._angle / constrain) * constrain - │ │ │ │ │ + diff; │ │ │ │ │ + control._angle = 0; │ │ │ │ │ + control.box.geometry.rotate(angle, centerGeometry); │ │ │ │ │ + control.transformFeature({ │ │ │ │ │ + rotation: angle │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + var handles = new Array(8); │ │ │ │ │ + var rotationHandles = new Array(4); │ │ │ │ │ + var geom, handle, rotationHandle; │ │ │ │ │ + var positions = ["sw", "s", "se", "e", "ne", "n", "nw", "w"]; │ │ │ │ │ + for (var i = 0; i < 8; ++i) { │ │ │ │ │ + geom = this.box.geometry.components[i]; │ │ │ │ │ + handle = new OpenLayers.Feature.Vector(geom.clone(), { │ │ │ │ │ + role: positions[i] + "-resize" │ │ │ │ │ + }, typeof this.renderIntent == "string" ? null : │ │ │ │ │ + this.renderIntent); │ │ │ │ │ + if (i % 2 == 0) { │ │ │ │ │ + rotationHandle = new OpenLayers.Feature.Vector(geom.clone(), { │ │ │ │ │ + role: positions[i] + "-rotate" │ │ │ │ │ + }, typeof this.rotationHandleSymbolizer == "string" ? │ │ │ │ │ + null : this.rotationHandleSymbolizer); │ │ │ │ │ + rotationHandle.geometry.move = rotationHandleMoveFn; │ │ │ │ │ + geom._rotationHandle = rotationHandle; │ │ │ │ │ + rotationHandles[i / 2] = rotationHandle; │ │ │ │ │ + } │ │ │ │ │ + geom.move = vertexMoveFn; │ │ │ │ │ + geom.resize = vertexResizeFn; │ │ │ │ │ + geom.rotate = vertexRotateFn; │ │ │ │ │ + handle.geometry.move = handleMoveFn; │ │ │ │ │ + geom._handle = handle; │ │ │ │ │ + handles[i] = handle; │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + this.rotationHandles = rotationHandles; │ │ │ │ │ + this.handles = handles; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: testTarget │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {Object} Object with target layer configuration. │ │ │ │ │ - * loc - {} The location of the mouse in map │ │ │ │ │ - * coords. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A result object with rank, dist, x, and y properties. │ │ │ │ │ - * Returns null if candidate is not eligible for snapping. │ │ │ │ │ + * Method: createControl │ │ │ │ │ + * Creates a DragFeature control for this control. │ │ │ │ │ */ │ │ │ │ │ - testTarget: function(target, loc) { │ │ │ │ │ - var resolution = this.layer.map.getResolution(); │ │ │ │ │ - if ("minResolution" in target) { │ │ │ │ │ - if (resolution < target.minResolution) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if ("maxResolution" in target) { │ │ │ │ │ - if (resolution >= target.maxResolution) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var tolerance = { │ │ │ │ │ - node: this.getGeoTolerance(target.nodeTolerance, resolution), │ │ │ │ │ - vertex: this.getGeoTolerance(target.vertexTolerance, resolution), │ │ │ │ │ - edge: this.getGeoTolerance(target.edgeTolerance, resolution) │ │ │ │ │ - }; │ │ │ │ │ - // this could be cached if we don't support setting tolerance values directly │ │ │ │ │ - var maxTolerance = Math.max( │ │ │ │ │ - tolerance.node, tolerance.vertex, tolerance.edge │ │ │ │ │ - ); │ │ │ │ │ - var result = { │ │ │ │ │ - rank: Number.POSITIVE_INFINITY, │ │ │ │ │ - dist: Number.POSITIVE_INFINITY │ │ │ │ │ - }; │ │ │ │ │ - var eligible = false; │ │ │ │ │ - var features = target.layer.features; │ │ │ │ │ - var feature, type, vertices, vertex, closest, dist, found; │ │ │ │ │ - var numTypes = this.precedence.length; │ │ │ │ │ - var ll = new OpenLayers.LonLat(loc.x, loc.y); │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (feature !== this.feature && !feature._sketch && │ │ │ │ │ - feature.state !== OpenLayers.State.DELETE && │ │ │ │ │ - (!target.filter || target.filter.evaluate(feature))) { │ │ │ │ │ - if (feature.atPoint(ll, maxTolerance, maxTolerance)) { │ │ │ │ │ - for (var j = 0, stop = Math.min(result.rank + 1, numTypes); j < stop; ++j) { │ │ │ │ │ - type = this.precedence[j]; │ │ │ │ │ - if (target[type]) { │ │ │ │ │ - if (type === "edge") { │ │ │ │ │ - closest = feature.geometry.distanceTo(loc, { │ │ │ │ │ - details: true │ │ │ │ │ - }); │ │ │ │ │ - dist = closest.distance; │ │ │ │ │ - if (dist <= tolerance[type] && dist < result.dist) { │ │ │ │ │ - result = { │ │ │ │ │ - rank: j, │ │ │ │ │ - dist: dist, │ │ │ │ │ - x: closest.x0, │ │ │ │ │ - y: closest.y0 // closest coords on feature │ │ │ │ │ - }; │ │ │ │ │ - eligible = true; │ │ │ │ │ - // don't look for lower precedence types for this feature │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // look for nodes or vertices │ │ │ │ │ - vertices = feature.geometry.getVertices(type === "node"); │ │ │ │ │ - found = false; │ │ │ │ │ - for (var k = 0, klen = vertices.length; k < klen; ++k) { │ │ │ │ │ - vertex = vertices[k]; │ │ │ │ │ - dist = vertex.distanceTo(loc); │ │ │ │ │ - if (dist <= tolerance[type] && │ │ │ │ │ - (j < result.rank || (j === result.rank && dist < result.dist))) { │ │ │ │ │ - result = { │ │ │ │ │ - rank: j, │ │ │ │ │ - dist: dist, │ │ │ │ │ - x: vertex.x, │ │ │ │ │ - y: vertex.y │ │ │ │ │ - }; │ │ │ │ │ - eligible = true; │ │ │ │ │ - found = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (found) { │ │ │ │ │ - // don't look for lower precedence types for this feature │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + createControl: function() { │ │ │ │ │ + var control = this; │ │ │ │ │ + this.dragControl = new OpenLayers.Control.DragFeature(this.layer, { │ │ │ │ │ + documentDrag: true, │ │ │ │ │ + // avoid moving the feature itself - move the box instead │ │ │ │ │ + moveFeature: function(pixel) { │ │ │ │ │ + if (this.feature === control.feature) { │ │ │ │ │ + this.feature = control.box; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.DragFeature.prototype.moveFeature.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + }, │ │ │ │ │ + // transform while dragging │ │ │ │ │ + onDrag: function(feature, pixel) { │ │ │ │ │ + if (feature === control.box) { │ │ │ │ │ + control.transformFeature({ │ │ │ │ │ + center: control.center │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + // set a new feature │ │ │ │ │ + onStart: function(feature, pixel) { │ │ │ │ │ + var eligible = !control.geometryTypes || │ │ │ │ │ + OpenLayers.Util.indexOf(control.geometryTypes, │ │ │ │ │ + feature.geometry.CLASS_NAME) !== -1; │ │ │ │ │ + var i = OpenLayers.Util.indexOf(control.handles, feature); │ │ │ │ │ + i += OpenLayers.Util.indexOf(control.rotationHandles, │ │ │ │ │ + feature); │ │ │ │ │ + if (feature !== control.feature && feature !== control.box && │ │ │ │ │ + i == -2 && eligible) { │ │ │ │ │ + control.setFeature(feature); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ + onComplete: function(feature, pixel) { │ │ │ │ │ + control.events.triggerEvent("transformcomplete", { │ │ │ │ │ + feature: control.feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawHandles │ │ │ │ │ + * Draws the handles to match the box. │ │ │ │ │ + */ │ │ │ │ │ + drawHandles: function() { │ │ │ │ │ + var layer = this.layer; │ │ │ │ │ + for (var i = 0; i < 8; ++i) { │ │ │ │ │ + if (this.rotate && i % 2 === 0) { │ │ │ │ │ + layer.drawFeature(this.rotationHandles[i / 2], │ │ │ │ │ + this.rotationHandleSymbolizer); │ │ │ │ │ } │ │ │ │ │ + layer.drawFeature(this.handles[i], this.renderIntent); │ │ │ │ │ } │ │ │ │ │ - return eligible ? result : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeoTolerance │ │ │ │ │ - * Calculate a tolerance in map units given a tolerance in pixels. This │ │ │ │ │ - * takes advantage of the when the map resolution │ │ │ │ │ - * has not changed. │ │ │ │ │ - * │ │ │ │ │ + * Method: transformFeature │ │ │ │ │ + * Transforms the feature. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * tolerance - {Number} A tolerance value in pixels. │ │ │ │ │ - * resolution - {Number} Map resolution. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} A tolerance value in map units. │ │ │ │ │ + * mods - {Object} An object with optional scale, ratio, rotation and │ │ │ │ │ + * center properties. │ │ │ │ │ */ │ │ │ │ │ - getGeoTolerance: function(tolerance, resolution) { │ │ │ │ │ - if (resolution !== this.resolution) { │ │ │ │ │ - this.resolution = resolution; │ │ │ │ │ - this.geoToleranceCache = {}; │ │ │ │ │ - } │ │ │ │ │ - var geoTolerance = this.geoToleranceCache[tolerance]; │ │ │ │ │ - if (geoTolerance === undefined) { │ │ │ │ │ - geoTolerance = tolerance * resolution; │ │ │ │ │ - this.geoToleranceCache[tolerance] = geoTolerance; │ │ │ │ │ + transformFeature: function(mods) { │ │ │ │ │ + if (!this._setfeature) { │ │ │ │ │ + this.scale *= (mods.scale || 1); │ │ │ │ │ + this.ratio *= (mods.ratio || 1); │ │ │ │ │ + var oldRotation = this.rotation; │ │ │ │ │ + this.rotation = (this.rotation + (mods.rotation || 0)) % 360; │ │ │ │ │ + │ │ │ │ │ + if (this.events.triggerEvent("beforetransform", mods) !== false) { │ │ │ │ │ + var feature = this.feature; │ │ │ │ │ + var geom = feature.geometry; │ │ │ │ │ + var center = this.center; │ │ │ │ │ + geom.rotate(-oldRotation, center); │ │ │ │ │ + if (mods.scale || mods.ratio) { │ │ │ │ │ + geom.resize(mods.scale, center, mods.ratio); │ │ │ │ │ + } else if (mods.center) { │ │ │ │ │ + feature.move(mods.center.getBounds().getCenterLonLat()); │ │ │ │ │ + } │ │ │ │ │ + geom.rotate(this.rotation, center); │ │ │ │ │ + this.layer.drawFeature(feature); │ │ │ │ │ + feature.toState(OpenLayers.State.UPDATE); │ │ │ │ │ + this.events.triggerEvent("transform", mods); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return geoTolerance; │ │ │ │ │ + this.layer.drawFeature(this.box, this.renderIntent); │ │ │ │ │ + this.drawHandles(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Clean up the control. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Take care of things that are not handled in superclass. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ + var geom; │ │ │ │ │ + for (var i = 0; i < 8; ++i) { │ │ │ │ │ + geom = this.box.geometry.components[i]; │ │ │ │ │ + geom._handle.destroy(); │ │ │ │ │ + geom._handle = null; │ │ │ │ │ + geom._rotationHandle && geom._rotationHandle.destroy(); │ │ │ │ │ + geom._rotationHandle = null; │ │ │ │ │ } │ │ │ │ │ - delete this.layer; │ │ │ │ │ - delete this.targets; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ + this.center = null; │ │ │ │ │ + this.feature = null; │ │ │ │ │ + this.handles = null; │ │ │ │ │ + this.rotationHandleSymbolizer = null; │ │ │ │ │ + this.rotationHandles = null; │ │ │ │ │ + this.box.destroy(); │ │ │ │ │ + this.box = null; │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.dragControl.destroy(); │ │ │ │ │ + this.dragControl = null; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Snapping" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.TransformFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/LayerSwitcher.js │ │ │ │ │ + OpenLayers/Control/Scale.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/Control.js │ │ │ │ │ * @requires OpenLayers/Lang.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.LayerSwitcher │ │ │ │ │ - * The LayerSwitcher control displays a table of contents for the map. This │ │ │ │ │ - * allows the user interface to switch between BaseLasyers and to show or hide │ │ │ │ │ - * Overlays. By default the switcher is shown minimized on the right edge of │ │ │ │ │ - * the map, the user may expand it by clicking on the handle. │ │ │ │ │ - * │ │ │ │ │ - * To create the LayerSwitcher outside of the map, pass the Id of a html div │ │ │ │ │ - * as the first argument to the constructor. │ │ │ │ │ + * Class: OpenLayers.Control.Scale │ │ │ │ │ + * The Scale control displays the current map scale as a ratio (e.g. Scale = │ │ │ │ │ + * 1:1M). By default it is displayed in the lower right corner of the map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerStates │ │ │ │ │ - * {Array(Object)} Basically a copy of the "state" of the map's layers │ │ │ │ │ - * the last time the control was drawn. We have this in order to avoid │ │ │ │ │ - * unnecessarily redrawing the control. │ │ │ │ │ - */ │ │ │ │ │ - layerStates: null, │ │ │ │ │ - │ │ │ │ │ - // DOM Elements │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - layersDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: baseLayersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - baseLayersDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: baseLayers │ │ │ │ │ - * {Array(Object)} │ │ │ │ │ - */ │ │ │ │ │ - baseLayers: null, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dataLbl │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - dataLbl: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dataLayersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - dataLayersDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dataLayers │ │ │ │ │ - * {Array(Object)} │ │ │ │ │ - */ │ │ │ │ │ - dataLayers: null, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: minimizeDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - minimizeDiv: null, │ │ │ │ │ +OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: maximizeDiv │ │ │ │ │ + * Property: element │ │ │ │ │ * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - maximizeDiv: null, │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: ascending │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * APIProperty: geodesic │ │ │ │ │ + * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ + * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ + * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ + * pixel in the center of the map viewport. │ │ │ │ │ */ │ │ │ │ │ - ascending: true, │ │ │ │ │ + geodesic: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.LayerSwitcher │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.Scale │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.layerStates = []; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - //clear out layers info and unregister their events │ │ │ │ │ - this.clearLayersArray("base"); │ │ │ │ │ - this.clearLayersArray("data"); │ │ │ │ │ - │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - addlayer: this.redraw, │ │ │ │ │ - changelayer: this.redraw, │ │ │ │ │ - removelayer: this.redraw, │ │ │ │ │ - changebaselayer: this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Properties: │ │ │ │ │ - * map - {} │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - addlayer: this.redraw, │ │ │ │ │ - changelayer: this.redraw, │ │ │ │ │ - removelayer: this.redraw, │ │ │ │ │ - changebaselayer: this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - if (this.outsideViewport) { │ │ │ │ │ - this.events.attachToElement(this.div); │ │ │ │ │ - this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(element, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.element = OpenLayers.Util.getElement(element); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: draw │ │ │ │ │ - * │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the │ │ │ │ │ - * switcher tabs. │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this); │ │ │ │ │ - │ │ │ │ │ - // create layout divs │ │ │ │ │ - this.loadContents(); │ │ │ │ │ - │ │ │ │ │ - // set mode to minimize │ │ │ │ │ - if (!this.outsideViewport) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (!this.element) { │ │ │ │ │ + this.element = document.createElement("div"); │ │ │ │ │ + this.div.appendChild(this.element); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // populate div with current info │ │ │ │ │ - this.redraw(); │ │ │ │ │ - │ │ │ │ │ + this.map.events.register('moveend', this, this.updateScale); │ │ │ │ │ + this.updateScale(); │ │ │ │ │ return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: updateScale │ │ │ │ │ */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - var button = evt.buttonElement; │ │ │ │ │ - if (button === this.minimizeDiv) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else if (button === this.maximizeDiv) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } else if (button._layerSwitcher === this.id) { │ │ │ │ │ - if (button["for"]) { │ │ │ │ │ - button = document.getElementById(button["for"]); │ │ │ │ │ - } │ │ │ │ │ - if (!button.disabled) { │ │ │ │ │ - if (button.type == "radio") { │ │ │ │ │ - button.checked = true; │ │ │ │ │ - this.map.setBaseLayer(this.map.getLayer(button._layer)); │ │ │ │ │ - } else { │ │ │ │ │ - button.checked = !button.checked; │ │ │ │ │ - this.updateMap(); │ │ │ │ │ - } │ │ │ │ │ + updateScale: function() { │ │ │ │ │ + var scale; │ │ │ │ │ + if (this.geodesic === true) { │ │ │ │ │ + var units = this.map.getUnits(); │ │ │ │ │ + if (!units) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ + var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ + scale = (this.map.getGeodesicPixelSize().w || 0.000001) * │ │ │ │ │ + inches["km"] * OpenLayers.DOTS_PER_INCH; │ │ │ │ │ + } else { │ │ │ │ │ + scale = this.map.getScale(); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearLayersArray │ │ │ │ │ - * User specifies either "base" or "data". we then clear all the │ │ │ │ │ - * corresponding listeners, the div, and reinitialize a new array. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layersType - {String} │ │ │ │ │ - */ │ │ │ │ │ - clearLayersArray: function(layersType) { │ │ │ │ │ - this[layersType + "LayersDiv"].innerHTML = ""; │ │ │ │ │ - this[layersType + "Layers"] = []; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: checkRedraw │ │ │ │ │ - * Checks if the layer state has changed since the last redraw() call. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer state changed since the last redraw() call. │ │ │ │ │ - */ │ │ │ │ │ - checkRedraw: function() { │ │ │ │ │ - if (!this.layerStates.length || │ │ │ │ │ - (this.map.layers.length != this.layerStates.length)) { │ │ │ │ │ - return true; │ │ │ │ │ + if (!scale) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - for (var i = 0, len = this.layerStates.length; i < len; i++) { │ │ │ │ │ - var layerState = this.layerStates[i]; │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if ((layerState.name != layer.name) || │ │ │ │ │ - (layerState.inRange != layer.inRange) || │ │ │ │ │ - (layerState.id != layer.id) || │ │ │ │ │ - (layerState.visibility != layer.visibility)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ + if (scale >= 9500 && scale <= 950000) { │ │ │ │ │ + scale = Math.round(scale / 1000) + "K"; │ │ │ │ │ + } else if (scale >= 950000) { │ │ │ │ │ + scale = Math.round(scale / 1000000) + "M"; │ │ │ │ │ + } else { │ │ │ │ │ + scale = Math.round(scale); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - return false; │ │ │ │ │ + this.element.innerHTML = OpenLayers.i18n("Scale = 1 : ${scaleDenom}", { │ │ │ │ │ + 'scaleDenom': scale │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ - * Goes through and takes the current state of the Map and rebuilds the │ │ │ │ │ - * control to display that state. Groups base layers into a │ │ │ │ │ - * radio-button group and lists each data layer with a checkbox. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ - */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - //if the state hasn't changed since last redraw, no need │ │ │ │ │ - // to do anything. Just return the existing div. │ │ │ │ │ - if (!this.checkRedraw()) { │ │ │ │ │ - return this.div; │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Scale" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - //clear out previous layers │ │ │ │ │ - this.clearLayersArray("base"); │ │ │ │ │ - this.clearLayersArray("data"); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Attribution.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var containsOverlays = false; │ │ │ │ │ - var containsBaseLayers = 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. */ │ │ │ │ │ │ │ │ │ │ - // Save state -- for checking layer if the map state changed. │ │ │ │ │ - // We save this before redrawing, because in the process of redrawing │ │ │ │ │ - // we will trigger more visibility changes, and we want to not redraw │ │ │ │ │ - // and enter an infinite loop. │ │ │ │ │ - var len = this.map.layers.length; │ │ │ │ │ - this.layerStates = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; i++) { │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - this.layerStates[i] = { │ │ │ │ │ - 'name': layer.name, │ │ │ │ │ - 'visibility': layer.visibility, │ │ │ │ │ - 'inRange': layer.inRange, │ │ │ │ │ - 'id': layer.id │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - var layers = this.map.layers.slice(); │ │ │ │ │ - if (!this.ascending) { │ │ │ │ │ - layers.reverse(); │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - var layer = layers[i]; │ │ │ │ │ - var baseLayer = layer.isBaseLayer; │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Attribution │ │ │ │ │ + * The attribution control adds attribution from layers to the map display. │ │ │ │ │ + * It uses 'attribution' property of each layer. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Attribution = │ │ │ │ │ + OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - if (layer.displayInLayerSwitcher) { │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: separator │ │ │ │ │ + * {String} String used to separate layers. │ │ │ │ │ + */ │ │ │ │ │ + separator: ", ", │ │ │ │ │ │ │ │ │ │ - if (baseLayer) { │ │ │ │ │ - containsBaseLayers = true; │ │ │ │ │ - } else { │ │ │ │ │ - containsOverlays = true; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: template │ │ │ │ │ + * {String} Template for the attribution. This has to include the substring │ │ │ │ │ + * "${layers}", which will be replaced by the layer specific │ │ │ │ │ + * attributions, separated by . The default is "${layers}". │ │ │ │ │ + */ │ │ │ │ │ + template: "${layers}", │ │ │ │ │ │ │ │ │ │ - // only check a baselayer if it is *the* baselayer, check data │ │ │ │ │ - // layers if they are visible │ │ │ │ │ - var checked = (baseLayer) ? (layer == this.map.baseLayer) : │ │ │ │ │ - layer.getVisibility(); │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Attribution │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Options for control. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // create input element │ │ │ │ │ - var inputElem = document.createElement("input"), │ │ │ │ │ - // The input shall have an id attribute so we can use │ │ │ │ │ - // labels to interact with them. │ │ │ │ │ - inputId = OpenLayers.Util.createUniqueID( │ │ │ │ │ - this.id + "_input_" │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy control. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "removelayer": this.updateAttribution, │ │ │ │ │ + "addlayer": this.updateAttribution, │ │ │ │ │ + "changelayer": this.updateAttribution, │ │ │ │ │ + "changebaselayer": this.updateAttribution, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - inputElem.id = inputId; │ │ │ │ │ - inputElem.name = (baseLayer) ? this.id + "_baseLayers" : layer.name; │ │ │ │ │ - inputElem.type = (baseLayer) ? "radio" : "checkbox"; │ │ │ │ │ - inputElem.value = layer.name; │ │ │ │ │ - inputElem.checked = checked; │ │ │ │ │ - inputElem.defaultChecked = checked; │ │ │ │ │ - inputElem.className = "olButton"; │ │ │ │ │ - inputElem._layer = layer.id; │ │ │ │ │ - inputElem._layerSwitcher = this.id; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (!baseLayer && !layer.inRange) { │ │ │ │ │ - inputElem.disabled = true; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Initialize control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - // create span │ │ │ │ │ - var labelSpan = document.createElement("label"); │ │ │ │ │ - // this isn't the DOM attribute 'for', but an arbitrary name we │ │ │ │ │ - // use to find the appropriate input element in │ │ │ │ │ - labelSpan["for"] = inputElem.id; │ │ │ │ │ - OpenLayers.Element.addClass(labelSpan, "labelSpan olButton"); │ │ │ │ │ - labelSpan._layer = layer.id; │ │ │ │ │ - labelSpan._layerSwitcher = this.id; │ │ │ │ │ - if (!baseLayer && !layer.inRange) { │ │ │ │ │ - labelSpan.style.color = "gray"; │ │ │ │ │ - } │ │ │ │ │ - labelSpan.innerHTML = layer.name; │ │ │ │ │ - labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : │ │ │ │ │ - "baseline"; │ │ │ │ │ - // create line break │ │ │ │ │ - var br = document.createElement("br"); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + 'changebaselayer': this.updateAttribution, │ │ │ │ │ + 'changelayer': this.updateAttribution, │ │ │ │ │ + 'addlayer': this.updateAttribution, │ │ │ │ │ + 'removelayer': this.updateAttribution, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.updateAttribution(); │ │ │ │ │ │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var groupArray = (baseLayer) ? this.baseLayers : │ │ │ │ │ - this.dataLayers; │ │ │ │ │ - groupArray.push({ │ │ │ │ │ - 'layer': layer, │ │ │ │ │ - 'inputElem': inputElem, │ │ │ │ │ - 'labelSpan': labelSpan │ │ │ │ │ + /** │ │ │ │ │ + * Method: updateAttribution │ │ │ │ │ + * Update attribution string. │ │ │ │ │ + */ │ │ │ │ │ + updateAttribution: function() { │ │ │ │ │ + var attributions = []; │ │ │ │ │ + if (this.map && this.map.layers) { │ │ │ │ │ + for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + if (layer.attribution && layer.getVisibility()) { │ │ │ │ │ + // add attribution only if attribution text is unique │ │ │ │ │ + if (OpenLayers.Util.indexOf( │ │ │ │ │ + attributions, layer.attribution) === -1) { │ │ │ │ │ + attributions.push(layer.attribution); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.div.innerHTML = OpenLayers.String.format(this.template, { │ │ │ │ │ + layers: attributions.join(this.separator) │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - var groupDiv = (baseLayer) ? this.baseLayersDiv : │ │ │ │ │ - this.dataLayersDiv; │ │ │ │ │ - groupDiv.appendChild(inputElem); │ │ │ │ │ - groupDiv.appendChild(labelSpan); │ │ │ │ │ - groupDiv.appendChild(br); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // if no overlays, dont display the overlay label │ │ │ │ │ - this.dataLbl.style.display = (containsOverlays) ? "" : "none"; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Attribution" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomOut.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // if no baselayers, dont display the baselayer label │ │ │ │ │ - this.baseLbl.style.display = (containsBaseLayers) ? "" : "none"; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomOut │ │ │ │ │ + * The ZoomOut control is a button to decrease the zoom level of a map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomOut = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateMap │ │ │ │ │ - * Cycles through the loaded data and base layer input arrays and makes │ │ │ │ │ - * the necessary calls to the Map object such that that the map's │ │ │ │ │ - * visual state corresponds to what the user has selected in │ │ │ │ │ - * the control. │ │ │ │ │ + * Method: trigger │ │ │ │ │ */ │ │ │ │ │ - updateMap: function() { │ │ │ │ │ - │ │ │ │ │ - // set the newly selected base layer │ │ │ │ │ - for (var i = 0, len = this.baseLayers.length; i < len; i++) { │ │ │ │ │ - var layerEntry = this.baseLayers[i]; │ │ │ │ │ - if (layerEntry.inputElem.checked) { │ │ │ │ │ - this.map.setBaseLayer(layerEntry.layer, false); │ │ │ │ │ - } │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // set the correct visibilities for the overlays │ │ │ │ │ - for (var i = 0, len = this.dataLayers.length; i < len; i++) { │ │ │ │ │ - var layerEntry = this.dataLayers[i]; │ │ │ │ │ - layerEntry.layer.setVisibility(layerEntry.inputElem.checked); │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomOut" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Zoom.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Zoom │ │ │ │ │ + * The Zoom control is a pair of +/- links for zooming in and out. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Zoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: maximizeControl │ │ │ │ │ - * Set up the labels and divs for the control │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * APIProperty: zoomInText │ │ │ │ │ + * {String} │ │ │ │ │ + * Text for zoom-in link. Default is "+". │ │ │ │ │ */ │ │ │ │ │ - maximizeControl: function(e) { │ │ │ │ │ + zoomInText: "+", │ │ │ │ │ │ │ │ │ │ - // set the div's width and height to empty values, so │ │ │ │ │ - // the div dimensions can be controlled by CSS │ │ │ │ │ - this.div.style.width = ""; │ │ │ │ │ - this.div.style.height = ""; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomInId │ │ │ │ │ + * {String} │ │ │ │ │ + * Instead of having the control create a zoom in link, you can provide │ │ │ │ │ + * the identifier for an anchor element already added to the document. │ │ │ │ │ + * By default, an element with id "olZoomInLink" will be searched for │ │ │ │ │ + * and used if it exists. │ │ │ │ │ + */ │ │ │ │ │ + zoomInId: "olZoomInLink", │ │ │ │ │ │ │ │ │ │ - this.showControls(false); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomOutText │ │ │ │ │ + * {String} │ │ │ │ │ + * Text for zoom-out link. Default is "\u2212". │ │ │ │ │ + */ │ │ │ │ │ + zoomOutText: "\u2212", │ │ │ │ │ │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomOutId │ │ │ │ │ + * {String} │ │ │ │ │ + * Instead of having the control create a zoom out link, you can provide │ │ │ │ │ + * the identifier for an anchor element already added to the document. │ │ │ │ │ + * By default, an element with id "olZoomOutLink" will be searched for │ │ │ │ │ + * and used if it exists. │ │ │ │ │ + */ │ │ │ │ │ + zoomOutId: "olZoomOutLink", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: minimizeControl │ │ │ │ │ - * Hide all the contents of the control, shrink the size, │ │ │ │ │ - * add the maximize icon │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DOMElement containing the zoom links. │ │ │ │ │ */ │ │ │ │ │ - minimizeControl: function(e) { │ │ │ │ │ - │ │ │ │ │ - // to minimize the control we set its div's width │ │ │ │ │ - // and height to 0px, we cannot just set "display" │ │ │ │ │ - // to "none" because it would hide the maximize │ │ │ │ │ - // div │ │ │ │ │ - this.div.style.width = "0px"; │ │ │ │ │ - this.div.style.height = "0px"; │ │ │ │ │ - │ │ │ │ │ - this.showControls(true); │ │ │ │ │ + draw: function() { │ │ │ │ │ + var div = OpenLayers.Control.prototype.draw.apply(this), │ │ │ │ │ + links = this.getOrCreateLinks(div), │ │ │ │ │ + zoomIn = links.zoomIn, │ │ │ │ │ + zoomOut = links.zoomOut, │ │ │ │ │ + eventsInstance = this.map.events; │ │ │ │ │ │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ + if (zoomOut.parentNode !== div) { │ │ │ │ │ + eventsInstance = this.events; │ │ │ │ │ + eventsInstance.attachToElement(zoomOut.parentNode); │ │ │ │ │ } │ │ │ │ │ + eventsInstance.register("buttonclick", this, this.onZoomClick); │ │ │ │ │ + │ │ │ │ │ + this.zoomInLink = zoomIn; │ │ │ │ │ + this.zoomOutLink = zoomOut; │ │ │ │ │ + return div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: showControls │ │ │ │ │ - * Hide/Show all LayerSwitcher controls depending on whether we are │ │ │ │ │ - * minimized or not │ │ │ │ │ - * │ │ │ │ │ + * Method: getOrCreateLinks │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * minimize - {Boolean} │ │ │ │ │ + * el - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Return: │ │ │ │ │ + * {Object} Object with zoomIn and zoomOut properties referencing links. │ │ │ │ │ */ │ │ │ │ │ - showControls: function(minimize) { │ │ │ │ │ - │ │ │ │ │ - this.maximizeDiv.style.display = minimize ? "" : "none"; │ │ │ │ │ - this.minimizeDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ - │ │ │ │ │ - this.layersDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ + getOrCreateLinks: function(el) { │ │ │ │ │ + var zoomIn = document.getElementById(this.zoomInId), │ │ │ │ │ + zoomOut = document.getElementById(this.zoomOutId); │ │ │ │ │ + if (!zoomIn) { │ │ │ │ │ + zoomIn = document.createElement("a"); │ │ │ │ │ + zoomIn.href = "#zoomIn"; │ │ │ │ │ + zoomIn.appendChild(document.createTextNode(this.zoomInText)); │ │ │ │ │ + zoomIn.className = "olControlZoomIn"; │ │ │ │ │ + el.appendChild(zoomIn); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Element.addClass(zoomIn, "olButton"); │ │ │ │ │ + if (!zoomOut) { │ │ │ │ │ + zoomOut = document.createElement("a"); │ │ │ │ │ + zoomOut.href = "#zoomOut"; │ │ │ │ │ + zoomOut.appendChild(document.createTextNode(this.zoomOutText)); │ │ │ │ │ + zoomOut.className = "olControlZoomOut"; │ │ │ │ │ + el.appendChild(zoomOut); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Element.addClass(zoomOut, "olButton"); │ │ │ │ │ + return { │ │ │ │ │ + zoomIn: zoomIn, │ │ │ │ │ + zoomOut: zoomOut │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: loadContents │ │ │ │ │ - * Set up the labels and divs for the control │ │ │ │ │ + * Method: onZoomClick │ │ │ │ │ + * Called when zoomin/out link is clicked. │ │ │ │ │ */ │ │ │ │ │ - loadContents: function() { │ │ │ │ │ - │ │ │ │ │ - // layers list div │ │ │ │ │ - this.layersDiv = document.createElement("div"); │ │ │ │ │ - this.layersDiv.id = this.id + "_layersDiv"; │ │ │ │ │ - OpenLayers.Element.addClass(this.layersDiv, "layersDiv"); │ │ │ │ │ - │ │ │ │ │ - this.baseLbl = document.createElement("div"); │ │ │ │ │ - this.baseLbl.innerHTML = OpenLayers.i18n("Base Layer"); │ │ │ │ │ - OpenLayers.Element.addClass(this.baseLbl, "baseLbl"); │ │ │ │ │ - │ │ │ │ │ - this.baseLayersDiv = document.createElement("div"); │ │ │ │ │ - OpenLayers.Element.addClass(this.baseLayersDiv, "baseLayersDiv"); │ │ │ │ │ - │ │ │ │ │ - this.dataLbl = document.createElement("div"); │ │ │ │ │ - this.dataLbl.innerHTML = OpenLayers.i18n("Overlays"); │ │ │ │ │ - OpenLayers.Element.addClass(this.dataLbl, "dataLbl"); │ │ │ │ │ - │ │ │ │ │ - this.dataLayersDiv = document.createElement("div"); │ │ │ │ │ - OpenLayers.Element.addClass(this.dataLayersDiv, "dataLayersDiv"); │ │ │ │ │ - │ │ │ │ │ - if (this.ascending) { │ │ │ │ │ - this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ - } else { │ │ │ │ │ - this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ + onZoomClick: function(evt) { │ │ │ │ │ + var button = evt.buttonElement; │ │ │ │ │ + if (button === this.zoomInLink) { │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + } else if (button === this.zoomOutLink) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.div.appendChild(this.layersDiv); │ │ │ │ │ - │ │ │ │ │ - // maximize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ - this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - "OpenLayers_Control_MaximizeDiv", │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - "absolute"); │ │ │ │ │ - OpenLayers.Element.addClass(this.maximizeDiv, "maximizeDiv olButton"); │ │ │ │ │ - this.maximizeDiv.style.display = "none"; │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(this.maximizeDiv); │ │ │ │ │ - │ │ │ │ │ - // minimize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ - this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - "OpenLayers_Control_MinimizeDiv", │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - "absolute"); │ │ │ │ │ - OpenLayers.Element.addClass(this.minimizeDiv, "minimizeDiv olButton"); │ │ │ │ │ - this.minimizeDiv.style.display = "none"; │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(this.minimizeDiv); │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.unregister("buttonclick", this, this.onZoomClick); │ │ │ │ │ + } │ │ │ │ │ + delete this.zoomInLink; │ │ │ │ │ + delete this.zoomOutLink; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.LayerSwitcher" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Zoom" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ArgParser.js │ │ │ │ │ + OpenLayers/Handler/Click.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ArgParser │ │ │ │ │ - * The ArgParser control adds location bar query string parsing functionality │ │ │ │ │ - * to an OpenLayers Map. │ │ │ │ │ - * When added to a Map control, on a page load/refresh, the Map will │ │ │ │ │ - * automatically take the href string and parse it for lon, lat, zoom, and │ │ │ │ │ - * layers information. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: center │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: single │ │ │ │ │ + * {Boolean} Handle single clicks. Default is true. If false, clicks │ │ │ │ │ + * will not be reported. If true, single-clicks will be reported. │ │ │ │ │ */ │ │ │ │ │ - center: null, │ │ │ │ │ + single: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: zoom │ │ │ │ │ - * {int} │ │ │ │ │ + * APIProperty: double │ │ │ │ │ + * {Boolean} Handle double-clicks. Default is false. │ │ │ │ │ */ │ │ │ │ │ - zoom: null, │ │ │ │ │ + 'double': false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layers │ │ │ │ │ - * {String} Each character represents the state of the corresponding layer │ │ │ │ │ - * on the map. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + pixelTolerance: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + dblclickTolerance: 13, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + stopSingle: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + stopDouble: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ + */ │ │ │ │ │ + timerId: 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. │ │ │ │ │ + */ │ │ │ │ │ + down: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} Requires proj4js support. │ │ │ │ │ - * Projection used when reading the coordinates from the URL. This will │ │ │ │ │ - * reproject the map coordinates from the URL into the map's │ │ │ │ │ - * projection. │ │ │ │ │ - * │ │ │ │ │ - * If you are using this functionality, be aware that any permalink │ │ │ │ │ - * which is added to the map will determine the coordinate type which │ │ │ │ │ - * is read from the URL, which means you should not add permalinks with │ │ │ │ │ - * different displayProjections to the same map. │ │ │ │ │ + * Property: first │ │ │ │ │ + * {Object} When waiting for double clicks, this object will store │ │ │ │ │ + * information about the first click in a two click sequence. │ │ │ │ │ */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ + first: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ArgParser │ │ │ │ │ - * │ │ │ │ │ + * Property: rightclickTimerId │ │ │ │ │ + * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + rightclickTimerId: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.Click │ │ │ │ │ + * Create a new click handler. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getParameters │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - getParameters: function(url) { │ │ │ │ │ - url = url || window.location.href; │ │ │ │ │ - var parameters = OpenLayers.Util.getParameters(url); │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + this.down = this.getEventInfo(evt); │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // If we have an anchor in the url use it to split the url │ │ │ │ │ - var index = url.indexOf('#'); │ │ │ │ │ - if (index > 0) { │ │ │ │ │ - // create an url to parse on the getParameters │ │ │ │ │ - url = '?' + url.substring(index + 1, url.length); │ │ │ │ │ + /** │ │ │ │ │ + * Method: touchmove │ │ │ │ │ + * Store position of last move, because touchend event can have │ │ │ │ │ + * an empty "touches" property. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ + */ │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Util.extend(parameters, │ │ │ │ │ - OpenLayers.Util.getParameters(url)); │ │ │ │ │ + /** │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ + * touches property from last touchstart or touchmove │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this 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; │ │ │ │ │ } │ │ │ │ │ - return parameters; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + mouseup: function(evt) { │ │ │ │ │ + var propagate = true; │ │ │ │ │ │ │ │ │ │ - //make sure we dont already have an arg parser attached │ │ │ │ │ - for (var i = 0, len = this.map.controls.length; i < len; i++) { │ │ │ │ │ - var control = this.map.controls[i]; │ │ │ │ │ - if ((control != this) && │ │ │ │ │ - (control.CLASS_NAME == "OpenLayers.Control.ArgParser")) { │ │ │ │ │ + // 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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // If a second argparser is added to the map, then we │ │ │ │ │ - // override the displayProjection to be the one added to the │ │ │ │ │ - // map. │ │ │ │ │ - if (control.displayProjection != this.displayProjection) { │ │ │ │ │ - this.displayProjection = control.displayProjection; │ │ │ │ │ - } │ │ │ │ │ + return propagate; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - break; │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (i == this.map.controls.length) { │ │ │ │ │ + return !this.stopSingle; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var args = this.getParameters(); │ │ │ │ │ - // Be careful to set layer first, to not trigger unnecessary layer loads │ │ │ │ │ - if (args.layers) { │ │ │ │ │ - this.layers = args.layers; │ │ │ │ │ + /** │ │ │ │ │ + * 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]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // when we add a new layer, set its visibility │ │ │ │ │ - this.map.events.register('addlayer', this, │ │ │ │ │ - this.configureLayers); │ │ │ │ │ - this.configureLayers(); │ │ │ │ │ - } │ │ │ │ │ - if (args.lat && args.lon) { │ │ │ │ │ - this.center = new OpenLayers.LonLat(parseFloat(args.lon), │ │ │ │ │ - parseFloat(args.lat)); │ │ │ │ │ - if (args.zoom) { │ │ │ │ │ - this.zoom = parseFloat(args.zoom); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // when we add a new baselayer to see when we can set the center │ │ │ │ │ - this.map.events.register('changebaselayer', this, │ │ │ │ │ - this.setCenter); │ │ │ │ │ - this.setCenter(); │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ + */ │ │ │ │ │ + dblclick: function(evt) { │ │ │ │ │ + this.handleDouble(evt); │ │ │ │ │ + return !this.stopDouble; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleDouble │ │ │ │ │ + * Handle double-click sequence. │ │ │ │ │ + */ │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setCenter │ │ │ │ │ - * As soon as a baseLayer has been loaded, we center and zoom │ │ │ │ │ - * ...and remove the handler. │ │ │ │ │ + * Method: handleSingle │ │ │ │ │ + * Handle single click sequence. │ │ │ │ │ */ │ │ │ │ │ - setCenter: function() { │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.map.baseLayer) { │ │ │ │ │ - //dont need to listen for this one anymore │ │ │ │ │ - this.map.events.unregister('changebaselayer', this, │ │ │ │ │ - this.setCenter); │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.displayProjection) { │ │ │ │ │ - this.center.transform(this.displayProjection, │ │ │ │ │ - this.map.getProjectionObject()); │ │ │ │ │ + /** │ │ │ │ │ + * 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). │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.map.setCenter(this.center, this.zoom); │ │ │ │ │ } │ │ │ │ │ + return passes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: configureLayers │ │ │ │ │ - * As soon as all the layers are loaded, cycle through them and │ │ │ │ │ - * hide or show them. │ │ │ │ │ + * Method: getTouchDistance │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The pixel displacement between two touches. │ │ │ │ │ */ │ │ │ │ │ - configureLayers: function() { │ │ │ │ │ + getTouchDistance: function(from, to) { │ │ │ │ │ + return Math.sqrt( │ │ │ │ │ + Math.pow(from.clientX - to.clientX, 2) + │ │ │ │ │ + Math.pow(from.clientY - to.clientY, 2) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.layers.length == this.map.layers.length) { │ │ │ │ │ - this.map.events.unregister('addlayer', this, this.configureLayers); │ │ │ │ │ + /** │ │ │ │ │ + * Method: passesDblclickTolerance │ │ │ │ │ + * Determine whether the event is within the optional double-cick pixel │ │ │ │ │ + * tolerance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The click is within the double-click pixel tolerance. │ │ │ │ │ + */ │ │ │ │ │ + passesDblclickTolerance: function(evt) { │ │ │ │ │ + var passes = true; │ │ │ │ │ + if (this.down && this.first) { │ │ │ │ │ + passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ + } │ │ │ │ │ + return passes; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearTimer │ │ │ │ │ + * Clear the timer and set to null. │ │ │ │ │ + */ │ │ │ │ │ + clearTimer: function() { │ │ │ │ │ + if (this.timerId != null) { │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.rightclickTimerId != null) { │ │ │ │ │ + window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ + this.rightclickTimerId = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - var c = this.layers.charAt(i); │ │ │ │ │ + /** │ │ │ │ │ + * Method: delayedCall │ │ │ │ │ + * Sets to null. And optionally triggers the click callback if │ │ │ │ │ + * evt is set. │ │ │ │ │ + */ │ │ │ │ │ + delayedCall: function(evt) { │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + if (evt) { │ │ │ │ │ + this.callback("click", [evt]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (c == "B") { │ │ │ │ │ - this.map.setBaseLayer(layer); │ │ │ │ │ - } else if ((c == "T") || (c == "F")) { │ │ │ │ │ - layer.setVisibility(c == "T"); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object with event related info. │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ArgParser" │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Permalink.js │ │ │ │ │ + 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/Control.js │ │ │ │ │ - * @requires OpenLayers/Control/ArgParser.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Permalink │ │ │ │ │ - * The Permalink control is hyperlink that will return the user to the │ │ │ │ │ - * current map view. By default it is drawn in the lower right corner of the │ │ │ │ │ - * map. The href is updated as the map is zoomed, panned and whilst layers │ │ │ │ │ - * are switched. │ │ │ │ │ - * │ │ │ │ │ + * 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.Control.Permalink = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: argParserClass │ │ │ │ │ - * {Class} The ArgParser control class (not instance) to use with this │ │ │ │ │ - * control. │ │ │ │ │ - */ │ │ │ │ │ - argParserClass: OpenLayers.Control.ArgParser, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - element: null, │ │ │ │ │ +OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: anchor │ │ │ │ │ - * {Boolean} This option changes 3 things: │ │ │ │ │ - * the character '#' is used in place of the character '?', │ │ │ │ │ - * the window.href is updated if no element is provided. │ │ │ │ │ - * When this option is set to true it's not recommend to provide │ │ │ │ │ - * a base without provide an element. │ │ │ │ │ + * Property: dragHandler │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - anchor: false, │ │ │ │ │ + dragHandler: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: base │ │ │ │ │ - * {String} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: boxDivClassName │ │ │ │ │ + * {String} The CSS class to use for drawing the box. Default is │ │ │ │ │ + * olHandlerBoxZoomBox │ │ │ │ │ */ │ │ │ │ │ - base: '', │ │ │ │ │ + boxDivClassName: 'olHandlerBoxZoomBox', │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} Requires proj4js support. Projection used │ │ │ │ │ - * when creating the coordinates in the link. This will reproject the │ │ │ │ │ - * map coordinates into display coordinates. If you are using this │ │ │ │ │ - * functionality, the permalink which is last added to the map will │ │ │ │ │ - * determine the coordinate type which is read from the URL, which │ │ │ │ │ - * means you should not add permalinks with different │ │ │ │ │ - * displayProjections to the same map. │ │ │ │ │ + /** │ │ │ │ │ + * Property: boxOffsets │ │ │ │ │ + * {Object} Caches box offsets from css. This is used by the getBoxOffsets │ │ │ │ │ + * method. │ │ │ │ │ */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ + boxOffsets: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Permalink │ │ │ │ │ + * Constructor: OpenLayers.Handler.Box │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * base - {String} │ │ │ │ │ - * options - {Object} options to the control. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} │ │ │ │ │ + * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ + * functions. Various callbacks described below. │ │ │ │ │ + * options - {Object} │ │ │ │ │ * │ │ │ │ │ - * Or for anchor: │ │ │ │ │ - * options - {Object} options to the control. │ │ │ │ │ + * 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(element, base, options) { │ │ │ │ │ - if (element !== null && typeof element == 'object' && !OpenLayers.Util.isElement(element)) { │ │ │ │ │ - options = element; │ │ │ │ │ - this.base = document.location.href; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - if (this.element != null) { │ │ │ │ │ - this.element = OpenLayers.Util.getElement(this.element); │ │ │ │ │ + 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 │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.element = OpenLayers.Util.getElement(element); │ │ │ │ │ - this.base = base || document.location.href; │ │ │ │ │ - } │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - if (this.element && this.element.parentNode == this.div) { │ │ │ │ │ - this.div.removeChild(this.element); │ │ │ │ │ - this.element = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.unregister('moveend', this, this.updateLink); │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ + if (this.dragHandler) { │ │ │ │ │ + this.dragHandler.destroy(); │ │ │ │ │ + this.dragHandler = null; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ */ │ │ │ │ │ setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - //make sure we have an arg parser attached │ │ │ │ │ - for (var i = 0, len = this.map.controls.length; i < len; i++) { │ │ │ │ │ - var control = this.map.controls[i]; │ │ │ │ │ - if (control.CLASS_NAME == this.argParserClass.CLASS_NAME) { │ │ │ │ │ - │ │ │ │ │ - // If a permalink is added to the map, and an ArgParser already │ │ │ │ │ - // exists, we override the displayProjection to be the one │ │ │ │ │ - // on the permalink. │ │ │ │ │ - if (control.displayProjection != this.displayProjection) { │ │ │ │ │ - this.displayProjection = control.displayProjection; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (i == this.map.controls.length) { │ │ │ │ │ - this.map.addControl(new this.argParserClass({ │ │ │ │ │ - 'displayProjection': this.displayProjection │ │ │ │ │ - })); │ │ │ │ │ + OpenLayers.Handler.prototype.setMap.apply(this, arguments); │ │ │ │ │ + if (this.dragHandler) { │ │ │ │ │ + this.dragHandler.setMap(map); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: startBox │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (!this.element && !this.anchor) { │ │ │ │ │ - this.element = document.createElement("a"); │ │ │ │ │ - this.element.innerHTML = OpenLayers.i18n("Permalink"); │ │ │ │ │ - this.element.href = ""; │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ - } │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - 'moveend': this.updateLink, │ │ │ │ │ - 'changelayer': this.updateLink, │ │ │ │ │ - 'changebaselayer': this.updateLink, │ │ │ │ │ - scope: this │ │ │ │ │ + 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; │ │ │ │ │ │ │ │ │ │ - // Make it so there is at least a link even though the map may not have │ │ │ │ │ - // moved yet. │ │ │ │ │ - this.updateLink(); │ │ │ │ │ + this.map.viewPortDiv.appendChild(this.zoomBox); │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ + OpenLayers.Element.addClass( │ │ │ │ │ + this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateLink │ │ │ │ │ + * Method: moveBox │ │ │ │ │ */ │ │ │ │ │ - updateLink: function() { │ │ │ │ │ - var separator = this.anchor ? '#' : '?'; │ │ │ │ │ - var href = this.base; │ │ │ │ │ - var anchor = null; │ │ │ │ │ - if (href.indexOf("#") != -1 && this.anchor == false) { │ │ │ │ │ - anchor = href.substring(href.indexOf("#"), href.length); │ │ │ │ │ - } │ │ │ │ │ - if (href.indexOf(separator) != -1) { │ │ │ │ │ - href = href.substring(0, href.indexOf(separator)); │ │ │ │ │ - } │ │ │ │ │ - var splits = href.split("#"); │ │ │ │ │ - href = splits[0] + separator + OpenLayers.Util.getParameterString(this.createParams()); │ │ │ │ │ - if (anchor) { │ │ │ │ │ - href += anchor; │ │ │ │ │ - } │ │ │ │ │ - if (this.anchor && !this.element) { │ │ │ │ │ - window.location.href = href; │ │ │ │ │ - } else { │ │ │ │ │ - this.element.href = href; │ │ │ │ │ - } │ │ │ │ │ + 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"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createParams │ │ │ │ │ - * Creates the parameters that need to be encoded into the permalink url. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * center - {} center to encode in the permalink. │ │ │ │ │ - * Defaults to the current map center. │ │ │ │ │ - * zoom - {Integer} zoom level to encode in the permalink. Defaults to the │ │ │ │ │ - * current map zoom level. │ │ │ │ │ - * layers - {Array()} layers to encode in the permalink. │ │ │ │ │ - * Defaults to the current map layers. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Hash of parameters that will be url-encoded into the │ │ │ │ │ - * permalink. │ │ │ │ │ + * Method: endBox │ │ │ │ │ */ │ │ │ │ │ - createParams: function(center, zoom, layers) { │ │ │ │ │ - center = center || this.map.getCenter(); │ │ │ │ │ - │ │ │ │ │ - var params = OpenLayers.Util.getParameters(this.base); │ │ │ │ │ - │ │ │ │ │ - // If there's still no center, map is not initialized yet. │ │ │ │ │ - // Break out of this function, and simply return the params from the │ │ │ │ │ - // base link. │ │ │ │ │ - if (center) { │ │ │ │ │ + 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(); │ │ │ │ │ │ │ │ │ │ - //zoom │ │ │ │ │ - params.zoom = zoom || this.map.getZoom(); │ │ │ │ │ + this.callback("done", [result]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //lon,lat │ │ │ │ │ - var lat = center.lat; │ │ │ │ │ - var lon = center.lon; │ │ │ │ │ + /** │ │ │ │ │ + * 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" │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - if (this.displayProjection) { │ │ │ │ │ - var mapPosition = OpenLayers.Projection.transform({ │ │ │ │ │ - x: lon, │ │ │ │ │ - y: lat │ │ │ │ │ - }, │ │ │ │ │ - this.map.getProjectionObject(), │ │ │ │ │ - this.displayProjection); │ │ │ │ │ - lon = mapPosition.x; │ │ │ │ │ - lat = mapPosition.y; │ │ │ │ │ - } │ │ │ │ │ - params.lat = Math.round(lat * 100000) / 100000; │ │ │ │ │ - params.lon = Math.round(lon * 100000) / 100000; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //layers │ │ │ │ │ - layers = layers || this.map.layers; │ │ │ │ │ - params.layers = ''; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - var layer = layers[i]; │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragHandler.activate(); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (layer.isBaseLayer) { │ │ │ │ │ - params.layers += (layer == this.map.baseLayer) ? "B" : "0"; │ │ │ │ │ - } else { │ │ │ │ │ - params.layers += (layer.getVisibility()) ? "T" : "F"; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return params; │ │ │ │ │ + /** │ │ │ │ │ + * 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.Control.Permalink" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Box" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/MouseWheel.js │ │ │ │ │ + OpenLayers/Handler/Hover.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.MouseWheel │ │ │ │ │ - * Handler for wheel up/down events. │ │ │ │ │ + * 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.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: wheelListener │ │ │ │ │ - * {function} │ │ │ │ │ +OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: delay │ │ │ │ │ + * {Integer} - Number of milliseconds between mousemoves before │ │ │ │ │ + * the event is considered a hover. Default is 500. │ │ │ │ │ */ │ │ │ │ │ - wheelListener: null, │ │ │ │ │ + delay: 500, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: pixelTolerance │ │ │ │ │ + * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ + * an event to be considered a hover. Default is null. │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + pixelTolerance: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: stopMove │ │ │ │ │ + * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - maxDelta: Number.POSITIVE_INFINITY, │ │ │ │ │ + stopMove: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: px │ │ │ │ │ + * {} - The location of the last mousemove, expressed │ │ │ │ │ + * in pixels. │ │ │ │ │ */ │ │ │ │ │ - delta: 0, │ │ │ │ │ + px: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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) │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * {Number} - The id of the timer. │ │ │ │ │ */ │ │ │ │ │ - cumulative: true, │ │ │ │ │ + timerId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.MouseWheel │ │ │ │ │ + * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ + * Construct a hover handler. │ │ │ │ │ * │ │ │ │ │ * 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} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.wheelListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ - this.onWheelEvent, this │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: mousemove │ │ │ │ │ + * Called when the mouse moves on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - this.wheelListener = null; │ │ │ │ │ + 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 │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return !this.stopMove; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onWheelEvent │ │ │ │ │ - * Catch the wheel event and handle it xbrowserly │ │ │ │ │ - * │ │ │ │ │ + * Method: mouseout │ │ │ │ │ + * Called when the mouse goes out of the map. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * evt - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - onWheelEvent: function(e) { │ │ │ │ │ - │ │ │ │ │ - // make sure we have a map and check keyboard modifiers │ │ │ │ │ - if (!this.map || !this.checkModifiers(e)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // 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 elem = OpenLayers.Event.element(e); │ │ │ │ │ - while ((elem != null) && !overMapDiv && !overScrollableDiv) { │ │ │ │ │ - │ │ │ │ │ - if (!overScrollableDiv) { │ │ │ │ │ - try { │ │ │ │ │ - var overflow; │ │ │ │ │ - if (elem.currentStyle) { │ │ │ │ │ - overflow = elem.currentStyle["overflow"]; │ │ │ │ │ - } else { │ │ │ │ │ - var style = │ │ │ │ │ - document.defaultView.getComputedStyle(elem, null); │ │ │ │ │ - overflow = style.getPropertyValue("overflow"); │ │ │ │ │ - } │ │ │ │ │ - overScrollableDiv = (overflow && │ │ │ │ │ - (overflow == "auto") || (overflow == "scroll")); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - //sometimes when scrolling in a popup, this causes │ │ │ │ │ - // obscure browser error │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - overMapDiv = (elem == this.map.div); │ │ │ │ │ - │ │ │ │ │ - elem = elem.parentNode; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // 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; │ │ │ │ │ - │ │ │ │ │ - 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; │ │ │ │ │ - │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ + mouseout: function(evt) { │ │ │ │ │ + if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + this.callback('move', [evt]); │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: passesTolerance │ │ │ │ │ + * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ */ │ │ │ │ │ - wheelZoom: function(e) { │ │ │ │ │ - var delta = this.delta; │ │ │ │ │ - this.delta = 0; │ │ │ │ │ - │ │ │ │ │ - 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]); │ │ │ │ │ + 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: activate │ │ │ │ │ + * Method: clearTimer │ │ │ │ │ + * Clear the timer and set to null. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + clearTimer: function() { │ │ │ │ │ + if (this.timerId != null) { │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: delayedCall │ │ │ │ │ + * Triggers pause callback. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function(evt) { │ │ │ │ │ + delayedCall: function(evt) { │ │ │ │ │ + this.callback('pause', [evt]); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ 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; │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + deactivated = true; │ │ │ │ │ } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.MouseWheel" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Hover" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Navigation.js │ │ │ │ │ + OpenLayers/Control/GetFeature.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/Control/ZoomBox.js │ │ │ │ │ - * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ - * @requires OpenLayers/Handler/MouseWheel.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler/Box.js │ │ │ │ │ + * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ + * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Navigation │ │ │ │ │ - * The navigation control handles map browsing with mouse events (dragging, │ │ │ │ │ - * double-clicking, and scrolling the wheel). Create a new navigation │ │ │ │ │ - * control with the control. │ │ │ │ │ - * │ │ │ │ │ - * Note that this control is added to the map by default (if no controls │ │ │ │ │ - * array is sent in the options object to the │ │ │ │ │ - * constructor). │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ + * Class: OpenLayers.Control.GetFeature │ │ │ │ │ + * Gets vector features for locations underneath the mouse cursor. Can be │ │ │ │ │ + * configured to act on click, hover or dragged boxes. Uses an │ │ │ │ │ + * that supports spatial filters to retrieve │ │ │ │ │ + * features from a server and fires events that notify applications of the │ │ │ │ │ + * selected features. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragPan │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: protocol │ │ │ │ │ + * {} Required. The protocol used for fetching │ │ │ │ │ + * features. │ │ │ │ │ */ │ │ │ │ │ - dragPan: null, │ │ │ │ │ + protocol: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dragPanOptions │ │ │ │ │ - * {Object} Options passed to the DragPan control. │ │ │ │ │ + * APIProperty: multipleKey │ │ │ │ │ + * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ + * the property to true. Default is null. │ │ │ │ │ */ │ │ │ │ │ - dragPanOptions: null, │ │ │ │ │ + multipleKey: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinchZoom │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: toggleKey │ │ │ │ │ + * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ + * the property to true. Default is null. │ │ │ │ │ */ │ │ │ │ │ - pinchZoom: null, │ │ │ │ │ + toggleKey: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pinchZoomOptions │ │ │ │ │ - * {Object} Options passed to the PinchZoom control. │ │ │ │ │ + * Property: modifiers │ │ │ │ │ + * {Object} The event modifiers to use, according to the current event │ │ │ │ │ + * being handled by this control's handlers │ │ │ │ │ */ │ │ │ │ │ - pinchZoomOptions: null, │ │ │ │ │ + modifiers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: multiple │ │ │ │ │ + * {Boolean} Allow selection of multiple geometries. Default is false. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + multiple: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomBox │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: click │ │ │ │ │ + * {Boolean} Use a click handler for selecting/unselecting features. If │ │ │ │ │ + * both and are set to true, the click handler takes │ │ │ │ │ + * precedence over the box handler if a box with zero extent was │ │ │ │ │ + * selected. Default is true. │ │ │ │ │ */ │ │ │ │ │ - zoomBox: null, │ │ │ │ │ + click: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomBoxEnabled │ │ │ │ │ - * {Boolean} Whether the user can draw a box to zoom │ │ │ │ │ + * APIProperty: single │ │ │ │ │ + * {Boolean} Tells whether select by click should select a single │ │ │ │ │ + * feature. If set to false, all matching features are selected. │ │ │ │ │ + * If set to true, only the best matching feature is selected. │ │ │ │ │ + * This option has an effect only of the option is set │ │ │ │ │ + * to true. Default is true. │ │ │ │ │ */ │ │ │ │ │ - zoomBoxEnabled: true, │ │ │ │ │ + single: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomWheelEnabled │ │ │ │ │ - * {Boolean} Whether the mousewheel should zoom the map │ │ │ │ │ + * APIProperty: clickout │ │ │ │ │ + * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ + * Applies only if is true. Default is true. │ │ │ │ │ */ │ │ │ │ │ - zoomWheelEnabled: true, │ │ │ │ │ + clickout: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: mouseWheelOptions │ │ │ │ │ - * {Object} Options passed to the MouseWheel control (only useful if │ │ │ │ │ - * is set to true). Default is no options for maps │ │ │ │ │ - * with fractionalZoom set to true, otherwise │ │ │ │ │ - * {cumulative: false, interval: 50, maxDelta: 6} │ │ │ │ │ + * APIProperty: toggle │ │ │ │ │ + * {Boolean} Unselect a selected feature on click. Applies only if │ │ │ │ │ + * is true. Default is false. │ │ │ │ │ */ │ │ │ │ │ - mouseWheelOptions: null, │ │ │ │ │ + toggle: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handleRightClicks │ │ │ │ │ - * {Boolean} Whether or not to handle right clicks. Default is false. │ │ │ │ │ + * APIProperty: clickTolerance │ │ │ │ │ + * {Integer} Tolerance for the filter query in pixels. This has the │ │ │ │ │ + * same effect as the tolerance parameter on WMS GetFeatureInfo │ │ │ │ │ + * requests. Will be ignored for box selections. Applies only if │ │ │ │ │ + * or is true. Default is 5. Note that this not │ │ │ │ │ + * only affects requests on click, but also on hover. │ │ │ │ │ */ │ │ │ │ │ - handleRightClicks: false, │ │ │ │ │ + clickTolerance: 5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomBoxKeyMask │ │ │ │ │ - * {Integer} key code of the key, which has to be │ │ │ │ │ - * pressed, while drawing the zoom box with the mouse on the screen. │ │ │ │ │ - * You should probably set handleRightClicks to true if you use this │ │ │ │ │ - * with MOD_CTRL, to disable the context menu for machines which use │ │ │ │ │ - * CTRL-Click as a right click. │ │ │ │ │ - * Default: │ │ │ │ │ + * APIProperty: hover │ │ │ │ │ + * {Boolean} Send feature requests on mouse moves. Default is false. │ │ │ │ │ */ │ │ │ │ │ - zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT, │ │ │ │ │ + hover: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * APIProperty: box │ │ │ │ │ + * {Boolean} Allow feature selection by drawing a box. If set to │ │ │ │ │ + * true set to false to disable the click handler and │ │ │ │ │ + * rely on the box handler only, even for "zero extent" boxes. │ │ │ │ │ + * See the description of the option for additional │ │ │ │ │ + * information. Default is false. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + box: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Navigation │ │ │ │ │ - * Create a new navigation control │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ + * APIProperty: maxFeatures │ │ │ │ │ + * {Integer} Maximum number of features to return from a query in single mode │ │ │ │ │ + * if supported by the . This set of features is then used to │ │ │ │ │ + * determine the best match client-side. Default is 10. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + maxFeatures: 10, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: features │ │ │ │ │ + * {Object} Hash of {}, keyed by fid, holding │ │ │ │ │ + * the currently selected features │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ + features: null, │ │ │ │ │ │ │ │ │ │ - if (this.dragPan) { │ │ │ │ │ - this.dragPan.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.dragPan = null; │ │ │ │ │ + /** │ │ │ │ │ + * Proeprty: hoverFeature │ │ │ │ │ + * {} The feature currently selected by the │ │ │ │ │ + * hover handler │ │ │ │ │ + */ │ │ │ │ │ + hoverFeature: null, │ │ │ │ │ │ │ │ │ │ - if (this.zoomBox) { │ │ │ │ │ - this.zoomBox.destroy(); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Additional options for the handlers used by this control. This │ │ │ │ │ + * is a hash with the keys "click", "box" and "hover". │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handlers │ │ │ │ │ + * {Object} Object with references to multiple │ │ │ │ │ + * instances. │ │ │ │ │ + */ │ │ │ │ │ + handlers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: hoverResponse │ │ │ │ │ + * {} The response object associated with │ │ │ │ │ + * the currently running hover request (if any). │ │ │ │ │ + */ │ │ │ │ │ + hoverResponse: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: filterType │ │ │ │ │ + * {} The type of filter to use when sending off a request. │ │ │ │ │ + * Possible values: │ │ │ │ │ + * OpenLayers.Filter.Spatial. │ │ │ │ │ + * Defaults to: OpenLayers.Filter.Spatial.BBOX │ │ │ │ │ + */ │ │ │ │ │ + filterType: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * beforefeatureselected - Triggered when is true before a │ │ │ │ │ + * feature is selected. The event object has a feature property with │ │ │ │ │ + * the feature about to select │ │ │ │ │ + * featureselected - Triggered when is true and a feature is │ │ │ │ │ + * selected. The event object has a feature property with the │ │ │ │ │ + * selected feature │ │ │ │ │ + * beforefeaturesselected - Triggered when is true before a │ │ │ │ │ + * set of features is selected. The event object is an array of │ │ │ │ │ + * feature properties with the features about to be selected. │ │ │ │ │ + * Return false after receiving this event to discontinue processing │ │ │ │ │ + * of all featureselected events and the featuresselected event. │ │ │ │ │ + * featuresselected - Triggered when is true and a set of │ │ │ │ │ + * features is selected. The event object is an array of feature │ │ │ │ │ + * properties of the selected features │ │ │ │ │ + * featureunselected - Triggered when is true and a feature is │ │ │ │ │ + * unselected. The event object has a feature property with the │ │ │ │ │ + * unselected feature │ │ │ │ │ + * clickout - Triggered when when is true and no feature was │ │ │ │ │ + * selected. │ │ │ │ │ + * hoverfeature - Triggered when is true and the mouse has │ │ │ │ │ + * stopped over a feature │ │ │ │ │ + * outfeature - Triggered when is true and the mouse moves │ │ │ │ │ + * moved away from a hover-selected feature │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.GetFeature │ │ │ │ │ + * Create a new control for fetching remote features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} A configuration object which at least has to contain │ │ │ │ │ + * a property (if not, it has to be set before a request is │ │ │ │ │ + * made) │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + this.features = {}; │ │ │ │ │ + │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + │ │ │ │ │ + if (this.click) { │ │ │ │ │ + this.handlers.click = new OpenLayers.Handler.Click(this, { │ │ │ │ │ + click: this.selectClick │ │ │ │ │ + }, this.handlerOptions.click || {}); │ │ │ │ │ } │ │ │ │ │ - this.zoomBox = null; │ │ │ │ │ │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.destroy(); │ │ │ │ │ + if (this.box) { │ │ │ │ │ + this.handlers.box = new OpenLayers.Handler.Box( │ │ │ │ │ + this, { │ │ │ │ │ + done: this.selectBox │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend(this.handlerOptions.box, { │ │ │ │ │ + boxDivClassName: "olHandlerBoxSelectFeature" │ │ │ │ │ + }) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - this.pinchZoom = null; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + if (this.hover) { │ │ │ │ │ + this.handlers.hover = new OpenLayers.Handler.Hover( │ │ │ │ │ + this, { │ │ │ │ │ + 'move': this.cancelHover, │ │ │ │ │ + 'pause': this.selectHover │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend(this.handlerOptions.hover, { │ │ │ │ │ + 'delay': 250, │ │ │ │ │ + 'pixelTolerance': 2 │ │ │ │ │ + }) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: activate │ │ │ │ │ + * Activates the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The control was effectively activated. │ │ │ │ │ */ │ │ │ │ │ activate: function() { │ │ │ │ │ - this.dragPan.activate(); │ │ │ │ │ - if (this.zoomWheelEnabled) { │ │ │ │ │ - this.handlers.wheel.activate(); │ │ │ │ │ - } │ │ │ │ │ - this.handlers.click.activate(); │ │ │ │ │ - if (this.zoomBoxEnabled) { │ │ │ │ │ - this.zoomBox.activate(); │ │ │ │ │ - } │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.activate(); │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + for (var i in this.handlers) { │ │ │ │ │ + this.handlers[i].activate(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Control.prototype.activate.apply(this, arguments); │ │ │ │ │ + return OpenLayers.Control.prototype.activate.apply( │ │ │ │ │ + this, arguments │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: deactivate │ │ │ │ │ + * Deactivates the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The control was effectively deactivated. │ │ │ │ │ */ │ │ │ │ │ deactivate: function() { │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.deactivate(); │ │ │ │ │ + if (this.active) { │ │ │ │ │ + for (var i in this.handlers) { │ │ │ │ │ + this.handlers[i].deactivate(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.zoomBox.deactivate(); │ │ │ │ │ - this.dragPan.deactivate(); │ │ │ │ │ - this.handlers.click.deactivate(); │ │ │ │ │ - this.handlers.wheel.deactivate(); │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ + this, arguments │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: selectClick │ │ │ │ │ + * Called on click │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - // disable right mouse context menu for support of right click events │ │ │ │ │ - if (this.handleRightClicks) { │ │ │ │ │ - this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ + selectClick: function(evt) { │ │ │ │ │ + var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ │ │ │ │ │ - var clickCallbacks = { │ │ │ │ │ - 'click': this.defaultClick, │ │ │ │ │ - 'dblclick': this.defaultDblClick, │ │ │ │ │ - 'dblrightclick': this.defaultDblRightClick │ │ │ │ │ - }; │ │ │ │ │ - var clickOptions = { │ │ │ │ │ - 'double': true, │ │ │ │ │ - 'stopDouble': true │ │ │ │ │ - }; │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ - this, clickCallbacks, clickOptions │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }, this.dragPanOptions) │ │ │ │ │ - ); │ │ │ │ │ - this.zoomBox = new OpenLayers.Control.ZoomBox({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - keyMask: this.zoomBoxKeyMask │ │ │ │ │ + this.setModifiers(evt); │ │ │ │ │ + this.request(bounds, { │ │ │ │ │ + single: this.single │ │ │ │ │ }); │ │ │ │ │ - this.dragPan.draw(); │ │ │ │ │ - this.zoomBox.draw(); │ │ │ │ │ - var wheelOptions = this.map.fractionalZoom ? {} : { │ │ │ │ │ - cumulative: false, │ │ │ │ │ - interval: 50, │ │ │ │ │ - maxDelta: 6 │ │ │ │ │ - }; │ │ │ │ │ - this.handlers.wheel = new OpenLayers.Handler.MouseWheel( │ │ │ │ │ - this, { │ │ │ │ │ - up: this.wheelUp, │ │ │ │ │ - down: this.wheelDown │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(wheelOptions, this.mouseWheelOptions) │ │ │ │ │ - ); │ │ │ │ │ - if (OpenLayers.Control.PinchZoom) { │ │ │ │ │ - this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map │ │ │ │ │ - }, this.pinchZoomOptions)); │ │ │ │ │ - } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultClick │ │ │ │ │ + * Method: selectBox │ │ │ │ │ + * Callback from the handlers.box set up when selection is on │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * position - {|Object} An OpenLayers.Bounds or │ │ │ │ │ + * an object with a 'left', 'bottom', 'right' and 'top' properties. │ │ │ │ │ */ │ │ │ │ │ - defaultClick: function(evt) { │ │ │ │ │ - if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + selectBox: function(position) { │ │ │ │ │ + var bounds; │ │ │ │ │ + if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ + var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.left, │ │ │ │ │ + y: position.bottom │ │ │ │ │ + }); │ │ │ │ │ + var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.right, │ │ │ │ │ + y: position.top │ │ │ │ │ + }); │ │ │ │ │ + bounds = new OpenLayers.Bounds( │ │ │ │ │ + minXY.lon, minXY.lat, maxXY.lon, maxXY.lat │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + } else { │ │ │ │ │ + if (this.click) { │ │ │ │ │ + // box without extent - let the click handler take care of it │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + bounds = this.pixelToBounds(position); │ │ │ │ │ } │ │ │ │ │ + this.setModifiers(this.handlers.box.dragHandler.evt); │ │ │ │ │ + this.request(bounds); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblClick │ │ │ │ │ - * │ │ │ │ │ + * Method: selectHover │ │ │ │ │ + * Callback from the handlers.hover set up when selection is on │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Object} event object with an xy property │ │ │ │ │ */ │ │ │ │ │ - defaultDblClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + selectHover: function(evt) { │ │ │ │ │ + var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ + this.request(bounds, { │ │ │ │ │ + single: true, │ │ │ │ │ + hover: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblRightClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: cancelHover │ │ │ │ │ + * Callback from the handlers.hover set up when selection is on │ │ │ │ │ */ │ │ │ │ │ - defaultDblRightClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom - 1, evt.xy); │ │ │ │ │ + cancelHover: function() { │ │ │ │ │ + if (this.hoverResponse) { │ │ │ │ │ + this.protocol.abort(this.hoverResponse); │ │ │ │ │ + this.hoverResponse = null; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: wheelChange │ │ │ │ │ - * │ │ │ │ │ + * Method: request │ │ │ │ │ + * Sends a GetFeature request to the WFS │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * deltaZ - {Integer} │ │ │ │ │ + * bounds - {} bounds for the request's BBOX filter │ │ │ │ │ + * options - {Object} additional options for this method. │ │ │ │ │ + * │ │ │ │ │ + * Supported options include: │ │ │ │ │ + * single - {Boolean} A single feature should be returned. │ │ │ │ │ + * Note that this will be ignored if the protocol does not │ │ │ │ │ + * return the geometries of the features. │ │ │ │ │ + * hover - {Boolean} Do the request for the hover handler. │ │ │ │ │ */ │ │ │ │ │ - wheelChange: function(evt, deltaZ) { │ │ │ │ │ - if (!this.map.fractionalZoom) { │ │ │ │ │ - deltaZ = Math.round(deltaZ); │ │ │ │ │ - } │ │ │ │ │ - var currentZoom = this.map.getZoom(), │ │ │ │ │ - newZoom = currentZoom + deltaZ; │ │ │ │ │ - newZoom = Math.max(newZoom, 0); │ │ │ │ │ - newZoom = Math.min(newZoom, this.map.getNumZoomLevels()); │ │ │ │ │ - if (newZoom === currentZoom) { │ │ │ │ │ - return; │ │ │ │ │ + request: function(bounds, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: this.filterType, │ │ │ │ │ + value: bounds │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + // Set the cursor to "wait" to tell the user we're working. │ │ │ │ │ + OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + │ │ │ │ │ + var response = this.protocol.read({ │ │ │ │ │ + maxFeatures: options.single == true ? this.maxFeatures : undefined, │ │ │ │ │ + filter: filter, │ │ │ │ │ + callback: function(result) { │ │ │ │ │ + if (result.success()) { │ │ │ │ │ + if (result.features.length) { │ │ │ │ │ + if (options.single == true) { │ │ │ │ │ + this.selectBestFeature(result.features, │ │ │ │ │ + bounds.getCenterLonLat(), options); │ │ │ │ │ + } else { │ │ │ │ │ + this.select(result.features); │ │ │ │ │ + } │ │ │ │ │ + } else if (options.hover) { │ │ │ │ │ + this.hoverSelect(); │ │ │ │ │ + } else { │ │ │ │ │ + this.events.triggerEvent("clickout"); │ │ │ │ │ + if (this.clickout) { │ │ │ │ │ + this.unselectAll(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // Reset the cursor. │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + if (options.hover == true) { │ │ │ │ │ + this.hoverResponse = response; │ │ │ │ │ } │ │ │ │ │ - this.map.zoomTo(newZoom, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: wheelUp │ │ │ │ │ - * User spun scroll wheel up │ │ │ │ │ + /** │ │ │ │ │ + * Method: selectBestFeature │ │ │ │ │ + * Selects the feature from an array of features that is the best match │ │ │ │ │ + * for the click position. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * delta - {Integer} │ │ │ │ │ + * features - {Array()} │ │ │ │ │ + * clickPosition - {} │ │ │ │ │ + * options - {Object} additional options for this method │ │ │ │ │ + * │ │ │ │ │ + * Supported options include: │ │ │ │ │ + * hover - {Boolean} Do the selection for the hover handler. │ │ │ │ │ */ │ │ │ │ │ - wheelUp: function(evt, delta) { │ │ │ │ │ - this.wheelChange(evt, delta || 1); │ │ │ │ │ + selectBestFeature: function(features, clickPosition, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + if (features.length) { │ │ │ │ │ + var point = new OpenLayers.Geometry.Point(clickPosition.lon, │ │ │ │ │ + clickPosition.lat); │ │ │ │ │ + var feature, resultFeature, dist; │ │ │ │ │ + var minDist = Number.MAX_VALUE; │ │ │ │ │ + for (var i = 0; i < features.length; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + dist = point.distanceTo(feature.geometry, { │ │ │ │ │ + edge: false │ │ │ │ │ + }); │ │ │ │ │ + if (dist < minDist) { │ │ │ │ │ + minDist = dist; │ │ │ │ │ + resultFeature = feature; │ │ │ │ │ + if (minDist == 0) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (options.hover == true) { │ │ │ │ │ + this.hoverSelect(resultFeature); │ │ │ │ │ + } else { │ │ │ │ │ + this.select(resultFeature || features); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: wheelDown │ │ │ │ │ - * User spun scroll wheel down │ │ │ │ │ + /** │ │ │ │ │ + * Method: setModifiers │ │ │ │ │ + * Sets the multiple and toggle modifiers according to the current event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * delta - {Integer} │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - wheelDown: function(evt, delta) { │ │ │ │ │ - this.wheelChange(evt, delta || -1); │ │ │ │ │ + setModifiers: function(evt) { │ │ │ │ │ + this.modifiers = { │ │ │ │ │ + multiple: this.multiple || (this.multipleKey && evt[this.multipleKey]), │ │ │ │ │ + toggle: this.toggle || (this.toggleKey && evt[this.toggleKey]) │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: disableZoomBox │ │ │ │ │ + * Method: select │ │ │ │ │ + * Add feature to the hash of selected features and trigger the │ │ │ │ │ + * featureselected and featuresselected events. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {} or an array of features │ │ │ │ │ */ │ │ │ │ │ - disableZoomBox: function() { │ │ │ │ │ - this.zoomBoxEnabled = false; │ │ │ │ │ - this.zoomBox.deactivate(); │ │ │ │ │ + select: function(features) { │ │ │ │ │ + if (!this.modifiers.multiple && !this.modifiers.toggle) { │ │ │ │ │ + this.unselectAll(); │ │ │ │ │ + } │ │ │ │ │ + if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ + features = [features]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var cont = this.events.triggerEvent("beforefeaturesselected", { │ │ │ │ │ + features: features │ │ │ │ │ + }); │ │ │ │ │ + if (cont !== false) { │ │ │ │ │ + var selectedFeatures = []; │ │ │ │ │ + var feature; │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + if (this.features[feature.fid || feature.id]) { │ │ │ │ │ + if (this.modifiers.toggle) { │ │ │ │ │ + this.unselect(this.features[feature.fid || feature.id]); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + cont = this.events.triggerEvent("beforefeatureselected", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + if (cont !== false) { │ │ │ │ │ + this.features[feature.fid || feature.id] = feature; │ │ │ │ │ + selectedFeatures.push(feature); │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("featureselected", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("featuresselected", { │ │ │ │ │ + features: selectedFeatures │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: enableZoomBox │ │ │ │ │ + * Method: hoverSelect │ │ │ │ │ + * Sets/unsets the │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} the feature to hover-select. │ │ │ │ │ + * If none is provided, the current will be nulled and │ │ │ │ │ + * the outfeature event will be triggered. │ │ │ │ │ */ │ │ │ │ │ - enableZoomBox: function() { │ │ │ │ │ - this.zoomBoxEnabled = true; │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.zoomBox.activate(); │ │ │ │ │ + hoverSelect: function(feature) { │ │ │ │ │ + var fid = feature ? feature.fid || feature.id : null; │ │ │ │ │ + var hfid = this.hoverFeature ? │ │ │ │ │ + this.hoverFeature.fid || this.hoverFeature.id : null; │ │ │ │ │ + │ │ │ │ │ + if (hfid && hfid != fid) { │ │ │ │ │ + this.events.triggerEvent("outfeature", { │ │ │ │ │ + feature: this.hoverFeature │ │ │ │ │ + }); │ │ │ │ │ + this.hoverFeature = null; │ │ │ │ │ + } │ │ │ │ │ + if (fid && fid != hfid) { │ │ │ │ │ + this.events.triggerEvent("hoverfeature", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + this.hoverFeature = feature; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: disableZoomWheel │ │ │ │ │ + * Method: unselect │ │ │ │ │ + * Remove feature from the hash of selected features and trigger the │ │ │ │ │ + * featureunselected event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ */ │ │ │ │ │ - │ │ │ │ │ - disableZoomWheel: function() { │ │ │ │ │ - this.zoomWheelEnabled = false; │ │ │ │ │ - this.handlers.wheel.deactivate(); │ │ │ │ │ + unselect: function(feature) { │ │ │ │ │ + delete this.features[feature.fid || feature.id]; │ │ │ │ │ + this.events.triggerEvent("featureunselected", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: enableZoomWheel │ │ │ │ │ + * Method: unselectAll │ │ │ │ │ + * Unselect all selected features. │ │ │ │ │ */ │ │ │ │ │ + unselectAll: function() { │ │ │ │ │ + // we'll want an option to supress notification here │ │ │ │ │ + for (var fid in this.features) { │ │ │ │ │ + this.unselect(this.features[fid]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - enableZoomWheel: function() { │ │ │ │ │ - this.zoomWheelEnabled = true; │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.handlers.wheel.activate(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + for (var i in this.handlers) { │ │ │ │ │ + this.handlers[i].setMap(map); │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Navigation" │ │ │ │ │ + /** │ │ │ │ │ + * Method: pixelToBounds │ │ │ │ │ + * Takes a pixel as argument and creates bounds after adding the │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} │ │ │ │ │ + */ │ │ │ │ │ + pixelToBounds: function(pixel) { │ │ │ │ │ + var llPx = pixel.add(-this.clickTolerance / 2, this.clickTolerance / 2); │ │ │ │ │ + var urPx = pixel.add(this.clickTolerance / 2, -this.clickTolerance / 2); │ │ │ │ │ + var ll = this.map.getLonLatFromPixel(llPx); │ │ │ │ │ + var ur = this.map.getLonLatFromPixel(urPx); │ │ │ │ │ + return new OpenLayers.Bounds(ll.lon, ll.lat, ur.lon, ur.lat); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.GetFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Polygon.js │ │ │ │ │ + OpenLayers/Layer/WMS.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/Grid.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.WMS │ │ │ │ │ + * Instances of OpenLayers.Layer.WMS are used to display data from OGC Web │ │ │ │ │ + * Mapping Services. Create a new WMS layer with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - holeModifier: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: drawingHole │ │ │ │ │ - * {Boolean} Currently drawing an interior ring. │ │ │ │ │ - */ │ │ │ │ │ - drawingHole: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: polygon │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - polygon: 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The initial pixel location for the new │ │ │ │ │ - * feature. │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addPoint │ │ │ │ │ - * Add point to geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The pixel location for the new point. │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getCurrentPointIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The index of the most recently drawn point. │ │ │ │ │ - */ │ │ │ │ │ - getCurrentPointIndex: function() { │ │ │ │ │ - return this.line.geometry.components.length - 2; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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). │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: finishGeometry │ │ │ │ │ - * Finish the geometry and send it back to the control. │ │ │ │ │ - */ │ │ │ │ │ - finishGeometry: function() { │ │ │ │ │ - var index = this.line.geometry.components.length - 2; │ │ │ │ │ - this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: finalizeInteriorRing │ │ │ │ │ - * Enforces that new ring has some area and doesn't contain vertices of any │ │ │ │ │ - * other rings. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ - */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - if (this.drawingHole) { │ │ │ │ │ - this.polygon.geometry.removeComponent(this.line.geometry); │ │ │ │ │ - this.restoreFeature(true); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ - */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - OpenLayers.Handler.Path.prototype.destroyFeature.call( │ │ │ │ │ - this, force); │ │ │ │ │ - this.polygon = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render geometries on the temporary layer. │ │ │ │ │ - */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.polygon, this.style); │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSketch │ │ │ │ │ - * Return the sketch feature. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getSketch: function() { │ │ │ │ │ - return this.polygon; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - 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/Control/EditingToolbar.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/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ - * @requires OpenLayers/Control/DrawFeature.js │ │ │ │ │ - * @requires OpenLayers/Handler/Point.js │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.EditingToolbar │ │ │ │ │ - * The EditingToolbar is a panel of 4 controls to draw polygons, lines, │ │ │ │ │ - * points, or to navigate the map by panning. By default it appears in the │ │ │ │ │ - * upper right corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.EditingToolbar = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Control.Panel, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.EditingToolbar │ │ │ │ │ - * Create an editing toolbar for a given layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - this.addControls( │ │ │ │ │ - [new OpenLayers.Control.Navigation()] │ │ │ │ │ - ); │ │ │ │ │ - var controls = [ │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePoint', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }), │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePath', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }), │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePolygon', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }) │ │ │ │ │ - ]; │ │ │ │ │ - this.addControls(controls); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * calls the default draw, and then activates mouse defaults. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.defaultControl === null) { │ │ │ │ │ - this.defaultControl = this.controls[0]; │ │ │ │ │ - } │ │ │ │ │ - return div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.EditingToolbar" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/OverviewMap.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/Control.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ - * @requires OpenLayers/Map.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.OverviewMap │ │ │ │ │ - * The OverMap control creates a small overview map, useful to display the │ │ │ │ │ - * extent of a zoomed map and your main map and provide additional │ │ │ │ │ - * navigation options to the User. By default the overview map is drawn in │ │ │ │ │ - * the lower right corner of the main map. Create a new overview map with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} The DOM element that contains the overview map │ │ │ │ │ - */ │ │ │ │ │ - element: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: ovmap │ │ │ │ │ - * {} A reference to the overview map itself. │ │ │ │ │ - */ │ │ │ │ │ - ovmap: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: size │ │ │ │ │ - * {} The overvew map size in pixels. Note that this is │ │ │ │ │ - * the size of the map itself - the element that contains the map (default │ │ │ │ │ - * class name olControlOverviewMapElement) may have padding or other style │ │ │ │ │ - * attributes added via CSS. │ │ │ │ │ - */ │ │ │ │ │ - size: { │ │ │ │ │ - w: 180, │ │ │ │ │ - h: 90 │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} Ordered list of layers in the overview map. │ │ │ │ │ - * If none are sent at construction, the base layer for the main map is used. │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minRectSize │ │ │ │ │ - * {Integer} The minimum width or height (in pixels) of the extent │ │ │ │ │ - * rectangle on the overview map. When the extent rectangle reaches │ │ │ │ │ - * this size, it will be replaced depending on the value of the │ │ │ │ │ - * property. Default is 15 pixels. │ │ │ │ │ - */ │ │ │ │ │ - minRectSize: 15, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minRectDisplayClass │ │ │ │ │ - * {String} Replacement style class name for the extent rectangle when │ │ │ │ │ - * is reached. This string will be suffixed on to the │ │ │ │ │ - * displayClass. Default is "RectReplacement". │ │ │ │ │ - * │ │ │ │ │ - * Example CSS declaration: │ │ │ │ │ - * (code) │ │ │ │ │ - * .olControlOverviewMapRectReplacement { │ │ │ │ │ - * overflow: hidden; │ │ │ │ │ - * cursor: move; │ │ │ │ │ - * background-image: url("img/overview_replacement.gif"); │ │ │ │ │ - * background-repeat: no-repeat; │ │ │ │ │ - * background-position: center; │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ - minRectDisplayClass: "RectReplacement", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minRatio │ │ │ │ │ - * {Float} The ratio of the overview map resolution to the main map │ │ │ │ │ - * resolution at which to zoom farther out on the overview map. │ │ │ │ │ - */ │ │ │ │ │ - minRatio: 8, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxRatio │ │ │ │ │ - * {Float} The ratio of the overview map resolution to the main map │ │ │ │ │ - * resolution at which to zoom farther in on the overview map. │ │ │ │ │ - */ │ │ │ │ │ - maxRatio: 32, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: mapOptions │ │ │ │ │ - * {Object} An object containing any non-default properties to be sent to │ │ │ │ │ - * the overview map's map constructor. These should include any │ │ │ │ │ - * non-default options that the main map was constructed with. │ │ │ │ │ - */ │ │ │ │ │ - mapOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoPan │ │ │ │ │ - * {Boolean} Always pan the overview map, so the extent marker remains in │ │ │ │ │ - * the center. Default is false. If true, when you drag the extent │ │ │ │ │ - * marker, the overview map will update itself so the marker returns │ │ │ │ │ - * to the center. │ │ │ │ │ - */ │ │ │ │ │ - autoPan: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - handlers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: resolutionFactor │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - resolutionFactor: 1, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maximized │ │ │ │ │ - * {Boolean} Start as maximized (visible). Defaults to false. │ │ │ │ │ - */ │ │ │ │ │ - maximized: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maximizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * maximize div. Defaults to "" (no title). │ │ │ │ │ - */ │ │ │ │ │ - maximizeTitle: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minimizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * minimize div. Defaults to "" (no title). │ │ │ │ │ - */ │ │ │ │ │ - minimizeTitle: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.OverviewMap │ │ │ │ │ - * Create a new overview map │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Properties of this object will be set on the overview │ │ │ │ │ - * map object. Note, to set options on the map object contained in this │ │ │ │ │ - * control, set as one of the options properties. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.layers = []; │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct the control │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (!this.mapDiv) { // we've already been destroyed │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers.click) { │ │ │ │ │ - this.handlers.click.destroy(); │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers.drag) { │ │ │ │ │ - this.handlers.drag.destroy(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.ovmap && this.ovmap.viewPortDiv.removeChild(this.extentRectangle); │ │ │ │ │ - this.extentRectangle = null; │ │ │ │ │ - │ │ │ │ │ - if (this.rectEvents) { │ │ │ │ │ - this.rectEvents.destroy(); │ │ │ │ │ - this.rectEvents = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.ovmap) { │ │ │ │ │ - this.ovmap.destroy(); │ │ │ │ │ - this.ovmap = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.element.removeChild(this.mapDiv); │ │ │ │ │ - this.mapDiv = null; │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.element); │ │ │ │ │ - this.element = null; │ │ │ │ │ - │ │ │ │ │ - if (this.maximizeDiv) { │ │ │ │ │ - this.div.removeChild(this.maximizeDiv); │ │ │ │ │ - this.maximizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.div.removeChild(this.minimizeDiv); │ │ │ │ │ - this.minimizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - changebaselayer: this.baseLayerDraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Render the control in the browser. │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.layers.length === 0) { │ │ │ │ │ - if (this.map.baseLayer) { │ │ │ │ │ - var layer = this.map.baseLayer.clone(); │ │ │ │ │ - this.layers = [layer]; │ │ │ │ │ - } else { │ │ │ │ │ - this.map.events.register("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ - return this.div; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // create overview map DOM elements │ │ │ │ │ - this.element = document.createElement('div'); │ │ │ │ │ - this.element.className = this.displayClass + 'Element'; │ │ │ │ │ - this.element.style.display = 'none'; │ │ │ │ │ - │ │ │ │ │ - this.mapDiv = document.createElement('div'); │ │ │ │ │ - this.mapDiv.style.width = this.size.w + 'px'; │ │ │ │ │ - this.mapDiv.style.height = this.size.h + 'px'; │ │ │ │ │ - this.mapDiv.style.position = 'relative'; │ │ │ │ │ - this.mapDiv.style.overflow = 'hidden'; │ │ │ │ │ - this.mapDiv.id = OpenLayers.Util.createUniqueID('overviewMap'); │ │ │ │ │ - │ │ │ │ │ - this.extentRectangle = document.createElement('div'); │ │ │ │ │ - this.extentRectangle.style.position = 'absolute'; │ │ │ │ │ - this.extentRectangle.style.zIndex = 1000; //HACK │ │ │ │ │ - this.extentRectangle.className = this.displayClass + 'ExtentRectangle'; │ │ │ │ │ - │ │ │ │ │ - this.element.appendChild(this.mapDiv); │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ - │ │ │ │ │ - // Optionally add min/max buttons if the control will go in the │ │ │ │ │ - // map viewport. │ │ │ │ │ - if (!this.outsideViewport) { │ │ │ │ │ - this.div.className += " " + this.displayClass + 'Container'; │ │ │ │ │ - // maximize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ - this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - this.displayClass + 'MaximizeButton', │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - 'absolute'); │ │ │ │ │ - this.maximizeDiv.style.display = 'none'; │ │ │ │ │ - this.maximizeDiv.className = this.displayClass + 'MaximizeButton olButton'; │ │ │ │ │ - if (this.maximizeTitle) { │ │ │ │ │ - this.maximizeDiv.title = this.maximizeTitle; │ │ │ │ │ - } │ │ │ │ │ - this.div.appendChild(this.maximizeDiv); │ │ │ │ │ - │ │ │ │ │ - // minimize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ - this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - 'OpenLayers_Control_minimizeDiv', │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - 'absolute'); │ │ │ │ │ - this.minimizeDiv.style.display = 'none'; │ │ │ │ │ - this.minimizeDiv.className = this.displayClass + 'MinimizeButton olButton'; │ │ │ │ │ - if (this.minimizeTitle) { │ │ │ │ │ - this.minimizeDiv.title = this.minimizeTitle; │ │ │ │ │ - } │ │ │ │ │ - this.div.appendChild(this.minimizeDiv); │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else { │ │ │ │ │ - // show the overview map │ │ │ │ │ - this.element.style.display = ''; │ │ │ │ │ - } │ │ │ │ │ - if (this.map.getExtent()) { │ │ │ │ │ - this.update(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (this.maximized) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: baseLayerDraw │ │ │ │ │ - * Draw the base layer - called if unable to complete in the initial draw │ │ │ │ │ - */ │ │ │ │ │ - baseLayerDraw: function() { │ │ │ │ │ - this.draw(); │ │ │ │ │ - this.map.events.unregister("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: rectDrag │ │ │ │ │ - * Handle extent rectangle drag │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} The pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - rectDrag: function(px) { │ │ │ │ │ - var deltaX = this.handlers.drag.last.x - px.x; │ │ │ │ │ - var deltaY = this.handlers.drag.last.y - px.y; │ │ │ │ │ - if (deltaX != 0 || deltaY != 0) { │ │ │ │ │ - var rectTop = this.rectPxBounds.top; │ │ │ │ │ - var rectLeft = this.rectPxBounds.left; │ │ │ │ │ - var rectHeight = Math.abs(this.rectPxBounds.getHeight()); │ │ │ │ │ - var rectWidth = this.rectPxBounds.getWidth(); │ │ │ │ │ - // don't allow dragging off of parent element │ │ │ │ │ - var newTop = Math.max(0, (rectTop - deltaY)); │ │ │ │ │ - newTop = Math.min(newTop, │ │ │ │ │ - this.ovmap.size.h - this.hComp - rectHeight); │ │ │ │ │ - var newLeft = Math.max(0, (rectLeft - deltaX)); │ │ │ │ │ - newLeft = Math.min(newLeft, │ │ │ │ │ - this.ovmap.size.w - this.wComp - rectWidth); │ │ │ │ │ - this.setRectPxBounds(new OpenLayers.Bounds(newLeft, │ │ │ │ │ - newTop + rectHeight, │ │ │ │ │ - newLeft + rectWidth, │ │ │ │ │ - newTop)); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mapDivClick │ │ │ │ │ - * Handle browser events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} evt │ │ │ │ │ - */ │ │ │ │ │ - mapDivClick: function(evt) { │ │ │ │ │ - var pxCenter = this.rectPxBounds.getCenterPixel(); │ │ │ │ │ - var deltaX = evt.xy.x - pxCenter.x; │ │ │ │ │ - var deltaY = evt.xy.y - pxCenter.y; │ │ │ │ │ - var top = this.rectPxBounds.top; │ │ │ │ │ - var left = this.rectPxBounds.left; │ │ │ │ │ - var height = Math.abs(this.rectPxBounds.getHeight()); │ │ │ │ │ - var width = this.rectPxBounds.getWidth(); │ │ │ │ │ - var newTop = Math.max(0, (top + deltaY)); │ │ │ │ │ - newTop = Math.min(newTop, this.ovmap.size.h - height); │ │ │ │ │ - var newLeft = Math.max(0, (left + deltaX)); │ │ │ │ │ - newLeft = Math.min(newLeft, this.ovmap.size.w - width); │ │ │ │ │ - this.setRectPxBounds(new OpenLayers.Bounds(newLeft, │ │ │ │ │ - newTop + height, │ │ │ │ │ - newLeft + width, │ │ │ │ │ - newTop)); │ │ │ │ │ - this.updateMapToRect(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - if (evt.buttonElement === this.minimizeDiv) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else if (evt.buttonElement === this.maximizeDiv) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: maximizeControl │ │ │ │ │ - * Unhide the control. Called when the control is in the map viewport. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ - */ │ │ │ │ │ - maximizeControl: function(e) { │ │ │ │ │ - this.element.style.display = ''; │ │ │ │ │ - this.showToggle(false); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: minimizeControl │ │ │ │ │ - * Hide all the contents of the control, shrink the size, │ │ │ │ │ - * add the maximize icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ - */ │ │ │ │ │ - minimizeControl: function(e) { │ │ │ │ │ - this.element.style.display = 'none'; │ │ │ │ │ - this.showToggle(true); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: showToggle │ │ │ │ │ - * Hide/Show the toggle depending on whether the control is minimized │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * minimize - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - showToggle: function(minimize) { │ │ │ │ │ - if (this.maximizeDiv) { │ │ │ │ │ - this.maximizeDiv.style.display = minimize ? '' : 'none'; │ │ │ │ │ - } │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.minimizeDiv.style.display = minimize ? 'none' : ''; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Update the overview map after layers move. │ │ │ │ │ - */ │ │ │ │ │ - update: function() { │ │ │ │ │ - if (this.ovmap == null) { │ │ │ │ │ - this.createMap(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.autoPan || !this.isSuitableOverview()) { │ │ │ │ │ - this.updateOverview(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // update extent rectangle │ │ │ │ │ - this.updateRectToMap(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: isSuitableOverview │ │ │ │ │ - * Determines if the overview map is suitable given the extent and │ │ │ │ │ - * resolution of the main map. │ │ │ │ │ - */ │ │ │ │ │ - isSuitableOverview: function() { │ │ │ │ │ - var mapExtent = this.map.getExtent(); │ │ │ │ │ - var maxExtent = this.map.getMaxExtent(); │ │ │ │ │ - var testExtent = new OpenLayers.Bounds( │ │ │ │ │ - Math.max(mapExtent.left, maxExtent.left), │ │ │ │ │ - Math.max(mapExtent.bottom, maxExtent.bottom), │ │ │ │ │ - Math.min(mapExtent.right, maxExtent.right), │ │ │ │ │ - Math.min(mapExtent.top, maxExtent.top)); │ │ │ │ │ - │ │ │ │ │ - if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ - testExtent = testExtent.transform( │ │ │ │ │ - this.map.getProjectionObject(), │ │ │ │ │ - this.ovmap.getProjectionObject()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var resRatio = this.ovmap.getResolution() / this.map.getResolution(); │ │ │ │ │ - return ((resRatio > this.minRatio) && │ │ │ │ │ - (resRatio <= this.maxRatio) && │ │ │ │ │ - (this.ovmap.getExtent().containsBounds(testExtent))); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method updateOverview │ │ │ │ │ - * Called by if returns true │ │ │ │ │ - */ │ │ │ │ │ - updateOverview: function() { │ │ │ │ │ - var mapRes = this.map.getResolution(); │ │ │ │ │ - var targetRes = this.ovmap.getResolution(); │ │ │ │ │ - var resRatio = targetRes / mapRes; │ │ │ │ │ - if (resRatio > this.maxRatio) { │ │ │ │ │ - // zoom in overview map │ │ │ │ │ - targetRes = this.minRatio * mapRes; │ │ │ │ │ - } else if (resRatio <= this.minRatio) { │ │ │ │ │ - // zoom out overview map │ │ │ │ │ - targetRes = this.maxRatio * mapRes; │ │ │ │ │ - } │ │ │ │ │ - var center; │ │ │ │ │ - if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ - center = this.map.center.clone(); │ │ │ │ │ - center.transform(this.map.getProjectionObject(), │ │ │ │ │ - this.ovmap.getProjectionObject()); │ │ │ │ │ - } else { │ │ │ │ │ - center = this.map.center; │ │ │ │ │ - } │ │ │ │ │ - this.ovmap.setCenter(center, this.ovmap.getZoomForResolution( │ │ │ │ │ - targetRes * this.resolutionFactor)); │ │ │ │ │ - this.updateRectToMap(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createMap │ │ │ │ │ - * Construct the map that this control contains │ │ │ │ │ - */ │ │ │ │ │ - createMap: function() { │ │ │ │ │ - // create the overview map │ │ │ │ │ - var options = OpenLayers.Util.extend({ │ │ │ │ │ - controls: [], │ │ │ │ │ - maxResolution: 'auto', │ │ │ │ │ - fallThrough: false │ │ │ │ │ - }, this.mapOptions); │ │ │ │ │ - this.ovmap = new OpenLayers.Map(this.mapDiv, options); │ │ │ │ │ - this.ovmap.viewPortDiv.appendChild(this.extentRectangle); │ │ │ │ │ - │ │ │ │ │ - // prevent ovmap from being destroyed when the page unloads, because │ │ │ │ │ - // the OverviewMap control has to do this (and does it). │ │ │ │ │ - OpenLayers.Event.stopObserving(window, 'unload', this.ovmap.unloadDestroy); │ │ │ │ │ - │ │ │ │ │ - this.ovmap.addLayers(this.layers); │ │ │ │ │ - this.ovmap.zoomToMaxExtent(); │ │ │ │ │ - // check extent rectangle border width │ │ │ │ │ - this.wComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ - 'border-left-width')) + │ │ │ │ │ - parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ - 'border-right-width')); │ │ │ │ │ - this.wComp = (this.wComp) ? this.wComp : 2; │ │ │ │ │ - this.hComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ - 'border-top-width')) + │ │ │ │ │ - parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ - 'border-bottom-width')); │ │ │ │ │ - this.hComp = (this.hComp) ? this.hComp : 2; │ │ │ │ │ - │ │ │ │ │ - this.handlers.drag = new OpenLayers.Handler.Drag( │ │ │ │ │ - this, { │ │ │ │ │ - move: this.rectDrag, │ │ │ │ │ - done: this.updateMapToRect │ │ │ │ │ - }, { │ │ │ │ │ - map: this.ovmap │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ - this, { │ │ │ │ │ - "click": this.mapDivClick │ │ │ │ │ - }, { │ │ │ │ │ - "single": true, │ │ │ │ │ - "double": false, │ │ │ │ │ - "stopSingle": true, │ │ │ │ │ - "stopDouble": true, │ │ │ │ │ - "pixelTolerance": 1, │ │ │ │ │ - map: this.ovmap │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - this.handlers.click.activate(); │ │ │ │ │ - │ │ │ │ │ - this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, │ │ │ │ │ - null, true); │ │ │ │ │ - this.rectEvents.register("mouseover", this, function(e) { │ │ │ │ │ - if (!this.handlers.drag.active && !this.map.dragging) { │ │ │ │ │ - this.handlers.drag.activate(); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.rectEvents.register("mouseout", this, function(e) { │ │ │ │ │ - if (!this.handlers.drag.dragging) { │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ - var sourceUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ - this.map.units || this.map.baseLayer.units; │ │ │ │ │ - var targetUnits = this.ovmap.getProjectionObject().getUnits() || │ │ │ │ │ - this.ovmap.units || this.ovmap.baseLayer.units; │ │ │ │ │ - this.resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ - OpenLayers.INCHES_PER_UNIT[sourceUnits] / │ │ │ │ │ - OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateRectToMap │ │ │ │ │ - * Updates the extent rectangle position and size to match the map extent │ │ │ │ │ - */ │ │ │ │ │ - updateRectToMap: function() { │ │ │ │ │ - // If the projections differ we need to reproject │ │ │ │ │ - var bounds; │ │ │ │ │ - if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ - bounds = this.map.getExtent().transform( │ │ │ │ │ - this.map.getProjectionObject(), │ │ │ │ │ - this.ovmap.getProjectionObject()); │ │ │ │ │ - } else { │ │ │ │ │ - bounds = this.map.getExtent(); │ │ │ │ │ - } │ │ │ │ │ - var pxBounds = this.getRectBoundsFromMapBounds(bounds); │ │ │ │ │ - if (pxBounds) { │ │ │ │ │ - this.setRectPxBounds(pxBounds); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateMapToRect │ │ │ │ │ - * Updates the map extent to match the extent rectangle position and size │ │ │ │ │ - */ │ │ │ │ │ - updateMapToRect: function() { │ │ │ │ │ - var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); │ │ │ │ │ - if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ - lonLatBounds = lonLatBounds.transform( │ │ │ │ │ - this.ovmap.getProjectionObject(), │ │ │ │ │ - this.map.getProjectionObject()); │ │ │ │ │ - } │ │ │ │ │ - this.map.panTo(lonLatBounds.getCenterLonLat()); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setRectPxBounds │ │ │ │ │ - * Set extent rectangle pixel bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pxBounds - {} │ │ │ │ │ - */ │ │ │ │ │ - setRectPxBounds: function(pxBounds) { │ │ │ │ │ - var top = Math.max(pxBounds.top, 0); │ │ │ │ │ - var left = Math.max(pxBounds.left, 0); │ │ │ │ │ - var bottom = Math.min(pxBounds.top + Math.abs(pxBounds.getHeight()), │ │ │ │ │ - this.ovmap.size.h - this.hComp); │ │ │ │ │ - var right = Math.min(pxBounds.left + pxBounds.getWidth(), │ │ │ │ │ - this.ovmap.size.w - this.wComp); │ │ │ │ │ - var width = Math.max(right - left, 0); │ │ │ │ │ - var height = Math.max(bottom - top, 0); │ │ │ │ │ - if (width < this.minRectSize || height < this.minRectSize) { │ │ │ │ │ - this.extentRectangle.className = this.displayClass + │ │ │ │ │ - this.minRectDisplayClass; │ │ │ │ │ - var rLeft = left + (width / 2) - (this.minRectSize / 2); │ │ │ │ │ - var rTop = top + (height / 2) - (this.minRectSize / 2); │ │ │ │ │ - this.extentRectangle.style.top = Math.round(rTop) + 'px'; │ │ │ │ │ - this.extentRectangle.style.left = Math.round(rLeft) + 'px'; │ │ │ │ │ - this.extentRectangle.style.height = this.minRectSize + 'px'; │ │ │ │ │ - this.extentRectangle.style.width = this.minRectSize + 'px'; │ │ │ │ │ - } else { │ │ │ │ │ - this.extentRectangle.className = this.displayClass + │ │ │ │ │ - 'ExtentRectangle'; │ │ │ │ │ - this.extentRectangle.style.top = Math.round(top) + 'px'; │ │ │ │ │ - this.extentRectangle.style.left = Math.round(left) + 'px'; │ │ │ │ │ - this.extentRectangle.style.height = Math.round(height) + 'px'; │ │ │ │ │ - this.extentRectangle.style.width = Math.round(width) + 'px'; │ │ │ │ │ - } │ │ │ │ │ - this.rectPxBounds = new OpenLayers.Bounds( │ │ │ │ │ - Math.round(left), Math.round(bottom), │ │ │ │ │ - Math.round(right), Math.round(top) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getRectBoundsFromMapBounds │ │ │ │ │ - * Get the rect bounds from the map bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonLatBounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {}A bounds which is the passed-in map lon/lat extent │ │ │ │ │ - * translated into pixel bounds for the overview map │ │ │ │ │ - */ │ │ │ │ │ - getRectBoundsFromMapBounds: function(lonLatBounds) { │ │ │ │ │ - var leftBottomPx = this.getOverviewPxFromLonLat({ │ │ │ │ │ - lon: lonLatBounds.left, │ │ │ │ │ - lat: lonLatBounds.bottom │ │ │ │ │ - }); │ │ │ │ │ - var rightTopPx = this.getOverviewPxFromLonLat({ │ │ │ │ │ - lon: lonLatBounds.right, │ │ │ │ │ - lat: lonLatBounds.top │ │ │ │ │ - }); │ │ │ │ │ - var bounds = null; │ │ │ │ │ - if (leftBottomPx && rightTopPx) { │ │ │ │ │ - bounds = new OpenLayers.Bounds(leftBottomPx.x, leftBottomPx.y, │ │ │ │ │ - rightTopPx.x, rightTopPx.y); │ │ │ │ │ - } │ │ │ │ │ - return bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getMapBoundsFromRectBounds │ │ │ │ │ - * Get the map bounds from the rect bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pxBounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Bounds which is the passed-in overview rect bounds │ │ │ │ │ - * translated into lon/lat bounds for the overview map │ │ │ │ │ - */ │ │ │ │ │ - getMapBoundsFromRectBounds: function(pxBounds) { │ │ │ │ │ - var leftBottomLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ - x: pxBounds.left, │ │ │ │ │ - y: pxBounds.bottom │ │ │ │ │ - }); │ │ │ │ │ - var rightTopLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ - x: pxBounds.right, │ │ │ │ │ - y: pxBounds.top │ │ │ │ │ - }); │ │ │ │ │ - return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat, │ │ │ │ │ - rightTopLonLat.lon, rightTopLonLat.lat); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getLonLatFromOverviewPx │ │ │ │ │ - * Get a map location from a pixel location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * overviewMapPx - {|Object} OpenLayers.Pixel or │ │ │ │ │ - * an object with a │ │ │ │ │ - * 'x' and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Location which is the passed-in overview map │ │ │ │ │ - * OpenLayers.Pixel, translated into lon/lat by the overview │ │ │ │ │ - * map. An object with a 'lon' and 'lat' properties. │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromOverviewPx: function(overviewMapPx) { │ │ │ │ │ - var size = this.ovmap.size; │ │ │ │ │ - var res = this.ovmap.getResolution(); │ │ │ │ │ - var center = this.ovmap.getExtent().getCenterLonLat(); │ │ │ │ │ - │ │ │ │ │ - var deltaX = overviewMapPx.x - (size.w / 2); │ │ │ │ │ - var deltaY = overviewMapPx.y - (size.h / 2); │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - lon: center.lon + deltaX * res, │ │ │ │ │ - lat: center.lat - deltaY * res │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getOverviewPxFromLonLat │ │ │ │ │ - * Get a pixel location from a map location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Location which is the passed-in OpenLayers.LonLat, │ │ │ │ │ - * translated into overview map pixels │ │ │ │ │ - */ │ │ │ │ │ - getOverviewPxFromLonLat: function(lonlat) { │ │ │ │ │ - var res = this.ovmap.getResolution(); │ │ │ │ │ - var extent = this.ovmap.getExtent(); │ │ │ │ │ - if (extent) { │ │ │ │ │ - return { │ │ │ │ │ - x: Math.round(1 / res * (lonlat.lon - extent.left)), │ │ │ │ │ - y: Math.round(1 / res * (extent.top - lonlat.lat)) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: 'OpenLayers.Control.OverviewMap' │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/CacheWrite.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.CacheWrite │ │ │ │ │ - * A control for caching image tiles in the browser's local storage. The │ │ │ │ │ - * control is used to fetch and use the cached │ │ │ │ │ - * tile images. │ │ │ │ │ - * │ │ │ │ │ - * Note: Before using this control on any layer that is not your own, make sure │ │ │ │ │ - * that the terms of service of the tile provider allow local storage of tiles. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * To register events in the constructor, configure . │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * cachefull - Triggered when the cache is full. Listeners receive an │ │ │ │ │ - * object with a tile property as first argument. The tile references │ │ │ │ │ - * the tile that couldn't be cached. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} Object with event listeners, keyed by event name. An optional │ │ │ │ │ - * scope property defines the scope that listeners will be executed in. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()}. Optional. If provided, caching │ │ │ │ │ - * will be enabled for these layers only, otherwise for all cacheable │ │ │ │ │ - * layers. │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: imageFormat │ │ │ │ │ - * {String} The image format used for caching. The default is "image/png". │ │ │ │ │ - * Supported formats depend on the user agent. If an unsupported │ │ │ │ │ - * is provided, "image/png" will be used. For aerial │ │ │ │ │ - * imagery, "image/jpeg" is recommended. │ │ │ │ │ - */ │ │ │ │ │ - imageFormat: "image/png", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: quotaRegEx │ │ │ │ │ - * {RegExp} │ │ │ │ │ - */ │ │ │ │ │ - quotaRegEx: (/quota/i), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.CacheWrite │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Object with API properties for this control. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - var i, layers = this.layers || map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!this.layers) { │ │ │ │ │ - map.events.on({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ - * will be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - evt.layer.events.on({ │ │ │ │ │ - tileloadstart: this.makeSameOrigin, │ │ │ │ │ - tileloaded: this.onTileLoaded, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ - * layer will no longer be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - evt.layer.events.un({ │ │ │ │ │ - tileloadstart: this.makeSameOrigin, │ │ │ │ │ - tileloaded: this.onTileLoaded, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: makeSameOrigin │ │ │ │ │ - * If the tile does not have CORS image loading enabled and is from a │ │ │ │ │ - * different origin, use OpenLayers.ProxyHost to make it a same origin url. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - makeSameOrigin: function(evt) { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - var tile = evt.tile; │ │ │ │ │ - if (tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ - !tile.crossOriginKeyword && │ │ │ │ │ - tile.url.substr(0, 5) !== "data:") { │ │ │ │ │ - var sameOriginUrl = OpenLayers.Request.makeSameOrigin( │ │ │ │ │ - tile.url, OpenLayers.ProxyHost │ │ │ │ │ - ); │ │ │ │ │ - OpenLayers.Control.CacheWrite.urlMap[sameOriginUrl] = tile.url; │ │ │ │ │ - tile.url = sameOriginUrl; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onTileLoaded │ │ │ │ │ - * Decides whether a tile can be cached and calls the cache method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onTileLoaded: function(evt) { │ │ │ │ │ - if (this.active && !evt.aborted && │ │ │ │ │ - evt.tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ - evt.tile.url.substr(0, 5) !== 'data:') { │ │ │ │ │ - this.cache({ │ │ │ │ │ - tile: evt.tile │ │ │ │ │ - }); │ │ │ │ │ - delete OpenLayers.Control.CacheWrite.urlMap[evt.tile.url]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: cache │ │ │ │ │ - * Adds a tile to the cache. When the cache is full, the "cachefull" event │ │ │ │ │ - * is triggered. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Object with a tile property, tile being the │ │ │ │ │ - * with the data to add to the cache │ │ │ │ │ - */ │ │ │ │ │ - cache: function(obj) { │ │ │ │ │ - if (window.localStorage) { │ │ │ │ │ - var tile = obj.tile; │ │ │ │ │ - try { │ │ │ │ │ - var canvasContext = tile.getCanvasContext(); │ │ │ │ │ - if (canvasContext) { │ │ │ │ │ - var urlMap = OpenLayers.Control.CacheWrite.urlMap; │ │ │ │ │ - var url = urlMap[tile.url] || tile.url; │ │ │ │ │ - window.localStorage.setItem( │ │ │ │ │ - "olCache_" + url, │ │ │ │ │ - canvasContext.canvas.toDataURL(this.imageFormat) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } catch (e) { │ │ │ │ │ - // local storage full or CORS violation │ │ │ │ │ - var reason = e.name || e.message; │ │ │ │ │ - if (reason && this.quotaRegEx.test(reason)) { │ │ │ │ │ - this.events.triggerEvent("cachefull", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Console.error(e.toString()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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.layers || this.map) { │ │ │ │ │ - var i, layers = this.layers || this.map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.CacheWrite" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: OpenLayers.Control.CacheWrite.clearCache │ │ │ │ │ - * Clears all tiles cached with from the cache. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheWrite.clearCache = function() { │ │ │ │ │ - if (!window.localStorage) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var i, key; │ │ │ │ │ - for (i = window.localStorage.length - 1; i >= 0; --i) { │ │ │ │ │ - key = window.localStorage.key(i); │ │ │ │ │ - if (key.substr(0, 8) === "olCache_") { │ │ │ │ │ - window.localStorage.removeItem(key); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Property: OpenLayers.Control.CacheWrite.urlMap │ │ │ │ │ - * {Object} Mapping of same origin urls to cache url keys. Entries will be │ │ │ │ │ - * deleted as soon as a tile was cached. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheWrite.urlMap = {}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/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/Handler.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. │ │ │ │ │ - * │ │ │ │ │ - * This handler stops event propagation for mousedown and mouseup if those │ │ │ │ │ - * browser events target features that can be selected. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: EVENTMAP │ │ │ │ │ - * {Object} A object mapping the browser events to objects with callback │ │ │ │ │ - * keys for in and out. │ │ │ │ │ - */ │ │ │ │ │ - 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' │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The last feature that was hovered. │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastFeature │ │ │ │ │ - * {} The last feature that was handled. │ │ │ │ │ - */ │ │ │ │ │ - lastFeature: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: down │ │ │ │ │ - * {} The location of the last mousedown. │ │ │ │ │ - */ │ │ │ │ │ - down: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: up │ │ │ │ │ - * {} The location of the last mouseup. │ │ │ │ │ - */ │ │ │ │ │ - up: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - clickTolerance: 4, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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) │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: 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. │ │ │ │ │ - */ │ │ │ │ │ - stopClick: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - stopUp: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Feature │ │ │ │ │ - * │ │ │ │ │ - * 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} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, layer, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, [control, callbacks, options]); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return OpenLayers.Event.isMultiTouch(evt) ? │ │ │ │ │ - true : this.mousedown(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mouse down. Stop propagation if a feature is targeted by this │ │ │ │ │ - * event (stops map dragging during feature selection). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouse up. Stop propagation if a feature is targeted by this │ │ │ │ │ - * event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - this.up = evt.xy; │ │ │ │ │ - return this.handle(evt) ? !this.stopUp : true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - return this.handle(evt) ? !this.stopClick : true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - if (!this.callbacks['over'] && !this.callbacks['out']) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - this.handle(evt); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle dblclick. Call the "dblclick" callback if dblclick on a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - return !this.handle(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: geometryTypeMatches │ │ │ │ │ - * Return true if the geometry type of the passed feature matches │ │ │ │ │ - * one of the geometry types in the geometryTypes array. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - geometryTypeMatches: function(feature) { │ │ │ │ │ - return this.geometryTypes == null || │ │ │ │ │ - OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ - feature.geometry.CLASS_NAME) > -1; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handle │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The event occurred over a relevant feature. │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: triggerCallback │ │ │ │ │ - * Call the callback keyed in the event map with the supplied arguments. │ │ │ │ │ - * For click and clickout, the is checked first. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * type - {String} │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Turn off the handler. Returns false if the handler was already active. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleMapEvents │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - handleMapEvents: function(evt) { │ │ │ │ │ - if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveLayerToTop │ │ │ │ │ - * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ - * it. │ │ │ │ │ - */ │ │ │ │ │ - moveLayerToTop: function() { │ │ │ │ │ - var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ - this.layer.getZIndex()) + 1; │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveLayerBack │ │ │ │ │ - * Moves the layer back to the position determined by the map's layers │ │ │ │ │ - * array. │ │ │ │ │ - */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Feature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DragFeature.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - * @requires OpenLayers/Handler/Feature.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.DragFeature │ │ │ │ │ - * The DragFeature control moves a feature with a drag of the mouse. Create a │ │ │ │ │ - * new control with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits From: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometryTypes │ │ │ │ │ - * {Array(String)} To restrict dragging to a limited set of geometry types, │ │ │ │ │ - * send a list of strings corresponding to the geometry class names. │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onStart │ │ │ │ │ - * {Function} Define this function if you want to know when a drag starts. │ │ │ │ │ - * The function should expect to receive two arguments: the feature │ │ │ │ │ - * that is about to be dragged and the pixel location of the mouse. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that is about to be │ │ │ │ │ - * dragged. │ │ │ │ │ - * pixel - {} The pixel location of the mouse. │ │ │ │ │ - */ │ │ │ │ │ - onStart: function(feature, pixel) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onDrag │ │ │ │ │ - * {Function} Define this function if you want to know about each move of a │ │ │ │ │ - * feature. The function should expect to receive two arguments: the │ │ │ │ │ - * feature that is being dragged and the pixel location of the mouse. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that was dragged. │ │ │ │ │ - * pixel - {} The pixel location of the mouse. │ │ │ │ │ - */ │ │ │ │ │ - onDrag: function(feature, pixel) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onComplete │ │ │ │ │ - * {Function} Define this function if you want to know when a feature is │ │ │ │ │ - * done dragging. The function should expect to receive two arguments: │ │ │ │ │ - * the feature that is being dragged and the pixel location of the │ │ │ │ │ - * mouse. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that was dragged. │ │ │ │ │ - * pixel - {} The pixel location of the mouse. │ │ │ │ │ - */ │ │ │ │ │ - onComplete: function(feature, pixel) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onEnter │ │ │ │ │ - * {Function} Define this function if you want to know when the mouse │ │ │ │ │ - * goes over a feature and thereby makes this feature a candidate │ │ │ │ │ - * for dragging. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that is ready │ │ │ │ │ - * to be dragged. │ │ │ │ │ - */ │ │ │ │ │ - onEnter: function(feature) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onLeave │ │ │ │ │ - * {Function} Define this function if you want to know when the mouse │ │ │ │ │ - * goes out of the feature that was dragged. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that was dragged. │ │ │ │ │ - */ │ │ │ │ │ - onLeave: function(feature) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ - * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragCallbacks │ │ │ │ │ - * {Object} The functions that are sent to the drag handler for callback. │ │ │ │ │ - */ │ │ │ │ │ - dragCallbacks: {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: featureCallbacks │ │ │ │ │ - * {Object} The functions that are sent to the feature handler for callback. │ │ │ │ │ - */ │ │ │ │ │ - featureCallbacks: {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastPixel │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - lastPixel: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.DragFeature │ │ │ │ │ - * Create a new control to drag features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The layer containing features to be │ │ │ │ │ - * dragged. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.handlers = { │ │ │ │ │ - drag: new OpenLayers.Handler.Drag( │ │ │ │ │ - this, OpenLayers.Util.extend({ │ │ │ │ │ - down: this.downFeature, │ │ │ │ │ - move: this.moveFeature, │ │ │ │ │ - up: this.upFeature, │ │ │ │ │ - out: this.cancel, │ │ │ │ │ - done: this.doneDragging │ │ │ │ │ - }, this.dragCallbacks), { │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - } │ │ │ │ │ - ), │ │ │ │ │ - feature: new OpenLayers.Handler.Feature( │ │ │ │ │ - this, this.layer, OpenLayers.Util.extend({ │ │ │ │ │ - // 'click' and 'clickout' callback are for the mobile │ │ │ │ │ - // support: no 'over' or 'out' in touch based browsers. │ │ │ │ │ - click: this.clickFeature, │ │ │ │ │ - clickout: this.clickoutFeature, │ │ │ │ │ - over: this.overFeature, │ │ │ │ │ - out: this.outFeature │ │ │ │ │ - }, this.featureCallbacks), { │ │ │ │ │ - geometryTypes: this.geometryTypes │ │ │ │ │ - } │ │ │ │ │ - ) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clickFeature │ │ │ │ │ - * Called when the feature handler detects a click-in on a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - clickFeature: function(feature) { │ │ │ │ │ - if (this.handlers.feature.touch && !this.over && this.overFeature(feature)) { │ │ │ │ │ - this.handlers.drag.dragstart(this.handlers.feature.evt); │ │ │ │ │ - // to let the events propagate to the feature handler (click callback) │ │ │ │ │ - this.handlers.drag.stopDown = false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clickoutFeature │ │ │ │ │ - * Called when the feature handler detects a click-out on a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - clickoutFeature: function(feature) { │ │ │ │ │ - if (this.handlers.feature.touch && this.over) { │ │ │ │ │ - this.outFeature(feature); │ │ │ │ │ - this.handlers.drag.stopDown = true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Take care of things that are not handled in superclass │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.layer = null; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control and the feature handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully activated the control and feature handler. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - return (this.handlers.feature.activate() && │ │ │ │ │ - OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control and all handlers. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully deactivated the control. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - // the return from the handlers is unimportant in this case │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - this.handlers.feature.deactivate(); │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.lastPixel = null; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, this.displayClass + "Over" │ │ │ │ │ - ); │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: overFeature │ │ │ │ │ - * Called when the feature handler detects a mouse-over on a feature. │ │ │ │ │ - * This activates the drag handler. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The selected feature. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully activated the drag handler. │ │ │ │ │ - */ │ │ │ │ │ - overFeature: function(feature) { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (!this.handlers.drag.dragging) { │ │ │ │ │ - this.feature = feature; │ │ │ │ │ - this.handlers.drag.activate(); │ │ │ │ │ - activated = true; │ │ │ │ │ - this.over = true; │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, this.displayClass + "Over"); │ │ │ │ │ - this.onEnter(feature); │ │ │ │ │ - } else { │ │ │ │ │ - if (this.feature.id == feature.id) { │ │ │ │ │ - this.over = true; │ │ │ │ │ - } else { │ │ │ │ │ - this.over = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: downFeature │ │ │ │ │ - * Called when the drag handler detects a mouse-down. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} Location of the mouse event. │ │ │ │ │ - */ │ │ │ │ │ - downFeature: function(pixel) { │ │ │ │ │ - this.lastPixel = pixel; │ │ │ │ │ - this.onStart(this.feature, pixel); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveFeature │ │ │ │ │ - * Called when the drag handler detects a mouse-move. Also calls the │ │ │ │ │ - * optional onDrag method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} Location of the mouse event. │ │ │ │ │ - */ │ │ │ │ │ - moveFeature: function(pixel) { │ │ │ │ │ - var res = this.map.getResolution(); │ │ │ │ │ - this.feature.geometry.move(res * (pixel.x - this.lastPixel.x), │ │ │ │ │ - res * (this.lastPixel.y - pixel.y)); │ │ │ │ │ - this.layer.drawFeature(this.feature); │ │ │ │ │ - this.lastPixel = pixel; │ │ │ │ │ - this.onDrag(this.feature, pixel); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: upFeature │ │ │ │ │ - * Called when the drag handler detects a mouse-up. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} Location of the mouse event. │ │ │ │ │ - */ │ │ │ │ │ - upFeature: function(pixel) { │ │ │ │ │ - if (!this.over) { │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: doneDragging │ │ │ │ │ - * Called when the drag handler is done dragging. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The last event pixel location. If this event │ │ │ │ │ - * came from a mouseout, this may not be in the map viewport. │ │ │ │ │ - */ │ │ │ │ │ - doneDragging: function(pixel) { │ │ │ │ │ - this.onComplete(this.feature, pixel); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: outFeature │ │ │ │ │ - * Called when the feature handler detects a mouse-out on a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature that the mouse left. │ │ │ │ │ - */ │ │ │ │ │ - outFeature: function(feature) { │ │ │ │ │ - if (!this.handlers.drag.dragging) { │ │ │ │ │ - this.over = false; │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, this.displayClass + "Over" │ │ │ │ │ - ); │ │ │ │ │ - this.onLeave(feature); │ │ │ │ │ - this.feature = null; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.feature.id == feature.id) { │ │ │ │ │ - this.over = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: cancel │ │ │ │ │ - * Called when the drag handler detects a mouse-out (from the map viewport). │ │ │ │ │ - */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - this.over = false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control and all handlers. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The control's map. │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.handlers.drag.setMap(map); │ │ │ │ │ - this.handlers.feature.setMap(map); │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DragFeature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/TransformFeature.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Control/DragFeature.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.TransformFeature │ │ │ │ │ - * Control to transform features with a standard transformation box. │ │ │ │ │ - * │ │ │ │ │ - * Inherits From: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforesetfeature - Triggered before a feature is set for │ │ │ │ │ - * tranformation. The feature will not be set if a listener returns │ │ │ │ │ - * false. Listeners receive a *feature* property, with the feature │ │ │ │ │ - * that will be set for transformation. Listeners are allowed to │ │ │ │ │ - * set the control's *scale*, *ratio* and *rotation* properties, │ │ │ │ │ - * which will set the initial scale, ratio and rotation of the │ │ │ │ │ - * feature, like the method's initialParams argument. │ │ │ │ │ - * setfeature - Triggered when a feature is set for tranformation. │ │ │ │ │ - * Listeners receive a *feature* property, with the feature that │ │ │ │ │ - * is now set for transformation. │ │ │ │ │ - * beforetransform - Triggered while dragging, before a feature is │ │ │ │ │ - * transformed. The feature will not be transformed if a listener │ │ │ │ │ - * returns false (but the box still will). Listeners receive one or │ │ │ │ │ - * more of *center*, *scale*, *ratio* and *rotation*. The *center* │ │ │ │ │ - * property is an object with the new │ │ │ │ │ - * center of the transformed feature, the others are Floats with the │ │ │ │ │ - * scale, ratio or rotation change since the last transformation. │ │ │ │ │ - * transform - Triggered while dragging, when a feature is transformed. │ │ │ │ │ - * Listeners receive an event object with one or more of *center*, │ │ │ │ │ - * scale*, *ratio* and *rotation*. The *center* property is an │ │ │ │ │ - * object with the new center of the │ │ │ │ │ - * transformed feature, the others are Floats with the scale, ratio │ │ │ │ │ - * or rotation change of the feature since the last transformation. │ │ │ │ │ - * transformcomplete - Triggered after dragging. Listeners receive │ │ │ │ │ - * an event object with the transformed *feature*. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometryTypes │ │ │ │ │ - * {Array(String)} To restrict transformation to a limited set of geometry │ │ │ │ │ - * types, send a list of strings corresponding to the geometry class │ │ │ │ │ - * names. │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: preserveAspectRatio │ │ │ │ │ - * {Boolean} set to true to not change the feature's aspect ratio. │ │ │ │ │ - */ │ │ │ │ │ - preserveAspectRatio: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: rotate │ │ │ │ │ - * {Boolean} set to false if rotation should be disabled. Default is true. │ │ │ │ │ - * To be passed with the constructor or set when the control is not │ │ │ │ │ - * active. │ │ │ │ │ - */ │ │ │ │ │ - rotate: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: feature │ │ │ │ │ - * {} Feature currently available for │ │ │ │ │ - * transformation. Read-only, use to set it manually. │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: renderIntent │ │ │ │ │ - * {String|Object} Render intent for the transformation box and │ │ │ │ │ - * handles. A symbolizer object can also be provided here. │ │ │ │ │ - */ │ │ │ │ │ - renderIntent: "temporary", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: rotationHandleSymbolizer │ │ │ │ │ - * {Object|String} Optional. A custom symbolizer for the rotation handles. │ │ │ │ │ - * A render intent can also be provided here. Defaults to │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * stroke: false, │ │ │ │ │ - * pointRadius: 10, │ │ │ │ │ - * fillOpacity: 0, │ │ │ │ │ - * cursor: "pointer" │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ - rotationHandleSymbolizer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: box │ │ │ │ │ - * {} The transformation box rectangle. │ │ │ │ │ - * Read-only. │ │ │ │ │ - */ │ │ │ │ │ - box: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: center │ │ │ │ │ - * {} The center of the feature bounds. │ │ │ │ │ - * Read-only. │ │ │ │ │ - */ │ │ │ │ │ - center: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: scale │ │ │ │ │ - * {Float} The scale of the feature, relative to the scale the time the │ │ │ │ │ - * feature was set. Read-only, except for *beforesetfeature* │ │ │ │ │ - * listeners. │ │ │ │ │ - */ │ │ │ │ │ - scale: 1, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: ratio │ │ │ │ │ - * {Float} The ratio of the feature relative to the ratio the time the │ │ │ │ │ - * feature was set. Read-only, except for *beforesetfeature* │ │ │ │ │ - * listeners. │ │ │ │ │ - */ │ │ │ │ │ - ratio: 1, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: rotation │ │ │ │ │ - * {Integer} the current rotation angle of the box. Read-only, except for │ │ │ │ │ - * *beforesetfeature* listeners. │ │ │ │ │ - */ │ │ │ │ │ - rotation: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: handles │ │ │ │ │ - * {Array()} The 8 handles currently available │ │ │ │ │ - * for scaling/resizing. Numbered counterclockwise, starting from the │ │ │ │ │ - * southwest corner. Read-only. │ │ │ │ │ - */ │ │ │ │ │ - handles: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: rotationHandles │ │ │ │ │ - * {Array()} The 4 rotation handles currently │ │ │ │ │ - * available for rotating. Numbered counterclockwise, starting from │ │ │ │ │ - * the southwest corner. Read-only. │ │ │ │ │ - */ │ │ │ │ │ - rotationHandles: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragControl │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - dragControl: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: irregular │ │ │ │ │ - * {Boolean} Make scaling/resizing work irregularly. If true then │ │ │ │ │ - * dragging a handle causes the feature to resize in the direction │ │ │ │ │ - * of movement. If false then the feature resizes symetrically │ │ │ │ │ - * about it's center. │ │ │ │ │ - */ │ │ │ │ │ - irregular: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.TransformFeature │ │ │ │ │ - * Create a new transform feature control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} Layer that contains features that │ │ │ │ │ - * will be transformed. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - │ │ │ │ │ - if (!this.rotationHandleSymbolizer) { │ │ │ │ │ - this.rotationHandleSymbolizer = { │ │ │ │ │ - stroke: false, │ │ │ │ │ - pointRadius: 10, │ │ │ │ │ - fillOpacity: 0, │ │ │ │ │ - cursor: "pointer" │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.createBox(); │ │ │ │ │ - this.createControl(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragControl.activate(); │ │ │ │ │ - this.layer.addFeatures([this.box]); │ │ │ │ │ - this.rotate && this.layer.addFeatures(this.rotationHandles); │ │ │ │ │ - this.layer.addFeatures(this.handles); │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.layer.removeFeatures(this.handles); │ │ │ │ │ - this.rotate && this.layer.removeFeatures(this.rotationHandles); │ │ │ │ │ - this.layer.removeFeatures([this.box]); │ │ │ │ │ - this.dragControl.deactivate(); │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.dragControl.setMap(map); │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setFeature │ │ │ │ │ - * Place the transformation box on a feature and start transforming it. │ │ │ │ │ - * If the control is not active, it will be activated. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * initialParams - {Object} Initial values for rotation, scale or ratio. │ │ │ │ │ - * Setting a rotation value here will cause the transformation box to │ │ │ │ │ - * start rotated. Setting a scale or ratio will not affect the │ │ │ │ │ - * transormation box, but applications may use this to keep track of │ │ │ │ │ - * scale and ratio of a feature across multiple transforms. │ │ │ │ │ - */ │ │ │ │ │ - setFeature: function(feature, initialParams) { │ │ │ │ │ - initialParams = OpenLayers.Util.applyDefaults(initialParams, { │ │ │ │ │ - rotation: 0, │ │ │ │ │ - scale: 1, │ │ │ │ │ - ratio: 1 │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - var oldRotation = this.rotation; │ │ │ │ │ - var oldCenter = this.center; │ │ │ │ │ - OpenLayers.Util.extend(this, initialParams); │ │ │ │ │ - │ │ │ │ │ - var cont = this.events.triggerEvent("beforesetfeature", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (cont === false) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.feature = feature; │ │ │ │ │ - this.activate(); │ │ │ │ │ - │ │ │ │ │ - this._setfeature = true; │ │ │ │ │ - │ │ │ │ │ - var featureBounds = this.feature.geometry.getBounds(); │ │ │ │ │ - this.box.move(featureBounds.getCenterLonLat()); │ │ │ │ │ - this.box.geometry.rotate(-oldRotation, oldCenter); │ │ │ │ │ - this._angle = 0; │ │ │ │ │ - │ │ │ │ │ - var ll; │ │ │ │ │ - if (this.rotation) { │ │ │ │ │ - var geom = feature.geometry.clone(); │ │ │ │ │ - geom.rotate(-this.rotation, this.center); │ │ │ │ │ - var box = new OpenLayers.Feature.Vector( │ │ │ │ │ - geom.getBounds().toGeometry()); │ │ │ │ │ - box.geometry.rotate(this.rotation, this.center); │ │ │ │ │ - this.box.geometry.rotate(this.rotation, this.center); │ │ │ │ │ - this.box.move(box.geometry.getBounds().getCenterLonLat()); │ │ │ │ │ - var llGeom = box.geometry.components[0].components[0]; │ │ │ │ │ - ll = llGeom.getBounds().getCenterLonLat(); │ │ │ │ │ - } else { │ │ │ │ │ - ll = new OpenLayers.LonLat(featureBounds.left, featureBounds.bottom); │ │ │ │ │ - } │ │ │ │ │ - this.handles[0].move(ll); │ │ │ │ │ - │ │ │ │ │ - delete this._setfeature; │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("setfeature", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: unsetFeature │ │ │ │ │ - * Remove the transformation box off any feature. │ │ │ │ │ - * If the control is active, it will be deactivated first. │ │ │ │ │ - */ │ │ │ │ │ - unsetFeature: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - } else { │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.rotation = 0; │ │ │ │ │ - this.scale = 1; │ │ │ │ │ - this.ratio = 1; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createBox │ │ │ │ │ - * Creates the box with all handles and transformation handles. │ │ │ │ │ - */ │ │ │ │ │ - createBox: function() { │ │ │ │ │ - var control = this; │ │ │ │ │ - │ │ │ │ │ - this.center = new OpenLayers.Geometry.Point(0, 0); │ │ │ │ │ - this.box = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LineString([ │ │ │ │ │ - new OpenLayers.Geometry.Point(-1, -1), │ │ │ │ │ - new OpenLayers.Geometry.Point(0, -1), │ │ │ │ │ - new OpenLayers.Geometry.Point(1, -1), │ │ │ │ │ - new OpenLayers.Geometry.Point(1, 0), │ │ │ │ │ - new OpenLayers.Geometry.Point(1, 1), │ │ │ │ │ - new OpenLayers.Geometry.Point(0, 1), │ │ │ │ │ - new OpenLayers.Geometry.Point(-1, 1), │ │ │ │ │ - new OpenLayers.Geometry.Point(-1, 0), │ │ │ │ │ - new OpenLayers.Geometry.Point(-1, -1) │ │ │ │ │ - ]), null, │ │ │ │ │ - typeof this.renderIntent == "string" ? null : this.renderIntent │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // Override for box move - make sure that the center gets updated │ │ │ │ │ - this.box.geometry.move = function(x, y) { │ │ │ │ │ - control._moving = true; │ │ │ │ │ - OpenLayers.Geometry.LineString.prototype.move.apply(this, arguments); │ │ │ │ │ - control.center.move(x, y); │ │ │ │ │ - delete control._moving; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Overrides for vertex move, resize and rotate - make sure that │ │ │ │ │ - // handle and rotationHandle geometries are also moved, resized and │ │ │ │ │ - // rotated. │ │ │ │ │ - var vertexMoveFn = function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.apply(this, arguments); │ │ │ │ │ - this._rotationHandle && this._rotationHandle.geometry.move(x, y); │ │ │ │ │ - this._handle.geometry.move(x, y); │ │ │ │ │ - }; │ │ │ │ │ - var vertexResizeFn = function(scale, center, ratio) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.resize.apply(this, arguments); │ │ │ │ │ - this._rotationHandle && this._rotationHandle.geometry.resize( │ │ │ │ │ - scale, center, ratio); │ │ │ │ │ - this._handle.geometry.resize(scale, center, ratio); │ │ │ │ │ - }; │ │ │ │ │ - var vertexRotateFn = function(angle, center) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.rotate.apply(this, arguments); │ │ │ │ │ - this._rotationHandle && this._rotationHandle.geometry.rotate( │ │ │ │ │ - angle, center); │ │ │ │ │ - this._handle.geometry.rotate(angle, center); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Override for handle move - make sure that the box and other handles │ │ │ │ │ - // are updated, and finally transform the feature. │ │ │ │ │ - var handleMoveFn = function(x, y) { │ │ │ │ │ - var oldX = this.x, │ │ │ │ │ - oldY = this.y; │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - if (control._moving) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var evt = control.dragControl.handlers.drag.evt; │ │ │ │ │ - var preserveAspectRatio = !control._setfeature && │ │ │ │ │ - control.preserveAspectRatio; │ │ │ │ │ - var reshape = !preserveAspectRatio && !(evt && evt.shiftKey); │ │ │ │ │ - var oldGeom = new OpenLayers.Geometry.Point(oldX, oldY); │ │ │ │ │ - var centerGeometry = control.center; │ │ │ │ │ - this.rotate(-control.rotation, centerGeometry); │ │ │ │ │ - oldGeom.rotate(-control.rotation, centerGeometry); │ │ │ │ │ - var dx1 = this.x - centerGeometry.x; │ │ │ │ │ - var dy1 = this.y - centerGeometry.y; │ │ │ │ │ - var dx0 = dx1 - (this.x - oldGeom.x); │ │ │ │ │ - var dy0 = dy1 - (this.y - oldGeom.y); │ │ │ │ │ - if (control.irregular && !control._setfeature) { │ │ │ │ │ - dx1 -= (this.x - oldGeom.x) / 2; │ │ │ │ │ - dy1 -= (this.y - oldGeom.y) / 2; │ │ │ │ │ - } │ │ │ │ │ - this.x = oldX; │ │ │ │ │ - this.y = oldY; │ │ │ │ │ - var scale, ratio = 1; │ │ │ │ │ - if (reshape) { │ │ │ │ │ - scale = Math.abs(dy0) < 0.00001 ? 1 : dy1 / dy0; │ │ │ │ │ - ratio = (Math.abs(dx0) < 0.00001 ? 1 : (dx1 / dx0)) / scale; │ │ │ │ │ - } else { │ │ │ │ │ - var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ - var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ - scale = l1 / l0; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // rotate the box to 0 before resizing - saves us some │ │ │ │ │ - // calculations and is inexpensive because we don't drawFeature. │ │ │ │ │ - control._moving = true; │ │ │ │ │ - control.box.geometry.rotate(-control.rotation, centerGeometry); │ │ │ │ │ - delete control._moving; │ │ │ │ │ - │ │ │ │ │ - control.box.geometry.resize(scale, centerGeometry, ratio); │ │ │ │ │ - control.box.geometry.rotate(control.rotation, centerGeometry); │ │ │ │ │ - control.transformFeature({ │ │ │ │ │ - scale: scale, │ │ │ │ │ - ratio: ratio │ │ │ │ │ - }); │ │ │ │ │ - if (control.irregular && !control._setfeature) { │ │ │ │ │ - var newCenter = centerGeometry.clone(); │ │ │ │ │ - newCenter.x += Math.abs(oldX - centerGeometry.x) < 0.00001 ? 0 : (this.x - oldX); │ │ │ │ │ - newCenter.y += Math.abs(oldY - centerGeometry.y) < 0.00001 ? 0 : (this.y - oldY); │ │ │ │ │ - control.box.geometry.move(this.x - oldX, this.y - oldY); │ │ │ │ │ - control.transformFeature({ │ │ │ │ │ - center: newCenter │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Override for rotation handle move - make sure that the box and │ │ │ │ │ - // other handles are updated, and finally transform the feature. │ │ │ │ │ - var rotationHandleMoveFn = function(x, y) { │ │ │ │ │ - var oldX = this.x, │ │ │ │ │ - oldY = this.y; │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - if (control._moving) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var evt = control.dragControl.handlers.drag.evt; │ │ │ │ │ - var constrain = (evt && evt.shiftKey) ? 45 : 1; │ │ │ │ │ - var centerGeometry = control.center; │ │ │ │ │ - var dx1 = this.x - centerGeometry.x; │ │ │ │ │ - var dy1 = this.y - centerGeometry.y; │ │ │ │ │ - var dx0 = dx1 - x; │ │ │ │ │ - var dy0 = dy1 - y; │ │ │ │ │ - this.x = oldX; │ │ │ │ │ - this.y = oldY; │ │ │ │ │ - var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ - var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ - var angle = a1 - a0; │ │ │ │ │ - angle *= 180 / Math.PI; │ │ │ │ │ - control._angle = (control._angle + angle) % 360; │ │ │ │ │ - var diff = control.rotation % constrain; │ │ │ │ │ - if (Math.abs(control._angle) >= constrain || diff !== 0) { │ │ │ │ │ - angle = Math.round(control._angle / constrain) * constrain - │ │ │ │ │ - diff; │ │ │ │ │ - control._angle = 0; │ │ │ │ │ - control.box.geometry.rotate(angle, centerGeometry); │ │ │ │ │ - control.transformFeature({ │ │ │ │ │ - rotation: angle │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - var handles = new Array(8); │ │ │ │ │ - var rotationHandles = new Array(4); │ │ │ │ │ - var geom, handle, rotationHandle; │ │ │ │ │ - var positions = ["sw", "s", "se", "e", "ne", "n", "nw", "w"]; │ │ │ │ │ - for (var i = 0; i < 8; ++i) { │ │ │ │ │ - geom = this.box.geometry.components[i]; │ │ │ │ │ - handle = new OpenLayers.Feature.Vector(geom.clone(), { │ │ │ │ │ - role: positions[i] + "-resize" │ │ │ │ │ - }, typeof this.renderIntent == "string" ? null : │ │ │ │ │ - this.renderIntent); │ │ │ │ │ - if (i % 2 == 0) { │ │ │ │ │ - rotationHandle = new OpenLayers.Feature.Vector(geom.clone(), { │ │ │ │ │ - role: positions[i] + "-rotate" │ │ │ │ │ - }, typeof this.rotationHandleSymbolizer == "string" ? │ │ │ │ │ - null : this.rotationHandleSymbolizer); │ │ │ │ │ - rotationHandle.geometry.move = rotationHandleMoveFn; │ │ │ │ │ - geom._rotationHandle = rotationHandle; │ │ │ │ │ - rotationHandles[i / 2] = rotationHandle; │ │ │ │ │ - } │ │ │ │ │ - geom.move = vertexMoveFn; │ │ │ │ │ - geom.resize = vertexResizeFn; │ │ │ │ │ - geom.rotate = vertexRotateFn; │ │ │ │ │ - handle.geometry.move = handleMoveFn; │ │ │ │ │ - geom._handle = handle; │ │ │ │ │ - handles[i] = handle; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.rotationHandles = rotationHandles; │ │ │ │ │ - this.handles = handles; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createControl │ │ │ │ │ - * Creates a DragFeature control for this control. │ │ │ │ │ - */ │ │ │ │ │ - createControl: function() { │ │ │ │ │ - var control = this; │ │ │ │ │ - this.dragControl = new OpenLayers.Control.DragFeature(this.layer, { │ │ │ │ │ - documentDrag: true, │ │ │ │ │ - // avoid moving the feature itself - move the box instead │ │ │ │ │ - moveFeature: function(pixel) { │ │ │ │ │ - if (this.feature === control.feature) { │ │ │ │ │ - this.feature = control.box; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.DragFeature.prototype.moveFeature.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - }, │ │ │ │ │ - // transform while dragging │ │ │ │ │ - onDrag: function(feature, pixel) { │ │ │ │ │ - if (feature === control.box) { │ │ │ │ │ - control.transformFeature({ │ │ │ │ │ - center: control.center │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - // set a new feature │ │ │ │ │ - onStart: function(feature, pixel) { │ │ │ │ │ - var eligible = !control.geometryTypes || │ │ │ │ │ - OpenLayers.Util.indexOf(control.geometryTypes, │ │ │ │ │ - feature.geometry.CLASS_NAME) !== -1; │ │ │ │ │ - var i = OpenLayers.Util.indexOf(control.handles, feature); │ │ │ │ │ - i += OpenLayers.Util.indexOf(control.rotationHandles, │ │ │ │ │ - feature); │ │ │ │ │ - if (feature !== control.feature && feature !== control.box && │ │ │ │ │ - i == -2 && eligible) { │ │ │ │ │ - control.setFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - onComplete: function(feature, pixel) { │ │ │ │ │ - control.events.triggerEvent("transformcomplete", { │ │ │ │ │ - feature: control.feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawHandles │ │ │ │ │ - * Draws the handles to match the box. │ │ │ │ │ - */ │ │ │ │ │ - drawHandles: function() { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - for (var i = 0; i < 8; ++i) { │ │ │ │ │ - if (this.rotate && i % 2 === 0) { │ │ │ │ │ - layer.drawFeature(this.rotationHandles[i / 2], │ │ │ │ │ - this.rotationHandleSymbolizer); │ │ │ │ │ - } │ │ │ │ │ - layer.drawFeature(this.handles[i], this.renderIntent); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: transformFeature │ │ │ │ │ - * Transforms the feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * mods - {Object} An object with optional scale, ratio, rotation and │ │ │ │ │ - * center properties. │ │ │ │ │ - */ │ │ │ │ │ - transformFeature: function(mods) { │ │ │ │ │ - if (!this._setfeature) { │ │ │ │ │ - this.scale *= (mods.scale || 1); │ │ │ │ │ - this.ratio *= (mods.ratio || 1); │ │ │ │ │ - var oldRotation = this.rotation; │ │ │ │ │ - this.rotation = (this.rotation + (mods.rotation || 0)) % 360; │ │ │ │ │ - │ │ │ │ │ - if (this.events.triggerEvent("beforetransform", mods) !== false) { │ │ │ │ │ - var feature = this.feature; │ │ │ │ │ - var geom = feature.geometry; │ │ │ │ │ - var center = this.center; │ │ │ │ │ - geom.rotate(-oldRotation, center); │ │ │ │ │ - if (mods.scale || mods.ratio) { │ │ │ │ │ - geom.resize(mods.scale, center, mods.ratio); │ │ │ │ │ - } else if (mods.center) { │ │ │ │ │ - feature.move(mods.center.getBounds().getCenterLonLat()); │ │ │ │ │ - } │ │ │ │ │ - geom.rotate(this.rotation, center); │ │ │ │ │ - this.layer.drawFeature(feature); │ │ │ │ │ - feature.toState(OpenLayers.State.UPDATE); │ │ │ │ │ - this.events.triggerEvent("transform", mods); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.layer.drawFeature(this.box, this.renderIntent); │ │ │ │ │ - this.drawHandles(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Take care of things that are not handled in superclass. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - var geom; │ │ │ │ │ - for (var i = 0; i < 8; ++i) { │ │ │ │ │ - geom = this.box.geometry.components[i]; │ │ │ │ │ - geom._handle.destroy(); │ │ │ │ │ - geom._handle = null; │ │ │ │ │ - geom._rotationHandle && geom._rotationHandle.destroy(); │ │ │ │ │ - geom._rotationHandle = null; │ │ │ │ │ - } │ │ │ │ │ - this.center = null; │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.handles = null; │ │ │ │ │ - this.rotationHandleSymbolizer = null; │ │ │ │ │ - this.rotationHandles = null; │ │ │ │ │ - this.box.destroy(); │ │ │ │ │ - this.box = null; │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.dragControl.destroy(); │ │ │ │ │ - this.dragControl = null; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.TransformFeature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/CacheRead.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/Control.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.CacheRead │ │ │ │ │ - * A control for using image tiles cached with │ │ │ │ │ - * from the browser's local storage. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheRead = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fetchEvent │ │ │ │ │ - * {String} The layer event to listen to for replacing remote resource tile │ │ │ │ │ - * URLs with cached data URIs. Supported values are "tileerror" (try │ │ │ │ │ - * remote first, fall back to cached) and "tileloadstart" (try cache │ │ │ │ │ - * first, fall back to remote). Default is "tileloadstart". │ │ │ │ │ - * │ │ │ │ │ - * Note that "tileerror" will not work for CORS enabled images (see │ │ │ │ │ - * https://developer.mozilla.org/en/CORS_Enabled_Image), i.e. layers │ │ │ │ │ - * configured with a in │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - fetchEvent: "tileloadstart", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()}. Optional. If provided, only these │ │ │ │ │ - * layers will receive tiles from the cache. │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.CacheRead │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Object with API properties for this control │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - var i, layers = this.layers || map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!this.layers) { │ │ │ │ │ - map.events.on({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ - * will be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - evt.layer.events.register(this.fetchEvent, this, this.fetch); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ - * layer will no longer be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - evt.layer.events.unregister(this.fetchEvent, this, this.fetch); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: fetch │ │ │ │ │ - * Listener to the event. Replaces a tile's url with a data │ │ │ │ │ - * URI from the cache. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Event object with a tile property. │ │ │ │ │ - */ │ │ │ │ │ - fetch: function(evt) { │ │ │ │ │ - if (this.active && window.localStorage && │ │ │ │ │ - evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ - var tile = evt.tile, │ │ │ │ │ - url = tile.url; │ │ │ │ │ - // deal with modified tile urls when both CacheWrite and CacheRead │ │ │ │ │ - // are active │ │ │ │ │ - if (!tile.layer.crossOriginKeyword && OpenLayers.ProxyHost && │ │ │ │ │ - url.indexOf(OpenLayers.ProxyHost) === 0) { │ │ │ │ │ - url = OpenLayers.Control.CacheWrite.urlMap[url]; │ │ │ │ │ - } │ │ │ │ │ - var dataURI = window.localStorage.getItem("olCache_" + url); │ │ │ │ │ - if (dataURI) { │ │ │ │ │ - tile.url = dataURI; │ │ │ │ │ - if (evt.type === "tileerror") { │ │ │ │ │ - tile.setImgSrc(dataURI); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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.layers || this.map) { │ │ │ │ │ - var i, layers = this.layers || this.map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.CacheRead" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PanZoom.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PanZoom │ │ │ │ │ - * The PanZoom is a visible control, composed of a │ │ │ │ │ - * and a . By │ │ │ │ │ - * default it is drawn in the upper left corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ - * on clicking the arrow buttons. If you want to pan by some ratio │ │ │ │ │ - * of the map dimensions, use instead. │ │ │ │ │ - */ │ │ │ │ │ - slideFactor: 50, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideRatio │ │ │ │ │ - * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ - * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ - * override . E.g. if slideRatio is .5, then the Pan Up │ │ │ │ │ - * button will pan up half the map height. │ │ │ │ │ - */ │ │ │ │ │ - slideRatio: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: buttons │ │ │ │ │ - * {Array(DOMElement)} Array of Button Divs │ │ │ │ │ - */ │ │ │ │ │ - buttons: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: position │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - position: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PanZoom │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X, │ │ │ │ │ - OpenLayers.Control.PanZoom.Y); │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } │ │ │ │ │ - this.removeButtons(); │ │ │ │ │ - this.buttons = null; │ │ │ │ │ - this.position = null; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Properties: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the container div for the PanZoom control. │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - // initialize our internal div │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - px = this.position; │ │ │ │ │ - │ │ │ │ │ - // place the controls │ │ │ │ │ - this.buttons = []; │ │ │ │ │ - │ │ │ │ │ - var sz = { │ │ │ │ │ - w: 18, │ │ │ │ │ - h: 18 │ │ │ │ │ - }; │ │ │ │ │ - var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ - │ │ │ │ │ - this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ - px.y = centered.y + sz.h; │ │ │ │ │ - this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ - this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ - this._addButton("pandown", "south-mini.png", │ │ │ │ │ - centered.add(0, sz.h * 2), sz); │ │ │ │ │ - this._addButton("zoomin", "zoom-plus-mini.png", │ │ │ │ │ - centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ - this._addButton("zoomworld", "zoom-world-mini.png", │ │ │ │ │ - centered.add(0, sz.h * 4 + 5), sz); │ │ │ │ │ - this._addButton("zoomout", "zoom-minus-mini.png", │ │ │ │ │ - centered.add(0, sz.h * 5 + 5), sz); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _addButton │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} │ │ │ │ │ - * img - {String} │ │ │ │ │ - * xy - {} │ │ │ │ │ - * sz - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A Div (an alphaImageDiv, to be precise) that contains the │ │ │ │ │ - * image of the button, and has all the proper event handlers set. │ │ │ │ │ - */ │ │ │ │ │ - _addButton: function(id, img, xy, sz) { │ │ │ │ │ - var imgLocation = OpenLayers.Util.getImageLocation(img); │ │ │ │ │ - var btn = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - this.id + "_" + id, │ │ │ │ │ - xy, sz, imgLocation, "absolute"); │ │ │ │ │ - btn.style.cursor = "pointer"; │ │ │ │ │ - //we want to add the outer div │ │ │ │ │ - this.div.appendChild(btn); │ │ │ │ │ - btn.action = id; │ │ │ │ │ - btn.className = "olButton"; │ │ │ │ │ - │ │ │ │ │ - //we want to remember/reference the outer div │ │ │ │ │ - this.buttons.push(btn); │ │ │ │ │ - return btn; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _removeButton │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * btn - {Object} │ │ │ │ │ - */ │ │ │ │ │ - _removeButton: function(btn) { │ │ │ │ │ - this.div.removeChild(btn); │ │ │ │ │ - OpenLayers.Util.removeItem(this.buttons, btn); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeButtons │ │ │ │ │ - */ │ │ │ │ │ - removeButtons: function() { │ │ │ │ │ - for (var i = this.buttons.length - 1; i >= 0; --i) { │ │ │ │ │ - this._removeButton(this.buttons[i]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - var btn = evt.buttonElement; │ │ │ │ │ - switch (btn.action) { │ │ │ │ │ - case "panup": │ │ │ │ │ - this.map.pan(0, -this.getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case "pandown": │ │ │ │ │ - this.map.pan(0, this.getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case "panleft": │ │ │ │ │ - this.map.pan(-this.getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ - case "panright": │ │ │ │ │ - this.map.pan(this.getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ - case "zoomin": │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - break; │ │ │ │ │ - case "zoomout": │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ - break; │ │ │ │ │ - case "zoomworld": │ │ │ │ │ - this.map.zoomToMaxExtent(); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSlideFactor │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dim - {String} "w" or "h" (for width or height). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The slide factor for panning in the requested direction. │ │ │ │ │ - */ │ │ │ │ │ - getSlideFactor: function(dim) { │ │ │ │ │ - return this.slideRatio ? │ │ │ │ │ - this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ - this.slideFactor; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PanZoom" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: X │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoom.X = 4; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: Y │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoom.Y = 4; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PanZoomBar.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/Control/PanZoom.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PanZoomBar │ │ │ │ │ - * The PanZoomBar is a visible control composed of a │ │ │ │ │ - * and a . │ │ │ │ │ - * By default it is displayed in the upper left corner of the map as 4 │ │ │ │ │ - * directional arrows above a vertical slider. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomStopWidth │ │ │ │ │ - */ │ │ │ │ │ - zoomStopWidth: 18, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomStopHeight │ │ │ │ │ - */ │ │ │ │ │ - zoomStopHeight: 11, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: slider │ │ │ │ │ - */ │ │ │ │ │ - slider: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: sliderEvents │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - sliderEvents: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoombarDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - zoombarDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomWorldIcon │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - zoomWorldIcon: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: panIcons │ │ │ │ │ - * {Boolean} Set this property to false not to display the pan icons. If │ │ │ │ │ - * false the zoom world icon is placed under the zoom bar. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - panIcons: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: forceFixedZoomLevel │ │ │ │ │ - * {Boolean} Force a fixed zoom level even though the map has │ │ │ │ │ - * fractionalZoom │ │ │ │ │ - */ │ │ │ │ │ - forceFixedZoomLevel: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: mouseDragStart │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - mouseDragStart: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: deltaY │ │ │ │ │ - * {Number} The cumulative vertical pixel offset during a zoom bar drag. │ │ │ │ │ - */ │ │ │ │ │ - deltaY: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomStart │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - zoomStart: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PanZoomBar │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - this._removeZoomBar(); │ │ │ │ │ - │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "changebaselayer": this.redraw, │ │ │ │ │ - "updatesize": this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - delete this.mouseDragStart; │ │ │ │ │ - delete this.zoomStart; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments); │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "changebaselayer": this.redraw, │ │ │ │ │ - "updatesize": this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ - * clear the div and start over. │ │ │ │ │ - */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.removeButtons(); │ │ │ │ │ - this._removeZoomBar(); │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - // initialize our internal div │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - px = this.position.clone(); │ │ │ │ │ - │ │ │ │ │ - // place the controls │ │ │ │ │ - this.buttons = []; │ │ │ │ │ - │ │ │ │ │ - var sz = { │ │ │ │ │ - w: 18, │ │ │ │ │ - h: 18 │ │ │ │ │ - }; │ │ │ │ │ - if (this.panIcons) { │ │ │ │ │ - var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ - var wposition = sz.w; │ │ │ │ │ - │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - centered = new OpenLayers.Pixel(px.x + sz.w, px.y); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ - px.y = centered.y + sz.h; │ │ │ │ │ - this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ - │ │ │ │ │ - wposition *= 2; │ │ │ │ │ - } │ │ │ │ │ - this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); │ │ │ │ │ - this._addButton("pandown", "south-mini.png", centered.add(0, sz.h * 2), sz); │ │ │ │ │ - this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ - centered = this._addZoomBar(centered.add(0, sz.h * 4 + 5)); │ │ │ │ │ - this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ - } else { │ │ │ │ │ - this._addButton("zoomin", "zoom-plus-mini.png", px, sz); │ │ │ │ │ - centered = this._addZoomBar(px.add(0, sz.h)); │ │ │ │ │ - this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - centered = centered.add(0, sz.h + 3); │ │ │ │ │ - this._addButton("zoomworld", "zoom-world-mini.png", centered, sz); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _addZoomBar │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * centered - {} where zoombar drawing is to start. │ │ │ │ │ - */ │ │ │ │ │ - _addZoomBar: function(centered) { │ │ │ │ │ - var imgLocation = OpenLayers.Util.getImageLocation("slider.png"); │ │ │ │ │ - var id = this.id + "_" + this.map.id; │ │ │ │ │ - var minZoom = this.map.getMinZoom(); │ │ │ │ │ - var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom(); │ │ │ │ │ - var slider = OpenLayers.Util.createAlphaImageDiv(id, │ │ │ │ │ - centered.add(-1, zoomsToEnd * this.zoomStopHeight), { │ │ │ │ │ - w: 20, │ │ │ │ │ - h: 9 │ │ │ │ │ - }, │ │ │ │ │ - imgLocation, │ │ │ │ │ - "absolute"); │ │ │ │ │ - slider.style.cursor = "move"; │ │ │ │ │ - this.slider = slider; │ │ │ │ │ - │ │ │ │ │ - this.sliderEvents = new OpenLayers.Events(this, slider, null, true, { │ │ │ │ │ - includeXY: true │ │ │ │ │ - }); │ │ │ │ │ - this.sliderEvents.on({ │ │ │ │ │ - "touchstart": this.zoomBarDown, │ │ │ │ │ - "touchmove": this.zoomBarDrag, │ │ │ │ │ - "touchend": this.zoomBarUp, │ │ │ │ │ - "mousedown": this.zoomBarDown, │ │ │ │ │ - "mousemove": this.zoomBarDrag, │ │ │ │ │ - "mouseup": this.zoomBarUp │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - var sz = { │ │ │ │ │ - w: this.zoomStopWidth, │ │ │ │ │ - h: this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom) │ │ │ │ │ - }; │ │ │ │ │ - var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png"); │ │ │ │ │ - var div = null; │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.Util.alphaHack()) { │ │ │ │ │ - var id = this.id + "_" + this.map.id; │ │ │ │ │ - div = OpenLayers.Util.createAlphaImageDiv(id, centered, { │ │ │ │ │ - w: sz.w, │ │ │ │ │ - h: this.zoomStopHeight │ │ │ │ │ - }, │ │ │ │ │ - imgLocation, │ │ │ │ │ - "absolute", null, "crop"); │ │ │ │ │ - div.style.height = sz.h + "px"; │ │ │ │ │ - } else { │ │ │ │ │ - div = OpenLayers.Util.createDiv( │ │ │ │ │ - 'OpenLayers_Control_PanZoomBar_Zoombar' + this.map.id, │ │ │ │ │ - centered, │ │ │ │ │ - sz, │ │ │ │ │ - imgLocation); │ │ │ │ │ - } │ │ │ │ │ - div.style.cursor = "pointer"; │ │ │ │ │ - div.className = "olButton"; │ │ │ │ │ - this.zoombarDiv = div; │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(div); │ │ │ │ │ - │ │ │ │ │ - this.startTop = parseInt(div.style.top); │ │ │ │ │ - this.div.appendChild(slider); │ │ │ │ │ - │ │ │ │ │ - this.map.events.register("zoomend", this, this.moveZoomBar); │ │ │ │ │ - │ │ │ │ │ - centered = centered.add(0, │ │ │ │ │ - this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom)); │ │ │ │ │ - return centered; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _removeZoomBar │ │ │ │ │ - */ │ │ │ │ │ - _removeZoomBar: function() { │ │ │ │ │ - this.sliderEvents.un({ │ │ │ │ │ - "touchstart": this.zoomBarDown, │ │ │ │ │ - "touchmove": this.zoomBarDrag, │ │ │ │ │ - "touchend": this.zoomBarUp, │ │ │ │ │ - "mousedown": this.zoomBarDown, │ │ │ │ │ - "mousemove": this.zoomBarDrag, │ │ │ │ │ - "mouseup": this.zoomBarUp │ │ │ │ │ - }); │ │ │ │ │ - this.sliderEvents.destroy(); │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.zoombarDiv); │ │ │ │ │ - this.zoombarDiv = null; │ │ │ │ │ - this.div.removeChild(this.slider); │ │ │ │ │ - this.slider = null; │ │ │ │ │ - │ │ │ │ │ - this.map.events.unregister("zoomend", this, this.moveZoomBar); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.onButtonClick.apply(this, arguments); │ │ │ │ │ - if (evt.buttonElement === this.zoombarDiv) { │ │ │ │ │ - var levels = evt.buttonXY.y / this.zoomStopHeight; │ │ │ │ │ - if (this.forceFixedZoomLevel || !this.map.fractionalZoom) { │ │ │ │ │ - levels = Math.floor(levels); │ │ │ │ │ - } │ │ │ │ │ - var zoom = (this.map.getNumZoomLevels() - 1) - levels; │ │ │ │ │ - zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); │ │ │ │ │ - this.map.zoomTo(zoom); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: passEventToSlider │ │ │ │ │ - * This function is used to pass events that happen on the div, or the map, │ │ │ │ │ - * through to the slider, which then does its moving thing. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - passEventToSlider: function(evt) { │ │ │ │ │ - this.sliderEvents.handleBrowserEvent(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarDown │ │ │ │ │ - * event listener for clicks on the slider │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarDown: function(evt) { │ │ │ │ │ - if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "touchmove": this.passEventToSlider, │ │ │ │ │ - "mousemove": this.passEventToSlider, │ │ │ │ │ - "mouseup": this.passEventToSlider, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ - this.zoomStart = evt.xy.clone(); │ │ │ │ │ - this.div.style.cursor = "move"; │ │ │ │ │ - // reset the div offsets just in case the div moved │ │ │ │ │ - this.zoombarDiv.offsets = null; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarDrag │ │ │ │ │ - * This is what happens when a click has occurred, and the client is │ │ │ │ │ - * dragging. Here we must ensure that the slider doesn't go beyond the │ │ │ │ │ - * bottom/top of the zoombar div, as well as moving the slider to its new │ │ │ │ │ - * visual location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarDrag: function(evt) { │ │ │ │ │ - if (this.mouseDragStart != null) { │ │ │ │ │ - var deltaY = this.mouseDragStart.y - evt.xy.y; │ │ │ │ │ - var offsets = OpenLayers.Util.pagePosition(this.zoombarDiv); │ │ │ │ │ - if ((evt.clientY - offsets[1]) > 0 && │ │ │ │ │ - (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { │ │ │ │ │ - var newTop = parseInt(this.slider.style.top) - deltaY; │ │ │ │ │ - this.slider.style.top = newTop + "px"; │ │ │ │ │ - this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ - } │ │ │ │ │ - // set cumulative displacement │ │ │ │ │ - this.deltaY = this.zoomStart.y - evt.xy.y; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarUp │ │ │ │ │ - * Perform cleanup when a mouseup event is received -- discover new zoom │ │ │ │ │ - * level and switch to it. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarUp: function(evt) { │ │ │ │ │ - if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.mouseDragStart) { │ │ │ │ │ - this.div.style.cursor = ""; │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "touchmove": this.passEventToSlider, │ │ │ │ │ - "mouseup": this.passEventToSlider, │ │ │ │ │ - "mousemove": this.passEventToSlider, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - var zoomLevel = this.map.zoom; │ │ │ │ │ - if (!this.forceFixedZoomLevel && this.map.fractionalZoom) { │ │ │ │ │ - zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ - zoomLevel = Math.min(Math.max(zoomLevel, 0), │ │ │ │ │ - this.map.getNumZoomLevels() - 1); │ │ │ │ │ - } else { │ │ │ │ │ - zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ - zoomLevel = Math.max(Math.round(zoomLevel), 0); │ │ │ │ │ - } │ │ │ │ │ - this.map.zoomTo(zoomLevel); │ │ │ │ │ - this.mouseDragStart = null; │ │ │ │ │ - this.zoomStart = null; │ │ │ │ │ - this.deltaY = 0; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: moveZoomBar │ │ │ │ │ - * Change the location of the slider to match the current zoom level. │ │ │ │ │ - */ │ │ │ │ │ - moveZoomBar: function() { │ │ │ │ │ - var newTop = │ │ │ │ │ - ((this.map.getNumZoomLevels() - 1) - this.map.getZoom()) * │ │ │ │ │ - this.zoomStopHeight + this.startTop + 1; │ │ │ │ │ - this.slider.style.top = newTop + "px"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PanZoomBar" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/WMS.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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.WMS │ │ │ │ │ - * Instances of OpenLayers.Layer.WMS are used to display data from OGC Web │ │ │ │ │ - * Mapping Services. Create a new WMS layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Constant: DEFAULT_PARAMS │ │ │ │ │ * {Object} Hashtable of default parameter key/value pairs │ │ │ │ │ */ │ │ │ │ │ DEFAULT_PARAMS: { │ │ │ │ │ service: "WMS", │ │ │ │ │ @@ -49724,14 +42888,333 @@ │ │ │ │ │ this.clear(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Handler.RegularPolygon" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Handler/Polygon.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 │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + holeModifier: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: drawingHole │ │ │ │ │ + * {Boolean} Currently drawing an interior ring. │ │ │ │ │ + */ │ │ │ │ │ + drawingHole: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: polygon │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + polygon: 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. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createFeature │ │ │ │ │ + * Add temporary geometries │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The initial pixel location for the new │ │ │ │ │ + * feature. │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addPoint │ │ │ │ │ + * Add point to geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The pixel location for the new point. │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getCurrentPointIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The index of the most recently drawn point. │ │ │ │ │ + */ │ │ │ │ │ + getCurrentPointIndex: function() { │ │ │ │ │ + return this.line.geometry.components.length - 2; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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). │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: finishGeometry │ │ │ │ │ + * Finish the geometry and send it back to the control. │ │ │ │ │ + */ │ │ │ │ │ + finishGeometry: function() { │ │ │ │ │ + var index = this.line.geometry.components.length - 2; │ │ │ │ │ + this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ + this.removePoint(); │ │ │ │ │ + this.finalize(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: finalizeInteriorRing │ │ │ │ │ + * Enforces that new ring has some area and doesn't contain vertices of any │ │ │ │ │ + * other rings. │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + */ │ │ │ │ │ + cancel: function() { │ │ │ │ │ + if (this.drawingHole) { │ │ │ │ │ + this.polygon.geometry.removeComponent(this.line.geometry); │ │ │ │ │ + this.restoreFeature(true); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyFeature │ │ │ │ │ + * Destroy temporary geometries │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + */ │ │ │ │ │ + destroyFeature: function(force) { │ │ │ │ │ + OpenLayers.Handler.Path.prototype.destroyFeature.call( │ │ │ │ │ + this, force); │ │ │ │ │ + this.polygon = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Render geometries on the temporary layer. │ │ │ │ │ + */ │ │ │ │ │ + drawFeature: function() { │ │ │ │ │ + this.layer.drawFeature(this.polygon, this.style); │ │ │ │ │ + this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSketch │ │ │ │ │ + * Return the sketch feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getSketch: function() { │ │ │ │ │ + return this.polygon; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeometry │ │ │ │ │ + * Return the sketch geometry. If is true, this will return │ │ │ │ │ + * a multi-part geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + 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/Format/SLD.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. */ │ │ │ │ │ @@ -52220,2645 +45703,1674 @@ │ │ │ │ │ } │ │ │ │ │ canApply && this._queue.call(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.SLDSelect" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Geolocate.js │ │ │ │ │ + OpenLayers/Control/ZoomToMaxExtent.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Geolocate │ │ │ │ │ - * The Geolocate control wraps w3c geolocation API into control that can be │ │ │ │ │ - * bound to a map, and generate events on location update │ │ │ │ │ - * │ │ │ │ │ - * To use this control requires to load the proj4js library if the projection │ │ │ │ │ - * of the map is not EPSG:4326 or EPSG:900913. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.ZoomToMaxExtent │ │ │ │ │ + * The ZoomToMaxExtent control is a button that zooms out to the maximum │ │ │ │ │ + * extent of the map. It is designed to be used with a │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * locationupdated - Triggered when browser return a new position. Listeners will │ │ │ │ │ - * receive an object with a 'position' property which is the browser.geolocation.position │ │ │ │ │ - * native object, as well as a 'point' property which is the location transformed in the │ │ │ │ │ - * current map projection. │ │ │ │ │ - * locationfailed - Triggered when geolocation has failed │ │ │ │ │ - * locationuncapable - Triggered when control is activated on a browser │ │ │ │ │ - * which doesn't support geolocation │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Control.ZoomToMaxExtent = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: geolocation │ │ │ │ │ - * {Object} The geolocation engine, as a property to be possibly mocked. │ │ │ │ │ - * This is set lazily to avoid a memory leak in IE9. │ │ │ │ │ + * Method: trigger │ │ │ │ │ + * │ │ │ │ │ + * Called whenever this control is being rendered inside of a panel and a │ │ │ │ │ + * click occurs on this controls element. Actually zooms to the maximum │ │ │ │ │ + * extent of this controls map. │ │ │ │ │ */ │ │ │ │ │ - geolocation: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: available │ │ │ │ │ - * {Boolean} The navigator.geolocation object is available. │ │ │ │ │ - */ │ │ │ │ │ - available: ('geolocation' in navigator), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: bind │ │ │ │ │ - * {Boolean} If true, map center will be set on location update. │ │ │ │ │ - */ │ │ │ │ │ - bind: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: watch │ │ │ │ │ - * {Boolean} If true, position will be update regularly. │ │ │ │ │ - */ │ │ │ │ │ - watch: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geolocationOptions │ │ │ │ │ - * {Object} Options to pass to the navigator's geolocation API. See │ │ │ │ │ - * . No specific │ │ │ │ │ - * option is passed to the geolocation API by default. │ │ │ │ │ - */ │ │ │ │ │ - geolocationOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Geolocate │ │ │ │ │ - * Create a new control to deal with browser geolocation API │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.available && !this.geolocation) { │ │ │ │ │ - // set lazily to avoid IE9 memory leak │ │ │ │ │ - this.geolocation = navigator.geolocation; │ │ │ │ │ - } │ │ │ │ │ - if (!this.geolocation) { │ │ │ │ │ - this.events.triggerEvent("locationuncapable"); │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - if (this.watch) { │ │ │ │ │ - this.watchId = this.geolocation.watchPosition( │ │ │ │ │ - OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ - OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ - this.geolocationOptions │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.getCurrentLocation(); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active && this.watchId !== null) { │ │ │ │ │ - this.geolocation.clearWatch(this.watchId); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: geolocate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - geolocate: function(position) { │ │ │ │ │ - var center = new OpenLayers.LonLat( │ │ │ │ │ - position.coords.longitude, │ │ │ │ │ - position.coords.latitude │ │ │ │ │ - ).transform( │ │ │ │ │ - new OpenLayers.Projection("EPSG:4326"), │ │ │ │ │ - this.map.getProjectionObject() │ │ │ │ │ - ); │ │ │ │ │ - if (this.bind) { │ │ │ │ │ - this.map.setCenter(center); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("locationupdated", { │ │ │ │ │ - position: position, │ │ │ │ │ - point: new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ) │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCurrentLocation │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Returns true if a event will be fired (successfull │ │ │ │ │ - * registration) │ │ │ │ │ - */ │ │ │ │ │ - getCurrentLocation: function() { │ │ │ │ │ - if (!this.active || this.watch) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - this.geolocation.getCurrentPosition( │ │ │ │ │ - OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ - OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ - this.geolocationOptions │ │ │ │ │ - ); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: failure │ │ │ │ │ - * method called on browser's geolocation failure │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - failure: function(error) { │ │ │ │ │ - this.events.triggerEvent("locationfailed", { │ │ │ │ │ - error: error │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Geolocate" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Scale.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Scale │ │ │ │ │ - * The Scale control displays the current map scale as a ratio (e.g. Scale = │ │ │ │ │ - * 1:1M). By default it is displayed in the lower right corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - element: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ - * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ - * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ - * pixel in the center of the map viewport. │ │ │ │ │ - */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Scale │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(element, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.element = OpenLayers.Util.getElement(element); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (!this.element) { │ │ │ │ │ - this.element = document.createElement("div"); │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ - } │ │ │ │ │ - this.map.events.register('moveend', this, this.updateScale); │ │ │ │ │ - this.updateScale(); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateScale │ │ │ │ │ - */ │ │ │ │ │ - updateScale: function() { │ │ │ │ │ - var scale; │ │ │ │ │ - if (this.geodesic === true) { │ │ │ │ │ - var units = this.map.getUnits(); │ │ │ │ │ - if (!units) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ - scale = (this.map.getGeodesicPixelSize().w || 0.000001) * │ │ │ │ │ - inches["km"] * OpenLayers.DOTS_PER_INCH; │ │ │ │ │ - } else { │ │ │ │ │ - scale = this.map.getScale(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!scale) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (scale >= 9500 && scale <= 950000) { │ │ │ │ │ - scale = Math.round(scale / 1000) + "K"; │ │ │ │ │ - } else if (scale >= 950000) { │ │ │ │ │ - scale = Math.round(scale / 1000000) + "M"; │ │ │ │ │ - } else { │ │ │ │ │ - scale = Math.round(scale); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.element.innerHTML = OpenLayers.i18n("Scale = 1 : ${scaleDenom}", { │ │ │ │ │ - 'scaleDenom': scale │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Scale" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/NavToolbar.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/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.NavToolbar │ │ │ │ │ - * This Toolbar is an alternative to the Navigation control that displays │ │ │ │ │ - * the state of the control, and provides a UI for changing state to │ │ │ │ │ - * use the zoomBox via a Panel control. │ │ │ │ │ - * │ │ │ │ │ - * If you wish to change the properties of the Navigation control used │ │ │ │ │ - * in the NavToolbar, see: │ │ │ │ │ - * http://trac.openlayers.org/wiki/Toolbars#SubclassingNavToolbar │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.NavToolbar = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.NavToolbar │ │ │ │ │ - * Add our two mousedefaults controls. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.addControls([ │ │ │ │ │ - new OpenLayers.Control.Navigation(), │ │ │ │ │ - new OpenLayers.Control.ZoomBox() │ │ │ │ │ - ]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * calls the default draw, and then activates mouse defaults. │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.defaultControl === null) { │ │ │ │ │ - this.defaultControl = this.controls[0]; │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomToMaxExtent(); │ │ │ │ │ } │ │ │ │ │ - return div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.NavToolbar" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomToMaxExtent" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Measure.js │ │ │ │ │ + OpenLayers/Control/Snapping.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Measure │ │ │ │ │ - * Allows for drawing of features for measurements. │ │ │ │ │ + * Class: OpenLayers.Control.Snapping │ │ │ │ │ + * Acts as a snapping agent while editing vector features. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ * 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) │ │ │ │ │ * │ │ │ │ │ * Supported event types (in addition to those from ): │ │ │ │ │ - * measure - Triggered when a measurement sketch is complete. Listeners │ │ │ │ │ - * will receive an event with measure, units, order, and geometry │ │ │ │ │ - * properties. │ │ │ │ │ - * measurepartial - Triggered when a new point is added to the │ │ │ │ │ - * measurement sketch or if the property is true and the │ │ │ │ │ - * measurement sketch is modified. Listeners receive an event with measure, │ │ │ │ │ - * units, order, and geometry. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * beforesnap - Triggered before a snap occurs. Listeners receive an │ │ │ │ │ + * event object with *point*, *x*, *y*, *distance*, *layer*, and │ │ │ │ │ + * *snapType* properties. The point property will be original point │ │ │ │ │ + * geometry considered for snapping. The x and y properties represent │ │ │ │ │ + * coordinates the point will receive. The distance is the distance │ │ │ │ │ + * of the snap. The layer is the target layer. The snapType property │ │ │ │ │ + * will be one of "node", "vertex", or "edge". Return false to stop │ │ │ │ │ + * snapping from occurring. │ │ │ │ │ + * snap - Triggered when a snap occurs. Listeners receive an event with │ │ │ │ │ + * *point*, *snapType*, *layer*, and *distance* properties. The point │ │ │ │ │ + * will be the location snapped to. The snapType will be one of "node", │ │ │ │ │ + * "vertex", or "edge". The layer will be the target layer. The │ │ │ │ │ + * distance will be the distance of the snap in map units. │ │ │ │ │ + * unsnap - Triggered when a vertex is unsnapped. Listeners receive an │ │ │ │ │ + * event with a *point* property. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ + * CONSTANT: DEFAULTS │ │ │ │ │ + * Default target properties. │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + DEFAULTS: { │ │ │ │ │ + tolerance: 10, │ │ │ │ │ + node: true, │ │ │ │ │ + edge: true, │ │ │ │ │ + vertex: true │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displaySystem │ │ │ │ │ - * {String} Display system for output measurements. Supported values │ │ │ │ │ - * are 'english', 'metric', and 'geographic'. Default is 'metric'. │ │ │ │ │ + * Property: greedy │ │ │ │ │ + * {Boolean} Snap to closest feature in first layer with an eligible │ │ │ │ │ + * feature. Default is true. │ │ │ │ │ */ │ │ │ │ │ - displaySystem: 'metric', │ │ │ │ │ + greedy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Calculate geodesic metrics instead of planar metrics. This │ │ │ │ │ - * requires that geometries can be transformed into Geographic/WGS84 │ │ │ │ │ - * (if that is not already the map projection). Default is false. │ │ │ │ │ + * Property: precedence │ │ │ │ │ + * {Array} List representing precedence of different snapping types. │ │ │ │ │ + * Default is "node", "vertex", "edge". │ │ │ │ │ */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ + precedence: ["node", "vertex", "edge"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: displaySystemUnits │ │ │ │ │ - * {Object} Units for various measurement systems. Values are arrays │ │ │ │ │ - * of unit abbreviations (from OpenLayers.INCHES_PER_UNIT) in decreasing │ │ │ │ │ - * order of length. │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} The map resolution for the previously considered snap. │ │ │ │ │ */ │ │ │ │ │ - displaySystemUnits: { │ │ │ │ │ - geographic: ['dd'], │ │ │ │ │ - english: ['mi', 'ft', 'in'], │ │ │ │ │ - metric: ['km', 'm'] │ │ │ │ │ - }, │ │ │ │ │ + resolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delay │ │ │ │ │ - * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ - * considered a double-click. The "measurepartial" event will not │ │ │ │ │ - * be triggered if the sketch is completed within this time. This │ │ │ │ │ - * is required for IE where creating a browser reflow (if a listener │ │ │ │ │ - * is modifying the DOM by displaying the measurement values) messes │ │ │ │ │ - * with the dblclick listener in the sketch handler. │ │ │ │ │ + * Property: geoToleranceCache │ │ │ │ │ + * {Object} A cache of geo-tolerances. Tolerance values (in map units) are │ │ │ │ │ + * calculated when the map resolution changes. │ │ │ │ │ */ │ │ │ │ │ - partialDelay: 300, │ │ │ │ │ + geoToleranceCache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delayedTrigger │ │ │ │ │ - * {Number} Timeout id of trigger for measurepartial. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The current editable layer. Set at │ │ │ │ │ + * construction or after construction with . │ │ │ │ │ */ │ │ │ │ │ - delayedTrigger: null, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Keep the temporary measurement sketch drawn after the │ │ │ │ │ - * measurement is complete. The geometry will persist until a new │ │ │ │ │ - * measurement is started, the control is deactivated, or is │ │ │ │ │ - * called. │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} The current editable feature. │ │ │ │ │ */ │ │ │ │ │ - persist: false, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: immediate │ │ │ │ │ - * {Boolean} Activates the immediate measurement so that the "measurepartial" │ │ │ │ │ - * event is also fired once the measurement sketch is modified. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: point │ │ │ │ │ + * {} The currently snapped vertex. │ │ │ │ │ */ │ │ │ │ │ - immediate: false, │ │ │ │ │ + point: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Measure │ │ │ │ │ + * Constructor: OpenLayers.Control.Snapping │ │ │ │ │ + * Creates a new snapping control. A control is constructed with an editable │ │ │ │ │ + * layer and a set of configuration objects for target layers. While the │ │ │ │ │ + * control is active, dragging vertices while drawing new features or │ │ │ │ │ + * modifying existing features on the editable layer will engage │ │ │ │ │ + * snapping to features on the target layers. Whether a vertex snaps to │ │ │ │ │ + * a feature on a target layer depends on the target layer configuration. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * handler - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * options - {Object} An object containing all configuration properties for │ │ │ │ │ + * the control. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * layer - {} The editable layer. Features from this │ │ │ │ │ + * layer that are digitized or modified may have vertices snapped to │ │ │ │ │ + * features from any of the target layers. │ │ │ │ │ + * targets - {Array(Object | OpenLayers.Layer.Vector)} A list of objects for │ │ │ │ │ + * configuring target layers. See valid properties of the target │ │ │ │ │ + * objects below. If the items in the targets list are vector layers │ │ │ │ │ + * (instead of configuration objects), the defaults from the │ │ │ │ │ + * property will apply. The editable layer itself may be a target │ │ │ │ │ + * layer, allowing newly created or edited features to be snapped to │ │ │ │ │ + * existing features from the same layer. If no targets are provided │ │ │ │ │ + * the layer given in the constructor (as ) will become the │ │ │ │ │ + * initial target. │ │ │ │ │ + * defaults - {Object} An object with default properties to be applied │ │ │ │ │ + * to all target objects. │ │ │ │ │ + * greedy - {Boolean} Snap to closest feature in first target layer that │ │ │ │ │ + * applies. Default is true. If false, all features in all target │ │ │ │ │ + * layers will be checked and the closest feature in all target layers │ │ │ │ │ + * will be chosen. The greedy property determines if the order of the │ │ │ │ │ + * target layers is significant. By default, the order of the target │ │ │ │ │ + * layers is significant where layers earlier in the target layer list │ │ │ │ │ + * have precedence over layers later in the list. Within a single │ │ │ │ │ + * layer, the closest feature is always chosen for snapping. This │ │ │ │ │ + * property only determines whether the search for a closer feature │ │ │ │ │ + * continues after an eligible feature is found in a target layer. │ │ │ │ │ + * │ │ │ │ │ + * Valid target properties: │ │ │ │ │ + * layer - {} A target layer. Features from this │ │ │ │ │ + * layer will be eligible to act as snapping target for the editable │ │ │ │ │ + * layer. │ │ │ │ │ + * tolerance - {Float} The distance (in pixels) at which snapping may occur. │ │ │ │ │ + * Default is 10. │ │ │ │ │ + * node - {Boolean} Snap to nodes (first or last point in a geometry) in │ │ │ │ │ + * target layer. Default is true. │ │ │ │ │ + * nodeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for nodes specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * vertex - {Boolean} Snap to vertices in target layer. Default is true. │ │ │ │ │ + * vertexTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for vertices specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * edge - {Boolean} Snap to edges in target layer. Default is true. │ │ │ │ │ + * edgeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for edges specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * filter - {} Optional filter to evaluate to determine if │ │ │ │ │ + * feature is eligible for snapping. If filter evaluates to true for a │ │ │ │ │ + * target feature a vertex may be snapped to the feature. │ │ │ │ │ + * minResolution - {Number} If a minResolution is provided, snapping to this │ │ │ │ │ + * target will only be considered if the map resolution is greater than │ │ │ │ │ + * or equal to this value (the minResolution is inclusive). Default is │ │ │ │ │ + * no minimum resolution limit. │ │ │ │ │ + * maxResolution - {Number} If a maxResolution is provided, snapping to this │ │ │ │ │ + * target will only be considered if the map resolution is strictly │ │ │ │ │ + * less than this value (the maxResolution is exclusive). Default is │ │ │ │ │ + * no maximum resolution limit. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(handler, options) { │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - var callbacks = { │ │ │ │ │ - done: this.measureComplete, │ │ │ │ │ - point: this.measurePartial │ │ │ │ │ - }; │ │ │ │ │ - if (this.immediate) { │ │ │ │ │ - callbacks.modify = this.measureImmediate; │ │ │ │ │ - } │ │ │ │ │ - this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); │ │ │ │ │ + this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ │ │ │ │ │ - // let the handler options override, so old code that passes 'persist' │ │ │ │ │ - // directly to the handler does not need an update │ │ │ │ │ - this.handlerOptions = OpenLayers.Util.extend({ │ │ │ │ │ - persist: this.persist │ │ │ │ │ - }, this.handlerOptions); │ │ │ │ │ - this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ - }, │ │ │ │ │ + // set the editable layer if provided │ │ │ │ │ + if (this.options.layer) { │ │ │ │ │ + this.setLayer(this.options.layer); │ │ │ │ │ + } │ │ │ │ │ + // configure target layers │ │ │ │ │ + var defaults = OpenLayers.Util.extend({}, this.options.defaults); │ │ │ │ │ + this.defaults = OpenLayers.Util.applyDefaults(defaults, this.DEFAULTS); │ │ │ │ │ + this.setTargets(this.options.targets); │ │ │ │ │ + if (this.targets.length === 0 && this.layer) { │ │ │ │ │ + this.addTargetLayer(this.layer); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + this.geoToleranceCache = {}; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Stop the control from measuring. If is true, the temporary │ │ │ │ │ - * sketch will be erased. │ │ │ │ │ + * APIMethod: setLayer │ │ │ │ │ + * Set the editable layer. Call the setLayer method if the editable layer │ │ │ │ │ + * changes and the same control should be used on a new editable layer. │ │ │ │ │ + * If the control is already active, it will be active after the new │ │ │ │ │ + * layer is set. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} The new editable layer. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.handler.cancel(); │ │ │ │ │ + setLayer: function(layer) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.activate(); │ │ │ │ │ + } else { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setImmediate │ │ │ │ │ - * Sets the property. Changes the activity of immediate │ │ │ │ │ - * measurement. │ │ │ │ │ + * Method: setTargets │ │ │ │ │ + * Set the targets for the snapping agent. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * targets - {Array} An array of target configs or target layers. │ │ │ │ │ */ │ │ │ │ │ - setImmediate: function(immediate) { │ │ │ │ │ - this.immediate = immediate; │ │ │ │ │ - if (this.immediate) { │ │ │ │ │ - this.callbacks.modify = this.measureImmediate; │ │ │ │ │ - } else { │ │ │ │ │ - delete this.callbacks.modify; │ │ │ │ │ + setTargets: function(targets) { │ │ │ │ │ + this.targets = []; │ │ │ │ │ + if (targets && targets.length) { │ │ │ │ │ + var target; │ │ │ │ │ + for (var i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ + target = targets[i]; │ │ │ │ │ + if (target instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ + this.addTargetLayer(target); │ │ │ │ │ + } else { │ │ │ │ │ + this.addTarget(target); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateHandler │ │ │ │ │ + * Method: addTargetLayer │ │ │ │ │ + * Add a target layer with the default target config. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * handler - {Function} One of the sketch handler constructors. │ │ │ │ │ - * options - {Object} Options for the handler. │ │ │ │ │ + * layer - {} A target layer. │ │ │ │ │ */ │ │ │ │ │ - updateHandler: function(handler, options) { │ │ │ │ │ - var active = this.active; │ │ │ │ │ - if (active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - this.handler = new handler(this, this.callbacks, options); │ │ │ │ │ - if (active) { │ │ │ │ │ - this.activate(); │ │ │ │ │ - } │ │ │ │ │ + addTargetLayer: function(layer) { │ │ │ │ │ + this.addTarget({ │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measureComplete │ │ │ │ │ - * Called when the measurement sketch is done. │ │ │ │ │ + * Method: addTarget │ │ │ │ │ + * Add a configured target layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ + * target - {Object} A target config. │ │ │ │ │ */ │ │ │ │ │ - measureComplete: function(geometry) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.measure(geometry, "measure"); │ │ │ │ │ + addTarget: function(target) { │ │ │ │ │ + target = OpenLayers.Util.applyDefaults(target, this.defaults); │ │ │ │ │ + target.nodeTolerance = target.nodeTolerance || target.tolerance; │ │ │ │ │ + target.vertexTolerance = target.vertexTolerance || target.tolerance; │ │ │ │ │ + target.edgeTolerance = target.edgeTolerance || target.tolerance; │ │ │ │ │ + this.targets.push(target); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measurePartial │ │ │ │ │ - * Called each time a new point is added to the measurement sketch. │ │ │ │ │ + * Method: removeTargetLayer │ │ │ │ │ + * Remove a target layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * point - {} The last point added. │ │ │ │ │ - * geometry - {} The sketch geometry. │ │ │ │ │ + * layer - {} The target layer to remove. │ │ │ │ │ */ │ │ │ │ │ - measurePartial: function(point, geometry) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - geometry = geometry.clone(); │ │ │ │ │ - // when we're wating for a dblclick, we have to trigger measurepartial │ │ │ │ │ - // after some delay to deal with reflow issues in IE │ │ │ │ │ - if (this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ - // no dblclick in freehand mode │ │ │ │ │ - this.measure(geometry, "measurepartial"); │ │ │ │ │ - } else { │ │ │ │ │ - this.delayedTrigger = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.delayedTrigger = null; │ │ │ │ │ - this.measure(geometry, "measurepartial"); │ │ │ │ │ - }, this), │ │ │ │ │ - this.partialDelay │ │ │ │ │ - ); │ │ │ │ │ + removeTargetLayer: function(layer) { │ │ │ │ │ + var target; │ │ │ │ │ + for (var i = this.targets.length - 1; i >= 0; --i) { │ │ │ │ │ + target = this.targets[i]; │ │ │ │ │ + if (target.layer === layer) { │ │ │ │ │ + this.removeTarget(target); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measureImmediate │ │ │ │ │ - * Called each time the measurement sketch is modified. │ │ │ │ │ + * Method: removeTarget │ │ │ │ │ + * Remove a target. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * point - {} The point at the mouse position. │ │ │ │ │ - * feature - {} The sketch feature. │ │ │ │ │ - * drawing - {Boolean} Indicates whether we're currently drawing. │ │ │ │ │ + * target - {Object} A target config. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} The targets array. │ │ │ │ │ */ │ │ │ │ │ - measureImmediate: function(point, feature, drawing) { │ │ │ │ │ - if (drawing && !this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.measure(feature.geometry, "measurepartial"); │ │ │ │ │ - } │ │ │ │ │ + removeTarget: function(target) { │ │ │ │ │ + return OpenLayers.Util.removeItem(this.targets, target); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelDelay │ │ │ │ │ - * Cancels the delay measurement that measurePartial began. │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. Activating the control registers listeners for │ │ │ │ │ + * editing related events so that during feature creation and │ │ │ │ │ + * modification, moving vertices will trigger snapping. │ │ │ │ │ */ │ │ │ │ │ - cancelDelay: function() { │ │ │ │ │ - if (this.delayedTrigger !== null) { │ │ │ │ │ - window.clearTimeout(this.delayedTrigger); │ │ │ │ │ - this.delayedTrigger = null; │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ + if (activated) { │ │ │ │ │ + if (this.layer && this.layer.events) { │ │ │ │ │ + this.layer.events.on({ │ │ │ │ │ + sketchstarted: this.onSketchModified, │ │ │ │ │ + sketchmodified: this.onSketchModified, │ │ │ │ │ + vertexmodified: this.onVertexModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measure │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * eventType - {String} │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ + * so feature editing may proceed without engaging the snapping agent. │ │ │ │ │ */ │ │ │ │ │ - measure: function(geometry, eventType) { │ │ │ │ │ - var stat, order; │ │ │ │ │ - if (geometry.CLASS_NAME.indexOf('LineString') > -1) { │ │ │ │ │ - stat = this.getBestLength(geometry); │ │ │ │ │ - order = 1; │ │ │ │ │ - } else { │ │ │ │ │ - stat = this.getBestArea(geometry); │ │ │ │ │ - order = 2; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ + if (deactivated) { │ │ │ │ │ + if (this.layer && this.layer.events) { │ │ │ │ │ + this.layer.events.un({ │ │ │ │ │ + sketchstarted: this.onSketchModified, │ │ │ │ │ + sketchmodified: this.onSketchModified, │ │ │ │ │ + vertexmodified: this.onVertexModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent(eventType, { │ │ │ │ │ - measure: stat[0], │ │ │ │ │ - units: stat[1], │ │ │ │ │ - order: order, │ │ │ │ │ - geometry: geometry │ │ │ │ │ - }); │ │ │ │ │ + this.feature = null; │ │ │ │ │ + this.point = null; │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getBestArea │ │ │ │ │ - * Based on the returns the area of a geometry. │ │ │ │ │ + * Method: onSketchModified │ │ │ │ │ + * Registered as a listener for the sketchmodified event on the editable │ │ │ │ │ + * layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ - * area and the units abbreviation. │ │ │ │ │ + * event - {Object} The sketch modified event. │ │ │ │ │ */ │ │ │ │ │ - getBestArea: function(geometry) { │ │ │ │ │ - var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ - var unit, area; │ │ │ │ │ - for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ - unit = units[i]; │ │ │ │ │ - area = this.getArea(geometry, unit); │ │ │ │ │ - if (area > 1) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return [area, unit]; │ │ │ │ │ + onSketchModified: function(event) { │ │ │ │ │ + this.feature = event.feature; │ │ │ │ │ + this.considerSnapping(event.vertex, event.vertex); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getArea │ │ │ │ │ + * Method: onVertexModified │ │ │ │ │ + * Registered as a listener for the vertexmodified event on the editable │ │ │ │ │ + * layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * units - {String} Unit abbreviation │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The geometry area in the given units. │ │ │ │ │ + * event - {Object} The vertex modified event. │ │ │ │ │ */ │ │ │ │ │ - getArea: function(geometry, units) { │ │ │ │ │ - var area, geomUnits; │ │ │ │ │ - if (this.geodesic) { │ │ │ │ │ - area = geometry.getGeodesicArea(this.map.getProjectionObject()); │ │ │ │ │ - geomUnits = "m"; │ │ │ │ │ - } else { │ │ │ │ │ - area = geometry.getArea(); │ │ │ │ │ - geomUnits = this.map.getUnits(); │ │ │ │ │ - } │ │ │ │ │ - var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ - if (inPerDisplayUnit) { │ │ │ │ │ - var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ - area *= Math.pow((inPerMapUnit / inPerDisplayUnit), 2); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ + onVertexModified: function(event) { │ │ │ │ │ + this.feature = event.feature; │ │ │ │ │ + var loc = this.layer.map.getLonLatFromViewPortPx(event.pixel); │ │ │ │ │ + this.considerSnapping( │ │ │ │ │ + event.vertex, new OpenLayers.Geometry.Point(loc.lon, loc.lat) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getBestLength │ │ │ │ │ - * Based on the returns the length of a geometry. │ │ │ │ │ + * Method: considerSnapping │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ - * length and the units abbreviation. │ │ │ │ │ + * point - {} The vertex to be snapped (or │ │ │ │ │ + * unsnapped). │ │ │ │ │ + * loc - {} The location of the mouse in map │ │ │ │ │ + * coords. │ │ │ │ │ */ │ │ │ │ │ - getBestLength: function(geometry) { │ │ │ │ │ - var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ - var unit, length; │ │ │ │ │ - for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ - unit = units[i]; │ │ │ │ │ - length = this.getLength(geometry, unit); │ │ │ │ │ - if (length > 1) { │ │ │ │ │ - break; │ │ │ │ │ + considerSnapping: function(point, loc) { │ │ │ │ │ + var best = { │ │ │ │ │ + rank: Number.POSITIVE_INFINITY, │ │ │ │ │ + dist: Number.POSITIVE_INFINITY, │ │ │ │ │ + x: null, │ │ │ │ │ + y: null │ │ │ │ │ + }; │ │ │ │ │ + var snapped = false; │ │ │ │ │ + var result, target; │ │ │ │ │ + for (var i = 0, len = this.targets.length; i < len; ++i) { │ │ │ │ │ + target = this.targets[i]; │ │ │ │ │ + result = this.testTarget(target, loc); │ │ │ │ │ + if (result) { │ │ │ │ │ + if (this.greedy) { │ │ │ │ │ + best = result; │ │ │ │ │ + best.target = target; │ │ │ │ │ + snapped = true; │ │ │ │ │ + break; │ │ │ │ │ + } else { │ │ │ │ │ + if ((result.rank < best.rank) || │ │ │ │ │ + (result.rank === best.rank && result.dist < best.dist)) { │ │ │ │ │ + best = result; │ │ │ │ │ + best.target = target; │ │ │ │ │ + snapped = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return [length, unit]; │ │ │ │ │ + if (snapped) { │ │ │ │ │ + var proceed = this.events.triggerEvent("beforesnap", { │ │ │ │ │ + point: point, │ │ │ │ │ + x: best.x, │ │ │ │ │ + y: best.y, │ │ │ │ │ + distance: best.dist, │ │ │ │ │ + layer: best.target.layer, │ │ │ │ │ + snapType: this.precedence[best.rank] │ │ │ │ │ + }); │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + point.x = best.x; │ │ │ │ │ + point.y = best.y; │ │ │ │ │ + this.point = point; │ │ │ │ │ + this.events.triggerEvent("snap", { │ │ │ │ │ + point: point, │ │ │ │ │ + snapType: this.precedence[best.rank], │ │ │ │ │ + layer: best.target.layer, │ │ │ │ │ + distance: best.dist │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + snapped = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.point && !snapped) { │ │ │ │ │ + point.x = loc.x; │ │ │ │ │ + point.y = loc.y; │ │ │ │ │ + this.point = null; │ │ │ │ │ + this.events.triggerEvent("unsnap", { │ │ │ │ │ + point: point │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLength │ │ │ │ │ + * Method: testTarget │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * units - {String} Unit abbreviation │ │ │ │ │ + * target - {Object} Object with target layer configuration. │ │ │ │ │ + * loc - {} The location of the mouse in map │ │ │ │ │ + * coords. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The geometry length in the given units. │ │ │ │ │ + * {Object} A result object with rank, dist, x, and y properties. │ │ │ │ │ + * Returns null if candidate is not eligible for snapping. │ │ │ │ │ */ │ │ │ │ │ - getLength: function(geometry, units) { │ │ │ │ │ - var length, geomUnits; │ │ │ │ │ - if (this.geodesic) { │ │ │ │ │ - length = geometry.getGeodesicLength(this.map.getProjectionObject()); │ │ │ │ │ - geomUnits = "m"; │ │ │ │ │ - } else { │ │ │ │ │ - length = geometry.getLength(); │ │ │ │ │ - geomUnits = this.map.getUnits(); │ │ │ │ │ + testTarget: function(target, loc) { │ │ │ │ │ + var resolution = this.layer.map.getResolution(); │ │ │ │ │ + if ("minResolution" in target) { │ │ │ │ │ + if (resolution < target.minResolution) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ - if (inPerDisplayUnit) { │ │ │ │ │ - var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ - length *= (inPerMapUnit / inPerDisplayUnit); │ │ │ │ │ + if ("maxResolution" in target) { │ │ │ │ │ + if (resolution >= target.maxResolution) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Measure" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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. │ │ │ │ │ - */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ - * Returns a new keyboard handler. │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ + var tolerance = { │ │ │ │ │ + node: this.getGeoTolerance(target.nodeTolerance, resolution), │ │ │ │ │ + vertex: this.getGeoTolerance(target.vertexTolerance, resolution), │ │ │ │ │ + edge: this.getGeoTolerance(target.edgeTolerance, resolution) │ │ │ │ │ + }; │ │ │ │ │ + // this could be cached if we don't support setting tolerance values directly │ │ │ │ │ + var maxTolerance = Math.max( │ │ │ │ │ + tolerance.node, tolerance.vertex, tolerance.edge │ │ │ │ │ ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.eventListener = null; │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ + var result = { │ │ │ │ │ + rank: Number.POSITIVE_INFINITY, │ │ │ │ │ + dist: Number.POSITIVE_INFINITY │ │ │ │ │ + }; │ │ │ │ │ + var eligible = false; │ │ │ │ │ + var features = target.layer.features; │ │ │ │ │ + var feature, type, vertices, vertex, closest, dist, found; │ │ │ │ │ + var numTypes = this.precedence.length; │ │ │ │ │ + var ll = new OpenLayers.LonLat(loc.x, loc.y); │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + if (feature !== this.feature && !feature._sketch && │ │ │ │ │ + feature.state !== OpenLayers.State.DELETE && │ │ │ │ │ + (!target.filter || target.filter.evaluate(feature))) { │ │ │ │ │ + if (feature.atPoint(ll, maxTolerance, maxTolerance)) { │ │ │ │ │ + for (var j = 0, stop = Math.min(result.rank + 1, numTypes); j < stop; ++j) { │ │ │ │ │ + type = this.precedence[j]; │ │ │ │ │ + if (target[type]) { │ │ │ │ │ + if (type === "edge") { │ │ │ │ │ + closest = feature.geometry.distanceTo(loc, { │ │ │ │ │ + details: true │ │ │ │ │ + }); │ │ │ │ │ + dist = closest.distance; │ │ │ │ │ + if (dist <= tolerance[type] && dist < result.dist) { │ │ │ │ │ + result = { │ │ │ │ │ + rank: j, │ │ │ │ │ + dist: dist, │ │ │ │ │ + x: closest.x0, │ │ │ │ │ + y: closest.y0 // closest coords on feature │ │ │ │ │ + }; │ │ │ │ │ + eligible = true; │ │ │ │ │ + // don't look for lower precedence types for this feature │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // look for nodes or vertices │ │ │ │ │ + vertices = feature.geometry.getVertices(type === "node"); │ │ │ │ │ + found = false; │ │ │ │ │ + for (var k = 0, klen = vertices.length; k < klen; ++k) { │ │ │ │ │ + vertex = vertices[k]; │ │ │ │ │ + dist = vertex.distanceTo(loc); │ │ │ │ │ + if (dist <= tolerance[type] && │ │ │ │ │ + (j < result.rank || (j === result.rank && dist < result.dist))) { │ │ │ │ │ + result = { │ │ │ │ │ + rank: j, │ │ │ │ │ + dist: dist, │ │ │ │ │ + x: vertex.x, │ │ │ │ │ + y: vertex.y │ │ │ │ │ + }; │ │ │ │ │ + eligible = true; │ │ │ │ │ + found = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (found) { │ │ │ │ │ + // don't look for lower precedence types for this feature │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ } │ │ │ │ │ + return eligible ? result : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: getGeoTolerance │ │ │ │ │ + * Calculate a tolerance in map units given a tolerance in pixels. This │ │ │ │ │ + * takes advantage of the when the map resolution │ │ │ │ │ + * has not changed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * tolerance - {Number} A tolerance value in pixels. │ │ │ │ │ + * resolution - {Number} Map resolution. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} A tolerance value in map units. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getGeoTolerance: function(tolerance, resolution) { │ │ │ │ │ + if (resolution !== this.resolution) { │ │ │ │ │ + this.resolution = resolution; │ │ │ │ │ + this.geoToleranceCache = {}; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + var geoTolerance = this.geoToleranceCache[tolerance]; │ │ │ │ │ + if (geoTolerance === undefined) { │ │ │ │ │ + geoTolerance = tolerance * resolution; │ │ │ │ │ + this.geoToleranceCache[tolerance] = geoTolerance; │ │ │ │ │ + } │ │ │ │ │ + return geoTolerance; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleKeyEvent │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Clean up the control. │ │ │ │ │ */ │ │ │ │ │ - handleKeyEvent: function(evt) { │ │ │ │ │ - if (this.checkModifiers(evt)) { │ │ │ │ │ - this.callback(evt.type, [evt]); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ } │ │ │ │ │ + delete this.layer; │ │ │ │ │ + delete this.targets; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Keyboard" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Snapping" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ModifyFeature.js │ │ │ │ │ + OpenLayers/Control/ArgParser.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ModifyFeature │ │ │ │ │ - * Control to modify features. When activated, a click renders the vertices │ │ │ │ │ - * of a feature - these vertices can then be dragged. By default, the │ │ │ │ │ - * delete key will delete the vertex under the mouse. New features are │ │ │ │ │ - * added by dragging "virtual vertices" between vertices. Create a new │ │ │ │ │ - * control with the constructor. │ │ │ │ │ + * Class: OpenLayers.Control.ArgParser │ │ │ │ │ + * The ArgParser control adds location bar query string parsing functionality │ │ │ │ │ + * to an OpenLayers Map. │ │ │ │ │ + * When added to a Map control, on a page load/refresh, the Map will │ │ │ │ │ + * automatically take the href string and parse it for lon, lat, zoom, and │ │ │ │ │ + * layers information. │ │ │ │ │ * │ │ │ │ │ - * Inherits From: │ │ │ │ │ + * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, dragging vertices will continue even if the │ │ │ │ │ - * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ + * Property: center │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + center: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geometryTypes │ │ │ │ │ - * {Array(String)} To restrict modification to a limited set of geometry │ │ │ │ │ - * types, send a list of strings corresponding to the geometry class │ │ │ │ │ - * names. │ │ │ │ │ + * Property: zoom │ │ │ │ │ + * {int} │ │ │ │ │ */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ + zoom: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickout │ │ │ │ │ - * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ - * Default is true. │ │ │ │ │ + * Property: layers │ │ │ │ │ + * {String} Each character represents the state of the corresponding layer │ │ │ │ │ + * on the map. │ │ │ │ │ */ │ │ │ │ │ - clickout: true, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: toggle │ │ │ │ │ - * {Boolean} Unselect a selected feature on click. │ │ │ │ │ - * Default is true. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayProjection │ │ │ │ │ + * {} Requires proj4js support. │ │ │ │ │ + * Projection used when reading the coordinates from the URL. This will │ │ │ │ │ + * reproject the map coordinates from the URL into the map's │ │ │ │ │ + * projection. │ │ │ │ │ + * │ │ │ │ │ + * If you are using this functionality, be aware that any permalink │ │ │ │ │ + * which is added to the map will determine the coordinate type which │ │ │ │ │ + * is read from the URL, which means you should not add permalinks with │ │ │ │ │ + * different displayProjections to the same map. │ │ │ │ │ */ │ │ │ │ │ - toggle: true, │ │ │ │ │ + displayProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: standalone │ │ │ │ │ - * {Boolean} Set to true to create a control without SelectFeature │ │ │ │ │ - * capabilities. Default is false. If standalone is true, to modify │ │ │ │ │ - * a feature, call the method with the target feature. │ │ │ │ │ - * Note that you must call the method to finish │ │ │ │ │ - * feature modification in standalone mode (before starting to modify │ │ │ │ │ - * another feature). │ │ │ │ │ + * Constructor: OpenLayers.Control.ArgParser │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - standalone: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ + * Method: getParameters │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + getParameters: function(url) { │ │ │ │ │ + url = url || window.location.href; │ │ │ │ │ + var parameters = OpenLayers.Util.getParameters(url); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} Feature currently available for modification. │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ + // If we have an anchor in the url use it to split the url │ │ │ │ │ + var index = url.indexOf('#'); │ │ │ │ │ + if (index > 0) { │ │ │ │ │ + // create an url to parse on the getParameters │ │ │ │ │ + url = '?' + url.substring(index + 1, url.length); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: vertex │ │ │ │ │ - * {} Vertex currently being modified. │ │ │ │ │ - */ │ │ │ │ │ - vertex: null, │ │ │ │ │ + OpenLayers.Util.extend(parameters, │ │ │ │ │ + OpenLayers.Util.getParameters(url)); │ │ │ │ │ + } │ │ │ │ │ + return parameters; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: vertices │ │ │ │ │ - * {Array()} Verticies currently available │ │ │ │ │ - * for dragging. │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - vertices: null, │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: virtualVertices │ │ │ │ │ - * {Array()} Virtual vertices in the middle │ │ │ │ │ - * of each edge. │ │ │ │ │ - */ │ │ │ │ │ - virtualVertices: null, │ │ │ │ │ + //make sure we dont already have an arg parser attached │ │ │ │ │ + for (var i = 0, len = this.map.controls.length; i < len; i++) { │ │ │ │ │ + var control = this.map.controls[i]; │ │ │ │ │ + if ((control != this) && │ │ │ │ │ + (control.CLASS_NAME == "OpenLayers.Control.ArgParser")) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - handlers: null, │ │ │ │ │ + // If a second argparser is added to the map, then we │ │ │ │ │ + // override the displayProjection to be the one added to the │ │ │ │ │ + // map. │ │ │ │ │ + if (control.displayProjection != this.displayProjection) { │ │ │ │ │ + this.displayProjection = control.displayProjection; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: deleteCodes │ │ │ │ │ - * {Array(Integer)} Keycodes for deleting verticies. Set to null to disable │ │ │ │ │ - * vertex deltion by keypress. If non-null, keypresses with codes │ │ │ │ │ - * in this array will delete vertices under the mouse. Default │ │ │ │ │ - * is 46 and 68, the 'delete' and lowercase 'd' keys. │ │ │ │ │ - */ │ │ │ │ │ - deleteCodes: null, │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (i == this.map.controls.length) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: virtualStyle │ │ │ │ │ - * {Object} A symbolizer to be used for virtual vertices. │ │ │ │ │ - */ │ │ │ │ │ - virtualStyle: null, │ │ │ │ │ + var args = this.getParameters(); │ │ │ │ │ + // Be careful to set layer first, to not trigger unnecessary layer loads │ │ │ │ │ + if (args.layers) { │ │ │ │ │ + this.layers = args.layers; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: vertexRenderIntent │ │ │ │ │ - * {String} The renderIntent to use for vertices. If no is │ │ │ │ │ - * provided, this renderIntent will also be used for virtual vertices, with │ │ │ │ │ - * a fillOpacity and strokeOpacity of 0.3. Default is null, which means │ │ │ │ │ - * that the layer's default style will be used for vertices. │ │ │ │ │ - */ │ │ │ │ │ - vertexRenderIntent: null, │ │ │ │ │ + // when we add a new layer, set its visibility │ │ │ │ │ + this.map.events.register('addlayer', this, │ │ │ │ │ + this.configureLayers); │ │ │ │ │ + this.configureLayers(); │ │ │ │ │ + } │ │ │ │ │ + if (args.lat && args.lon) { │ │ │ │ │ + this.center = new OpenLayers.LonLat(parseFloat(args.lon), │ │ │ │ │ + parseFloat(args.lat)); │ │ │ │ │ + if (args.zoom) { │ │ │ │ │ + this.zoom = parseFloat(args.zoom); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: mode │ │ │ │ │ - * {Integer} Bitfields specifying the modification mode. Defaults to │ │ │ │ │ - * OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a │ │ │ │ │ - * combination of options, use the | operator. For example, to allow │ │ │ │ │ - * the control to both resize and rotate features, use the following │ │ │ │ │ - * syntax │ │ │ │ │ - * (code) │ │ │ │ │ - * control.mode = OpenLayers.Control.ModifyFeature.RESIZE | │ │ │ │ │ - * OpenLayers.Control.ModifyFeature.ROTATE; │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ - mode: null, │ │ │ │ │ + // when we add a new baselayer to see when we can set the center │ │ │ │ │ + this.map.events.register('changebaselayer', this, │ │ │ │ │ + this.setCenter); │ │ │ │ │ + this.setCenter(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: createVertices │ │ │ │ │ - * {Boolean} Create new vertices by dragging the virtual vertices │ │ │ │ │ - * in the middle of each edge. Default is true. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setCenter │ │ │ │ │ + * As soon as a baseLayer has been loaded, we center and zoom │ │ │ │ │ + * ...and remove the handler. │ │ │ │ │ */ │ │ │ │ │ - createVertices: true, │ │ │ │ │ + setCenter: function() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: modified │ │ │ │ │ - * {Boolean} The currently selected feature has been modified. │ │ │ │ │ - */ │ │ │ │ │ - modified: false, │ │ │ │ │ + if (this.map.baseLayer) { │ │ │ │ │ + //dont need to listen for this one anymore │ │ │ │ │ + this.map.events.unregister('changebaselayer', this, │ │ │ │ │ + this.setCenter); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: radiusHandle │ │ │ │ │ - * {} A handle for rotating/resizing a feature. │ │ │ │ │ - */ │ │ │ │ │ - radiusHandle: null, │ │ │ │ │ + if (this.displayProjection) { │ │ │ │ │ + this.center.transform(this.displayProjection, │ │ │ │ │ + this.map.getProjectionObject()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragHandle │ │ │ │ │ - * {} A handle for dragging a feature. │ │ │ │ │ - */ │ │ │ │ │ - dragHandle: null, │ │ │ │ │ + this.map.setCenter(this.center, this.zoom); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onModificationStart │ │ │ │ │ - * {Function} *Deprecated*. Register for "beforefeaturemodified" instead. │ │ │ │ │ - * The "beforefeaturemodified" event is triggered on the layer before │ │ │ │ │ - * any modification begins. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature is selected │ │ │ │ │ - * to be modified. The function should expect to be called with a │ │ │ │ │ - * feature. This could be used for example to allow to lock the │ │ │ │ │ - * feature on server-side. │ │ │ │ │ + /** │ │ │ │ │ + * Method: configureLayers │ │ │ │ │ + * As soon as all the layers are loaded, cycle through them and │ │ │ │ │ + * hide or show them. │ │ │ │ │ */ │ │ │ │ │ - onModificationStart: function() {}, │ │ │ │ │ + configureLayers: function() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onModification │ │ │ │ │ - * {Function} *Deprecated*. Register for "featuremodified" instead. │ │ │ │ │ - * The "featuremodified" event is triggered on the layer with each │ │ │ │ │ - * feature modification. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature has been │ │ │ │ │ - * modified. The function should expect to be called with a feature. │ │ │ │ │ - */ │ │ │ │ │ - onModification: function() {}, │ │ │ │ │ + if (this.layers.length == this.map.layers.length) { │ │ │ │ │ + this.map.events.unregister('addlayer', this, this.configureLayers); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onModificationEnd │ │ │ │ │ - * {Function} *Deprecated*. Register for "afterfeaturemodified" instead. │ │ │ │ │ - * The "afterfeaturemodified" event is triggered on the layer after │ │ │ │ │ - * a feature has been modified. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature is finished │ │ │ │ │ - * being modified. The function should expect to be called with a │ │ │ │ │ - * feature. │ │ │ │ │ - */ │ │ │ │ │ - onModificationEnd: function() {}, │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ModifyFeature │ │ │ │ │ - * Create a new modify feature control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} Layer that contains features that │ │ │ │ │ - * will be modified. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - this.virtualStyle = OpenLayers.Util.extend({}, │ │ │ │ │ - this.layer.style || │ │ │ │ │ - this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent) │ │ │ │ │ - ); │ │ │ │ │ - this.virtualStyle.fillOpacity = 0.3; │ │ │ │ │ - this.virtualStyle.strokeOpacity = 0.3; │ │ │ │ │ - this.deleteCodes = [46, 68]; │ │ │ │ │ - this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - if (!(OpenLayers.Util.isArray(this.deleteCodes))) { │ │ │ │ │ - this.deleteCodes = [this.deleteCodes]; │ │ │ │ │ - } │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + var c = this.layers.charAt(i); │ │ │ │ │ │ │ │ │ │ - // configure the drag handler │ │ │ │ │ - var dragCallbacks = { │ │ │ │ │ - down: function(pixel) { │ │ │ │ │ - this.vertex = null; │ │ │ │ │ - var feature = this.layer.getFeatureFromEvent( │ │ │ │ │ - this.handlers.drag.evt); │ │ │ │ │ - if (feature) { │ │ │ │ │ - this.dragStart(feature); │ │ │ │ │ - } else if (this.clickout) { │ │ │ │ │ - this._unselect = this.feature; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - move: function(pixel) { │ │ │ │ │ - delete this._unselect; │ │ │ │ │ - if (this.vertex) { │ │ │ │ │ - this.dragVertex(this.vertex, pixel); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - up: function() { │ │ │ │ │ - this.handlers.drag.stopDown = false; │ │ │ │ │ - if (this._unselect) { │ │ │ │ │ - this.unselectFeature(this._unselect); │ │ │ │ │ - delete this._unselect; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - done: function(pixel) { │ │ │ │ │ - if (this.vertex) { │ │ │ │ │ - this.dragComplete(this.vertex); │ │ │ │ │ + if (c == "B") { │ │ │ │ │ + this.map.setBaseLayer(layer); │ │ │ │ │ + } else if ((c == "T") || (c == "F")) { │ │ │ │ │ + layer.setVisibility(c == "T"); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - var dragOptions = { │ │ │ │ │ - documentDrag: this.documentDrag, │ │ │ │ │ - stopDown: false │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // configure the keyboard handler │ │ │ │ │ - var keyboardOptions = { │ │ │ │ │ - keydown: this.handleKeypress │ │ │ │ │ - }; │ │ │ │ │ - this.handlers = { │ │ │ │ │ - keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions), │ │ │ │ │ - drag: new OpenLayers.Handler.Drag(this, dragCallbacks, dragOptions) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Take care of things that are not handled in superclass. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully activated the control. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - return (this.handlers.keyboard.activate() && │ │ │ │ │ - this.handlers.drag.activate() && │ │ │ │ │ - OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully deactivated the control. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - // the return from the controls is unimportant in this case │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.moveLayerBack(); │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - this.handlers.keyboard.deactivate(); │ │ │ │ │ - var feature = this.feature; │ │ │ │ │ - if (feature && feature.geometry && feature.layer) { │ │ │ │ │ - this.unselectFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ArgParser" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomBox.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: beforeSelectFeature │ │ │ │ │ - * Called before a feature is selected. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The feature about to be selected. │ │ │ │ │ - */ │ │ │ │ │ - beforeSelectFeature: function(feature) { │ │ │ │ │ - return this.layer.events.triggerEvent( │ │ │ │ │ - "beforefeaturemodified", { │ │ │ │ │ - feature: feature │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: selectFeature │ │ │ │ │ - * Select a feature for modification in standalone mode. In non-standalone │ │ │ │ │ - * mode, this method is called when a feature is selected by clicking. │ │ │ │ │ - * Register a listener to the beforefeaturemodified event and return false │ │ │ │ │ - * to prevent feature modification. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} the selected feature. │ │ │ │ │ - */ │ │ │ │ │ - selectFeature: function(feature) { │ │ │ │ │ - if (this.feature === feature || │ │ │ │ │ - (this.geometryTypes && OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ - feature.geometry.CLASS_NAME) == -1)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.beforeSelectFeature(feature) !== false) { │ │ │ │ │ - if (this.feature) { │ │ │ │ │ - this.unselectFeature(this.feature); │ │ │ │ │ - } │ │ │ │ │ - this.feature = feature; │ │ │ │ │ - this.layer.selectedFeatures.push(feature); │ │ │ │ │ - this.layer.drawFeature(feature, 'select'); │ │ │ │ │ - this.modified = false; │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.onModificationStart(this.feature); │ │ │ │ │ - } │ │ │ │ │ - // keep track of geometry modifications │ │ │ │ │ - var modified = feature.modified; │ │ │ │ │ - if (feature.geometry && !(modified && modified.geometry)) { │ │ │ │ │ - this._originalGeometry = feature.geometry.clone(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Box.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomBox │ │ │ │ │ + * The ZoomBox control enables zooming directly to a given extent, by drawing │ │ │ │ │ + * a box on the map. The box is drawn by holding down shift, whilst dragging │ │ │ │ │ + * the mouse. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: unselectFeature │ │ │ │ │ - * Called when the select feature control unselects a feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The unselected feature. │ │ │ │ │ + * Property: type │ │ │ │ │ + * {OpenLayers.Control.TYPE} │ │ │ │ │ */ │ │ │ │ │ - unselectFeature: function(feature) { │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - if (this.dragHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - delete this.dragHandle; │ │ │ │ │ - } │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - delete this.radiusHandle; │ │ │ │ │ - } │ │ │ │ │ - this.layer.drawFeature(this.feature, 'default'); │ │ │ │ │ - this.feature = null; │ │ │ │ │ - OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); │ │ │ │ │ - this.onModificationEnd(feature); │ │ │ │ │ - this.layer.events.triggerEvent("afterfeaturemodified", { │ │ │ │ │ - feature: feature, │ │ │ │ │ - modified: this.modified │ │ │ │ │ - }); │ │ │ │ │ - this.modified = false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragStart │ │ │ │ │ - * Called by the drag handler before a feature is dragged. This method is │ │ │ │ │ - * used to differentiate between points and vertices │ │ │ │ │ - * of higher order geometries. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The point or vertex about to be │ │ │ │ │ - * dragged. │ │ │ │ │ + * Property: out │ │ │ │ │ + * {Boolean} Should the control be used for zooming out? │ │ │ │ │ */ │ │ │ │ │ - dragStart: function(feature) { │ │ │ │ │ - var isPoint = feature.geometry.CLASS_NAME == │ │ │ │ │ - 'OpenLayers.Geometry.Point'; │ │ │ │ │ - if (!this.standalone && │ │ │ │ │ - ((!feature._sketch && isPoint) || !feature._sketch)) { │ │ │ │ │ - if (this.toggle && this.feature === feature) { │ │ │ │ │ - // mark feature for unselection │ │ │ │ │ - this._unselect = feature; │ │ │ │ │ - } │ │ │ │ │ - this.selectFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - if (feature._sketch || isPoint) { │ │ │ │ │ - // feature is a drag or virtual handle or point │ │ │ │ │ - this.vertex = feature; │ │ │ │ │ - this.handlers.drag.stopDown = true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + out: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragVertex │ │ │ │ │ - * Called by the drag handler with each drag move of a vertex. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * vertex - {} The vertex being dragged. │ │ │ │ │ - * pixel - {} Pixel location of the mouse event. │ │ │ │ │ + * APIProperty: keyMask │ │ │ │ │ + * {Integer} Zoom only occurs if the keyMask matches the combination of │ │ │ │ │ + * keys down. Use bitwise operators and one or more of the │ │ │ │ │ + * constants to construct a keyMask. Leave null if │ │ │ │ │ + * not used mask. Default is null. │ │ │ │ │ */ │ │ │ │ │ - dragVertex: function(vertex, pixel) { │ │ │ │ │ - var pos = this.map.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geom = vertex.geometry; │ │ │ │ │ - geom.move(pos.lon - geom.x, pos.lat - geom.y); │ │ │ │ │ - this.modified = true; │ │ │ │ │ - /** │ │ │ │ │ - * Five cases: │ │ │ │ │ - * 1) dragging a simple point │ │ │ │ │ - * 2) dragging a virtual vertex │ │ │ │ │ - * 3) dragging a drag handle │ │ │ │ │ - * 4) dragging a real vertex │ │ │ │ │ - * 5) dragging a radius handle │ │ │ │ │ - */ │ │ │ │ │ - if (this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - // dragging a simple point │ │ │ │ │ - this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: pixel │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - if (vertex._index) { │ │ │ │ │ - // dragging a virtual vertex │ │ │ │ │ - vertex.geometry.parent.addComponent(vertex.geometry, │ │ │ │ │ - vertex._index); │ │ │ │ │ - // move from virtual to real vertex │ │ │ │ │ - delete vertex._index; │ │ │ │ │ - OpenLayers.Util.removeItem(this.virtualVertices, vertex); │ │ │ │ │ - this.vertices.push(vertex); │ │ │ │ │ - } else if (vertex == this.dragHandle) { │ │ │ │ │ - // dragging a drag handle │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.radiusHandle = null; │ │ │ │ │ - } │ │ │ │ │ - } else if (vertex !== this.radiusHandle) { │ │ │ │ │ - // dragging a real vertex │ │ │ │ │ - this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: pixel │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - // dragging a radius handle - no special treatment │ │ │ │ │ - if (this.virtualVertices.length > 0) { │ │ │ │ │ - this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - } │ │ │ │ │ - this.layer.drawFeature(this.feature, this.standalone ? undefined : │ │ │ │ │ - 'select'); │ │ │ │ │ - } │ │ │ │ │ - // keep the vertex on top so it gets the mouseout after dragging │ │ │ │ │ - // this should be removed in favor of an option to draw under or │ │ │ │ │ - // maintain node z-index │ │ │ │ │ - this.layer.drawFeature(vertex); │ │ │ │ │ - }, │ │ │ │ │ + keyMask: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragComplete │ │ │ │ │ - * Called by the drag handler when the feature dragging is complete. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * vertex - {} The vertex being dragged. │ │ │ │ │ + * APIProperty: alwaysZoom │ │ │ │ │ + * {Boolean} Always zoom in/out when box drawn, even if the zoom level does │ │ │ │ │ + * not change. │ │ │ │ │ */ │ │ │ │ │ - dragComplete: function(vertex) { │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.setFeatureState(); │ │ │ │ │ - this.onModification(this.feature); │ │ │ │ │ - this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ - feature: this.feature │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + alwaysZoom: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setFeatureState │ │ │ │ │ - * Called when the feature is modified. If the current state is not │ │ │ │ │ - * INSERT or DELETE, the state is set to UPDATE. │ │ │ │ │ + * APIProperty: zoomOnClick │ │ │ │ │ + * {Boolean} Should we zoom when no box was dragged, i.e. the user only │ │ │ │ │ + * clicked? Default is true. │ │ │ │ │ */ │ │ │ │ │ - setFeatureState: function() { │ │ │ │ │ - if (this.feature.state != OpenLayers.State.INSERT && │ │ │ │ │ - this.feature.state != OpenLayers.State.DELETE) { │ │ │ │ │ - this.feature.state = OpenLayers.State.UPDATE; │ │ │ │ │ - if (this.modified && this._originalGeometry) { │ │ │ │ │ - var feature = this.feature; │ │ │ │ │ - feature.modified = OpenLayers.Util.extend(feature.modified, { │ │ │ │ │ - geometry: this._originalGeometry │ │ │ │ │ - }); │ │ │ │ │ - delete this._originalGeometry; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + zoomOnClick: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetVertices │ │ │ │ │ + * Method: draw │ │ │ │ │ */ │ │ │ │ │ - resetVertices: function() { │ │ │ │ │ - if (this.vertices.length > 0) { │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - } │ │ │ │ │ - if (this.virtualVertices.length > 0) { │ │ │ │ │ - this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - } │ │ │ │ │ - if (this.dragHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.dragHandle = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.radiusHandle = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.feature && │ │ │ │ │ - this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { │ │ │ │ │ - if ((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { │ │ │ │ │ - this.collectDragHandle(); │ │ │ │ │ - } │ │ │ │ │ - if ((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | │ │ │ │ │ - OpenLayers.Control.ModifyFeature.RESIZE))) { │ │ │ │ │ - this.collectRadiusHandle(); │ │ │ │ │ - } │ │ │ │ │ - if (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE) { │ │ │ │ │ - // Don't collect vertices when we're resizing │ │ │ │ │ - if (!(this.mode & OpenLayers.Control.ModifyFeature.RESIZE)) { │ │ │ │ │ - this.collectVertices(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + draw: function() { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Box(this, { │ │ │ │ │ + done: this.zoomBox │ │ │ │ │ + }, { │ │ │ │ │ + keyMask: this.keyMask │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleKeypress │ │ │ │ │ - * Called by the feature handler on keypress. This is used to delete │ │ │ │ │ - * vertices. If the property is set, vertices will │ │ │ │ │ - * be deleted when a feature is selected for modification and │ │ │ │ │ - * the mouse is over a vertex. │ │ │ │ │ + * Method: zoomBox │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} Keypress event. │ │ │ │ │ + * position - {} or {} │ │ │ │ │ */ │ │ │ │ │ - handleKeypress: function(evt) { │ │ │ │ │ - var code = evt.keyCode; │ │ │ │ │ - │ │ │ │ │ - // check for delete key │ │ │ │ │ - if (this.feature && │ │ │ │ │ - OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { │ │ │ │ │ - var vertex = this.layer.getFeatureFromEvent(this.handlers.drag.evt); │ │ │ │ │ - if (vertex && │ │ │ │ │ - OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && │ │ │ │ │ - !this.handlers.drag.dragging && vertex.geometry.parent) { │ │ │ │ │ - // remove the vertex │ │ │ │ │ - vertex.geometry.parent.removeComponent(vertex.geometry); │ │ │ │ │ - this.layer.events.triggerEvent("vertexremoved", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: evt.xy │ │ │ │ │ + zoomBox: function(position) { │ │ │ │ │ + if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ + var bounds, │ │ │ │ │ + targetCenterPx = position.getCenterPixel(); │ │ │ │ │ + if (!this.out) { │ │ │ │ │ + var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.left, │ │ │ │ │ + y: position.bottom │ │ │ │ │ }); │ │ │ │ │ - this.layer.drawFeature(this.feature, this.standalone ? │ │ │ │ │ - undefined : 'select'); │ │ │ │ │ - this.modified = true; │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.setFeatureState(); │ │ │ │ │ - this.onModification(this.feature); │ │ │ │ │ - this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ - feature: this.feature │ │ │ │ │ + var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.right, │ │ │ │ │ + y: position.top │ │ │ │ │ }); │ │ │ │ │ + bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, │ │ │ │ │ + maxXY.lon, maxXY.lat); │ │ │ │ │ + } else { │ │ │ │ │ + var pixWidth = position.right - position.left; │ │ │ │ │ + var pixHeight = position.bottom - position.top; │ │ │ │ │ + var zoomFactor = Math.min((this.map.size.h / pixHeight), │ │ │ │ │ + (this.map.size.w / pixWidth)); │ │ │ │ │ + var extent = this.map.getExtent(); │ │ │ │ │ + var center = this.map.getLonLatFromPixel(targetCenterPx); │ │ │ │ │ + var xmin = center.lon - (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ + var xmax = center.lon + (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ + var ymin = center.lat - (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ + var ymax = center.lat + (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ + bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: collectVertices │ │ │ │ │ - * Collect the vertices from the modifiable feature's geometry and push │ │ │ │ │ - * them on to the control's vertices array. │ │ │ │ │ - */ │ │ │ │ │ - collectVertices: function() { │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - var control = this; │ │ │ │ │ - │ │ │ │ │ - function collectComponentVertices(geometry) { │ │ │ │ │ - var i, vertex, component, len; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - vertex = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - vertex._sketch = true; │ │ │ │ │ - vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ - control.vertices.push(vertex); │ │ │ │ │ + // always zoom in/out │ │ │ │ │ + var lastZoom = this.map.getZoom(), │ │ │ │ │ + size = this.map.getSize(), │ │ │ │ │ + centerPx = { │ │ │ │ │ + x: size.w / 2, │ │ │ │ │ + y: size.h / 2 │ │ │ │ │ + }, │ │ │ │ │ + zoom = this.map.getZoomForExtent(bounds), │ │ │ │ │ + oldRes = this.map.getResolution(), │ │ │ │ │ + newRes = this.map.getResolutionForZoom(zoom); │ │ │ │ │ + if (oldRes == newRes) { │ │ │ │ │ + this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx)); │ │ │ │ │ } else { │ │ │ │ │ - var numVert = geometry.components.length; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ - numVert -= 1; │ │ │ │ │ - } │ │ │ │ │ - for (i = 0; i < numVert; ++i) { │ │ │ │ │ - component = geometry.components[i]; │ │ │ │ │ - if (component.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - vertex = new OpenLayers.Feature.Vector(component); │ │ │ │ │ - vertex._sketch = true; │ │ │ │ │ - vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ - control.vertices.push(vertex); │ │ │ │ │ - } else { │ │ │ │ │ - collectComponentVertices(component); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add virtual vertices in the middle of each edge │ │ │ │ │ - if (control.createVertices && geometry.CLASS_NAME != "OpenLayers.Geometry.MultiPoint") { │ │ │ │ │ - for (i = 0, len = geometry.components.length; i < len - 1; ++i) { │ │ │ │ │ - var prevVertex = geometry.components[i]; │ │ │ │ │ - var nextVertex = geometry.components[i + 1]; │ │ │ │ │ - if (prevVertex.CLASS_NAME == "OpenLayers.Geometry.Point" && │ │ │ │ │ - nextVertex.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - var x = (prevVertex.x + nextVertex.x) / 2; │ │ │ │ │ - var y = (prevVertex.y + nextVertex.y) / 2; │ │ │ │ │ - var point = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ - null, control.virtualStyle │ │ │ │ │ - ); │ │ │ │ │ - // set the virtual parent and intended index │ │ │ │ │ - point.geometry.parent = geometry; │ │ │ │ │ - point._index = i + 1; │ │ │ │ │ - point._sketch = true; │ │ │ │ │ - control.virtualVertices.push(point); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + var zoomOriginPx = { │ │ │ │ │ + x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / │ │ │ │ │ + (oldRes - newRes), │ │ │ │ │ + y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / │ │ │ │ │ + (oldRes - newRes) │ │ │ │ │ + }; │ │ │ │ │ + this.map.zoomTo(zoom, zoomOriginPx); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - collectComponentVertices.call(this, this.feature.geometry); │ │ │ │ │ - this.layer.addFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.addFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: collectDragHandle │ │ │ │ │ - * Collect the drag handle for the selected geometry. │ │ │ │ │ - */ │ │ │ │ │ - collectDragHandle: function() { │ │ │ │ │ - var geometry = this.feature.geometry; │ │ │ │ │ - var center = geometry.getBounds().getCenterLonLat(); │ │ │ │ │ - var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ); │ │ │ │ │ - var origin = new OpenLayers.Feature.Vector(originGeometry); │ │ │ │ │ - originGeometry.move = function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - geometry.move(x, y); │ │ │ │ │ - }; │ │ │ │ │ - origin._sketch = true; │ │ │ │ │ - this.dragHandle = origin; │ │ │ │ │ - this.dragHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ - this.layer.addFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: collectRadiusHandle │ │ │ │ │ - * Collect the radius handle for the selected geometry. │ │ │ │ │ - */ │ │ │ │ │ - collectRadiusHandle: function() { │ │ │ │ │ - var geometry = this.feature.geometry; │ │ │ │ │ - var bounds = geometry.getBounds(); │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ); │ │ │ │ │ - var radiusGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - bounds.right, bounds.bottom │ │ │ │ │ - ); │ │ │ │ │ - var radius = new OpenLayers.Feature.Vector(radiusGeometry); │ │ │ │ │ - var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE); │ │ │ │ │ - var reshape = (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE); │ │ │ │ │ - var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE); │ │ │ │ │ - │ │ │ │ │ - radiusGeometry.move = function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - var dx1 = this.x - originGeometry.x; │ │ │ │ │ - var dy1 = this.y - originGeometry.y; │ │ │ │ │ - var dx0 = dx1 - x; │ │ │ │ │ - var dy0 = dy1 - y; │ │ │ │ │ - if (rotate) { │ │ │ │ │ - var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ - var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ - var angle = a1 - a0; │ │ │ │ │ - angle *= 180 / Math.PI; │ │ │ │ │ - geometry.rotate(angle, originGeometry); │ │ │ │ │ + if (lastZoom == this.map.getZoom() && this.alwaysZoom == true) { │ │ │ │ │ + this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); │ │ │ │ │ } │ │ │ │ │ - if (resize) { │ │ │ │ │ - var scale, ratio; │ │ │ │ │ - // 'resize' together with 'reshape' implies that the aspect │ │ │ │ │ - // ratio of the geometry will not be preserved whilst resizing │ │ │ │ │ - if (reshape) { │ │ │ │ │ - scale = dy1 / dy0; │ │ │ │ │ - ratio = (dx1 / dx0) / scale; │ │ │ │ │ - } else { │ │ │ │ │ - var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ - var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ - scale = l1 / l0; │ │ │ │ │ - } │ │ │ │ │ - geometry.resize(scale, originGeometry, ratio); │ │ │ │ │ + } else if (this.zoomOnClick) { // it's a pixel │ │ │ │ │ + if (!this.out) { │ │ │ │ │ + this.map.zoomTo(this.map.getZoom() + 1, position); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.zoomTo(this.map.getZoom() - 1, position); │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - radius._sketch = true; │ │ │ │ │ - this.radiusHandle = radius; │ │ │ │ │ - this.radiusHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ - this.layer.addFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control and all handlers. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The control's map. │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.handlers.drag.setMap(map); │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomBox" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomPanel.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleMapEvents │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - handleMapEvents: function(evt) { │ │ │ │ │ - if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/* 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: moveLayerToTop │ │ │ │ │ - * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ - * it. │ │ │ │ │ - */ │ │ │ │ │ - moveLayerToTop: function() { │ │ │ │ │ - var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ - this.layer.getZIndex()) + 1; │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomIn.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomOut.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomPanel │ │ │ │ │ + * The ZoomPanel control is a compact collecton of 3 zoom controls: a │ │ │ │ │ + * , a , and a │ │ │ │ │ + * . By default it is drawn in the upper left │ │ │ │ │ + * corner of the map. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * If you wish to use this class with the default images and you want │ │ │ │ │ + * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ + * added css stylesheet to your HTML file: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveLayerBack │ │ │ │ │ - * Moves the layer back to the position determined by the map's layers │ │ │ │ │ - * array. │ │ │ │ │ + * Constructor: OpenLayers.Control.ZoomPanel │ │ │ │ │ + * Add the three zooming controls. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.addControls([ │ │ │ │ │ + new OpenLayers.Control.ZoomIn(), │ │ │ │ │ + new OpenLayers.Control.ZoomToMaxExtent(), │ │ │ │ │ + new OpenLayers.Control.ZoomOut() │ │ │ │ │ + ]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ModifyFeature" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomPanel" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: RESHAPE │ │ │ │ │ - * {Integer} Constant used to make the control work in reshape mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.RESHAPE = 1; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: RESIZE │ │ │ │ │ - * {Integer} Constant used to make the control work in resize mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.RESIZE = 2; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: ROTATE │ │ │ │ │ - * {Integer} Constant used to make the control work in rotate mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.ROTATE = 4; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: DRAG │ │ │ │ │ - * {Integer} Constant used to make the control work in drag mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.DRAG = 8; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/UTFGrid.js │ │ │ │ │ + OpenLayers/Control/PanZoom.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.UTFGrid │ │ │ │ │ - * │ │ │ │ │ - * This Control provides behavior associated with UTFGrid Layers. │ │ │ │ │ - * These 'hit grids' provide underlying feature attributes without │ │ │ │ │ - * calling the server (again). This control allows Mousemove, Hovering │ │ │ │ │ - * and Click events to trigger callbacks that use the attributes in │ │ │ │ │ - * whatever way you need. │ │ │ │ │ - * │ │ │ │ │ - * The most common example may be a UTFGrid layer containing feature │ │ │ │ │ - * attributes that are displayed in a div as you mouseover. │ │ │ │ │ - * │ │ │ │ │ - * Example Code: │ │ │ │ │ - * │ │ │ │ │ - * (start code) │ │ │ │ │ - * var world_utfgrid = new OpenLayers.Layer.UTFGrid( │ │ │ │ │ - * 'UTFGrid Layer', │ │ │ │ │ - * "http://tiles/world_utfgrid/${z}/${x}/${y}.json" │ │ │ │ │ - * ); │ │ │ │ │ - * map.addLayer(world_utfgrid); │ │ │ │ │ - * │ │ │ │ │ - * var control = new OpenLayers.Control.UTFGrid({ │ │ │ │ │ - * layers: [world_utfgrid], │ │ │ │ │ - * handlerMode: 'move', │ │ │ │ │ - * callback: function(infoLookup) { │ │ │ │ │ - * // do something with returned data │ │ │ │ │ - * │ │ │ │ │ - * } │ │ │ │ │ - * }) │ │ │ │ │ - * (end code) │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.PanZoom │ │ │ │ │ + * The PanZoom is a visible control, composed of a │ │ │ │ │ + * and a . By │ │ │ │ │ + * default it is drawn in the upper left corner of the map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ + * on clicking the arrow buttons. If you want to pan by some ratio │ │ │ │ │ + * of the map dimensions, use instead. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + slideFactor: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: Layers │ │ │ │ │ - * List of layers to consider. Must be Layer.UTFGrids │ │ │ │ │ - * `null` is the default indicating all UTFGrid Layers are queried. │ │ │ │ │ - * {Array} │ │ │ │ │ + * APIProperty: slideRatio │ │ │ │ │ + * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ + * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ + * override . E.g. if slideRatio is .5, then the Pan Up │ │ │ │ │ + * button will pan up half the map height. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + slideRatio: null, │ │ │ │ │ │ │ │ │ │ - /* Property: defaultHandlerOptions │ │ │ │ │ - * The default opts passed to the handler constructors │ │ │ │ │ + /** │ │ │ │ │ + * Property: buttons │ │ │ │ │ + * {Array(DOMElement)} Array of Button Divs │ │ │ │ │ */ │ │ │ │ │ - defaultHandlerOptions: { │ │ │ │ │ - 'delay': 300, │ │ │ │ │ - 'pixelTolerance': 4, │ │ │ │ │ - 'stopMove': false, │ │ │ │ │ - 'single': true, │ │ │ │ │ - 'double': false, │ │ │ │ │ - 'stopSingle': false, │ │ │ │ │ - 'stopDouble': false │ │ │ │ │ - }, │ │ │ │ │ + buttons: null, │ │ │ │ │ │ │ │ │ │ - /* APIProperty: handlerMode │ │ │ │ │ - * Defaults to 'click'. Can be 'hover' or 'move'. │ │ │ │ │ + /** │ │ │ │ │ + * Property: position │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - handlerMode: 'click', │ │ │ │ │ + position: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setHandler │ │ │ │ │ - * sets this.handlerMode and calls resetHandler() │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.PanZoom │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * hm - {String} Handler Mode string; 'click', 'hover' or 'move'. │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - setHandler: function(hm) { │ │ │ │ │ - this.handlerMode = hm; │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X, │ │ │ │ │ + OpenLayers.Control.PanZoom.Y); │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetHandler │ │ │ │ │ - * Deactivates the old hanlder and creates a new │ │ │ │ │ - * based on the mode specified in │ │ │ │ │ - * this.handlerMode │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - resetHandler: function() { │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.deactivate(); │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ } │ │ │ │ │ + this.removeButtons(); │ │ │ │ │ + this.buttons = null; │ │ │ │ │ + this.position = null; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.handlerMode == 'hover') { │ │ │ │ │ - // Handle this event on hover │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'pause': this.handleEvent, │ │ │ │ │ - 'move': this.reset │ │ │ │ │ - }, │ │ │ │ │ - this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } else if (this.handlerMode == 'click') { │ │ │ │ │ - // Handle this event on click │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, { │ │ │ │ │ - 'click': this.handleEvent │ │ │ │ │ - }, this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } else if (this.handlerMode == 'move') { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, │ │ │ │ │ - // Handle this event while hovering OR moving │ │ │ │ │ - { │ │ │ │ │ - 'pause': this.handleEvent, │ │ │ │ │ - 'move': this.handleEvent │ │ │ │ │ - }, │ │ │ │ │ - this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * │ │ │ │ │ + * Properties: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the container div for the PanZoom control. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || this.defaultHandlerOptions; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + // initialize our internal div │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + px = this.position; │ │ │ │ │ + │ │ │ │ │ + // place the controls │ │ │ │ │ + this.buttons = []; │ │ │ │ │ + │ │ │ │ │ + var sz = { │ │ │ │ │ + w: 18, │ │ │ │ │ + h: 18 │ │ │ │ │ + }; │ │ │ │ │ + var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ + │ │ │ │ │ + this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ + px.y = centered.y + sz.h; │ │ │ │ │ + this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ + this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ + this._addButton("pandown", "south-mini.png", │ │ │ │ │ + centered.add(0, sz.h * 2), sz); │ │ │ │ │ + this._addButton("zoomin", "zoom-plus-mini.png", │ │ │ │ │ + centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ + this._addButton("zoomworld", "zoom-world-mini.png", │ │ │ │ │ + centered.add(0, sz.h * 4 + 5), sz); │ │ │ │ │ + this._addButton("zoomout", "zoom-minus-mini.png", │ │ │ │ │ + centered.add(0, sz.h * 5 + 5), sz); │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleEvent │ │ │ │ │ - * Internal method called when specified event is triggered. │ │ │ │ │ + * Method: _addButton │ │ │ │ │ * │ │ │ │ │ - * This method does several things: │ │ │ │ │ - * │ │ │ │ │ - * Gets the lonLat of the event. │ │ │ │ │ - * │ │ │ │ │ - * Loops through the appropriate hit grid layers and gathers the attributes. │ │ │ │ │ - * │ │ │ │ │ - * Passes the attributes to the callback │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * id - {String} │ │ │ │ │ + * img - {String} │ │ │ │ │ + * xy - {} │ │ │ │ │ + * sz - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A Div (an alphaImageDiv, to be precise) that contains the │ │ │ │ │ + * image of the button, and has all the proper event handlers set. │ │ │ │ │ */ │ │ │ │ │ - handleEvent: function(evt) { │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - this.reset(); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ - if (!lonLat) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + _addButton: function(id, img, xy, sz) { │ │ │ │ │ + var imgLocation = OpenLayers.Util.getImageLocation(img); │ │ │ │ │ + var btn = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + this.id + "_" + id, │ │ │ │ │ + xy, sz, imgLocation, "absolute"); │ │ │ │ │ + btn.style.cursor = "pointer"; │ │ │ │ │ + //we want to add the outer div │ │ │ │ │ + this.div.appendChild(btn); │ │ │ │ │ + btn.action = id; │ │ │ │ │ + btn.className = "olButton"; │ │ │ │ │ │ │ │ │ │ - var layers = this.findLayers(); │ │ │ │ │ - if (layers.length > 0) { │ │ │ │ │ - var infoLookup = {}; │ │ │ │ │ - var layer, idx; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - layer = layers[i]; │ │ │ │ │ - idx = OpenLayers.Util.indexOf(this.map.layers, layer); │ │ │ │ │ - infoLookup[idx] = layer.getFeatureInfo(lonLat); │ │ │ │ │ - } │ │ │ │ │ - this.callback(infoLookup, lonLat, evt.xy); │ │ │ │ │ - } │ │ │ │ │ + //we want to remember/reference the outer div │ │ │ │ │ + this.buttons.push(btn); │ │ │ │ │ + return btn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: callback │ │ │ │ │ - * Function to be called when a mouse event corresponds with a location that │ │ │ │ │ - * includes data in one of the configured UTFGrid layers. │ │ │ │ │ - * │ │ │ │ │ + * Method: _removeButton │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * infoLookup - {Object} Keys of this object are layer indexes and can be │ │ │ │ │ - * used to resolve a layer in the map.layers array. The structure of │ │ │ │ │ - * the property values depend on the data included in the underlying │ │ │ │ │ - * UTFGrid and may be any valid JSON type. │ │ │ │ │ + * btn - {Object} │ │ │ │ │ */ │ │ │ │ │ - callback: function(infoLookup) { │ │ │ │ │ - // to be provided in the constructor │ │ │ │ │ + _removeButton: function(btn) { │ │ │ │ │ + this.div.removeChild(btn); │ │ │ │ │ + OpenLayers.Util.removeItem(this.buttons, btn); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: reset │ │ │ │ │ - * Calls the callback with null. │ │ │ │ │ + * Method: removeButtons │ │ │ │ │ */ │ │ │ │ │ - reset: function(evt) { │ │ │ │ │ - this.callback(null); │ │ │ │ │ + removeButtons: function() { │ │ │ │ │ + for (var i = this.buttons.length - 1; i >= 0; --i) { │ │ │ │ │ + this._removeButton(this.buttons[i]); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ - * The default value of this.layers is null; this causes the │ │ │ │ │ - * findLayers method to return ALL UTFGrid layers encountered. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + var btn = evt.buttonElement; │ │ │ │ │ + switch (btn.action) { │ │ │ │ │ + case "panup": │ │ │ │ │ + this.map.pan(0, -this.getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case "pandown": │ │ │ │ │ + this.map.pan(0, this.getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case "panleft": │ │ │ │ │ + this.map.pan(-this.getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + case "panright": │ │ │ │ │ + this.map.pan(this.getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + case "zoomin": │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + break; │ │ │ │ │ + case "zoomout": │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + break; │ │ │ │ │ + case "zoomworld": │ │ │ │ │ + this.map.zoomToMaxExtent(); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSlideFactor │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * None │ │ │ │ │ + * dim - {String} "w" or "h" (for width or height). │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} Layers to handle on each event │ │ │ │ │ + * {Number} The slide factor for panning in the requested direction. │ │ │ │ │ */ │ │ │ │ │ - findLayers: function() { │ │ │ │ │ - var candidates = this.layers || this.map.layers; │ │ │ │ │ - var layers = []; │ │ │ │ │ - var layer; │ │ │ │ │ - for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = candidates[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.UTFGrid) { │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return layers; │ │ │ │ │ + getSlideFactor: function(dim) { │ │ │ │ │ + return this.slideRatio ? │ │ │ │ │ + this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ + this.slideFactor; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.UTFGrid" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.PanZoom" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: X │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.PanZoom.X = 4; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: Y │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.PanZoom.Y = 4; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/MousePosition.js │ │ │ │ │ + OpenLayers/Control/PanZoomBar.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Control/PanZoom.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.MousePosition │ │ │ │ │ - * The MousePosition control displays geographic coordinates of the mouse │ │ │ │ │ - * pointer, as it is moved about the map. │ │ │ │ │ - * │ │ │ │ │ - * You can use the - or -properties to provide more information │ │ │ │ │ - * about the displayed coordinates to the user: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * var mousePositionCtrl = new OpenLayers.Control.MousePosition({ │ │ │ │ │ - * prefix: '' + │ │ │ │ │ - * 'EPSG:4326 coordinates: ' │ │ │ │ │ - * } │ │ │ │ │ - * ); │ │ │ │ │ - * (end code) │ │ │ │ │ + * Class: OpenLayers.Control.PanZoomBar │ │ │ │ │ + * The PanZoomBar is a visible control composed of a │ │ │ │ │ + * and a . │ │ │ │ │ + * By default it is displayed in the upper left corner of the map as 4 │ │ │ │ │ + * directional arrows above a vertical slider. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomStopWidth │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + zoomStopWidth: 18, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomStopHeight │ │ │ │ │ */ │ │ │ │ │ - element: null, │ │ │ │ │ + zoomStopHeight: 11, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: prefix │ │ │ │ │ - * {String} A string to be prepended to the current pointers coordinates │ │ │ │ │ - * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ + /** │ │ │ │ │ + * Property: slider │ │ │ │ │ */ │ │ │ │ │ - prefix: '', │ │ │ │ │ + slider: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: separator │ │ │ │ │ - * {String} A string to be used to seperate the two coordinates from each │ │ │ │ │ - * other. Defaults to the string ', ', which will result in a │ │ │ │ │ - * rendered coordinate of e.g. '42.12, 21.22'. │ │ │ │ │ + /** │ │ │ │ │ + * Property: sliderEvents │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - separator: ', ', │ │ │ │ │ + sliderEvents: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: suffix │ │ │ │ │ - * {String} A string to be appended to the current pointers coordinates │ │ │ │ │ - * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoombarDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - suffix: '', │ │ │ │ │ + zoombarDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numDigits │ │ │ │ │ - * {Integer} The number of digits each coordinate shall have when being │ │ │ │ │ - * rendered, Defaults to 5. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomWorldIcon │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - numDigits: 5, │ │ │ │ │ + zoomWorldIcon: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: granularity │ │ │ │ │ - * {Integer} │ │ │ │ │ + * APIProperty: panIcons │ │ │ │ │ + * {Boolean} Set this property to false not to display the pan icons. If │ │ │ │ │ + * false the zoom world icon is placed under the zoom bar. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - granularity: 10, │ │ │ │ │ + panIcons: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: emptyString │ │ │ │ │ - * {String} Set this to some value to set when the mouse is outside the │ │ │ │ │ - * map. │ │ │ │ │ + * APIProperty: forceFixedZoomLevel │ │ │ │ │ + * {Boolean} Force a fixed zoom level even though the map has │ │ │ │ │ + * fractionalZoom │ │ │ │ │ */ │ │ │ │ │ - emptyString: null, │ │ │ │ │ + forceFixedZoomLevel: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastXy │ │ │ │ │ + * Property: mouseDragStart │ │ │ │ │ * {} │ │ │ │ │ */ │ │ │ │ │ - lastXy: null, │ │ │ │ │ + mouseDragStart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} The projection in which the mouse position is │ │ │ │ │ - * displayed. │ │ │ │ │ + * Property: deltaY │ │ │ │ │ + * {Number} The cumulative vertical pixel offset during a zoom bar drag. │ │ │ │ │ */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ + deltaY: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.MousePosition │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Options for control. │ │ │ │ │ + * Property: zoomStart │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ + zoomStart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Constructor: OpenLayers.Control.PanZoomBar │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.map.events.register('mousemove', this, this.redraw); │ │ │ │ │ - this.map.events.register('mouseout', this, this.reset); │ │ │ │ │ - this.redraw(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + destroy: function() { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.map.events.unregister('mousemove', this, this.redraw); │ │ │ │ │ - this.map.events.unregister('mouseout', this, this.reset); │ │ │ │ │ - this.element.innerHTML = ""; │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + this._removeZoomBar(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "changebaselayer": this.redraw, │ │ │ │ │ + "updatesize": this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - if (!this.element) { │ │ │ │ │ - this.div.left = ""; │ │ │ │ │ - this.div.top = ""; │ │ │ │ │ - this.element = this.div; │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ + delete this.mouseDragStart; │ │ │ │ │ + delete this.zoomStart; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - redraw: function(evt) { │ │ │ │ │ - │ │ │ │ │ - var lonLat; │ │ │ │ │ - │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - this.reset(); │ │ │ │ │ - return; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.lastXy == null || │ │ │ │ │ - Math.abs(evt.xy.x - this.lastXy.x) > this.granularity || │ │ │ │ │ - Math.abs(evt.xy.y - this.lastXy.y) > this.granularity) { │ │ │ │ │ - this.lastXy = evt.xy; │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ - if (!lonLat) { │ │ │ │ │ - // map has not yet been properly initialized │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.displayProjection) { │ │ │ │ │ - lonLat.transform(this.map.getProjectionObject(), │ │ │ │ │ - this.displayProjection); │ │ │ │ │ - } │ │ │ │ │ - this.lastXy = evt.xy; │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var newHtml = this.formatOutput(lonLat); │ │ │ │ │ - │ │ │ │ │ - if (newHtml != this.element.innerHTML) { │ │ │ │ │ - this.element.innerHTML = newHtml; │ │ │ │ │ - } │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "changebaselayer": this.redraw, │ │ │ │ │ + "updatesize": this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: reset │ │ │ │ │ + /** │ │ │ │ │ + * Method: redraw │ │ │ │ │ + * clear the div and start over. │ │ │ │ │ */ │ │ │ │ │ - reset: function(evt) { │ │ │ │ │ - if (this.emptyString != null) { │ │ │ │ │ - this.element.innerHTML = this.emptyString; │ │ │ │ │ + redraw: function() { │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.removeButtons(); │ │ │ │ │ + this._removeZoomBar(); │ │ │ │ │ } │ │ │ │ │ + this.draw(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: formatOutput │ │ │ │ │ - * Override to provide custom display output │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonLat - {} Location to display │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - formatOutput: function(lonLat) { │ │ │ │ │ - var digits = parseInt(this.numDigits); │ │ │ │ │ - var newHtml = │ │ │ │ │ - this.prefix + │ │ │ │ │ - lonLat.lon.toFixed(digits) + │ │ │ │ │ - this.separator + │ │ │ │ │ - lonLat.lat.toFixed(digits) + │ │ │ │ │ - this.suffix; │ │ │ │ │ - return newHtml; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.MousePosition" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Graticule.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + // initialize our internal div │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + px = this.position.clone(); │ │ │ │ │ │ │ │ │ │ -/* 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. */ │ │ │ │ │ + // place the controls │ │ │ │ │ + this.buttons = []; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - * @requires OpenLayers/Rule.js │ │ │ │ │ - * @requires OpenLayers/StyleMap.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ - */ │ │ │ │ │ + var sz = { │ │ │ │ │ + w: 18, │ │ │ │ │ + h: 18 │ │ │ │ │ + }; │ │ │ │ │ + if (this.panIcons) { │ │ │ │ │ + var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ + var wposition = sz.w; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Graticule │ │ │ │ │ - * The Graticule displays a grid of latitude/longitude lines reprojected on │ │ │ │ │ - * the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + centered = new OpenLayers.Pixel(px.x + sz.w, px.y); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ + px.y = centered.y + sz.h; │ │ │ │ │ + this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: intervals │ │ │ │ │ - * {Array(Float)} A list of possible graticule widths in degrees. │ │ │ │ │ - */ │ │ │ │ │ - intervals: [45, 30, 20, 10, 5, 2, 1, │ │ │ │ │ - 0.5, 0.2, 0.1, 0.05, 0.01, │ │ │ │ │ - 0.005, 0.002, 0.001 │ │ │ │ │ - ], │ │ │ │ │ + wposition *= 2; │ │ │ │ │ + } │ │ │ │ │ + this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); │ │ │ │ │ + this._addButton("pandown", "south-mini.png", centered.add(0, sz.h * 2), sz); │ │ │ │ │ + this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ + centered = this._addZoomBar(centered.add(0, sz.h * 4 + 5)); │ │ │ │ │ + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ + } else { │ │ │ │ │ + this._addButton("zoomin", "zoom-plus-mini.png", px, sz); │ │ │ │ │ + centered = this._addZoomBar(px.add(0, sz.h)); │ │ │ │ │ + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + centered = centered.add(0, sz.h + 3); │ │ │ │ │ + this._addButton("zoomworld", "zoom-world-mini.png", centered, sz); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Allows the Graticule control to be switched on and off by │ │ │ │ │ - * LayerSwitcher control. Defaults is true. │ │ │ │ │ + /** │ │ │ │ │ + * Method: _addZoomBar │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * centered - {} where zoombar drawing is to start. │ │ │ │ │ */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ + _addZoomBar: function(centered) { │ │ │ │ │ + var imgLocation = OpenLayers.Util.getImageLocation("slider.png"); │ │ │ │ │ + var id = this.id + "_" + this.map.id; │ │ │ │ │ + var minZoom = this.map.getMinZoom(); │ │ │ │ │ + var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom(); │ │ │ │ │ + var slider = OpenLayers.Util.createAlphaImageDiv(id, │ │ │ │ │ + centered.add(-1, zoomsToEnd * this.zoomStopHeight), { │ │ │ │ │ + w: 20, │ │ │ │ │ + h: 9 │ │ │ │ │ + }, │ │ │ │ │ + imgLocation, │ │ │ │ │ + "absolute"); │ │ │ │ │ + slider.style.cursor = "move"; │ │ │ │ │ + this.slider = slider; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: visible │ │ │ │ │ - * {Boolean} should the graticule be initially visible (default=true) │ │ │ │ │ - */ │ │ │ │ │ - visible: true, │ │ │ │ │ + this.sliderEvents = new OpenLayers.Events(this, slider, null, true, { │ │ │ │ │ + includeXY: true │ │ │ │ │ + }); │ │ │ │ │ + this.sliderEvents.on({ │ │ │ │ │ + "touchstart": this.zoomBarDown, │ │ │ │ │ + "touchmove": this.zoomBarDrag, │ │ │ │ │ + "touchend": this.zoomBarUp, │ │ │ │ │ + "mousedown": this.zoomBarDown, │ │ │ │ │ + "mousemove": this.zoomBarDrag, │ │ │ │ │ + "mouseup": this.zoomBarUp │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numPoints │ │ │ │ │ - * {Integer} The number of points to use in each graticule line. Higher │ │ │ │ │ - * numbers result in a smoother curve for projected maps │ │ │ │ │ - */ │ │ │ │ │ - numPoints: 50, │ │ │ │ │ + var sz = { │ │ │ │ │ + w: this.zoomStopWidth, │ │ │ │ │ + h: this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom) │ │ │ │ │ + }; │ │ │ │ │ + var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png"); │ │ │ │ │ + var div = null; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: targetSize │ │ │ │ │ - * {Integer} The maximum size of the grid in pixels on the map │ │ │ │ │ - */ │ │ │ │ │ - targetSize: 200, │ │ │ │ │ + if (OpenLayers.Util.alphaHack()) { │ │ │ │ │ + var id = this.id + "_" + this.map.id; │ │ │ │ │ + div = OpenLayers.Util.createAlphaImageDiv(id, centered, { │ │ │ │ │ + w: sz.w, │ │ │ │ │ + h: this.zoomStopHeight │ │ │ │ │ + }, │ │ │ │ │ + imgLocation, │ │ │ │ │ + "absolute", null, "crop"); │ │ │ │ │ + div.style.height = sz.h + "px"; │ │ │ │ │ + } else { │ │ │ │ │ + div = OpenLayers.Util.createDiv( │ │ │ │ │ + 'OpenLayers_Control_PanZoomBar_Zoombar' + this.map.id, │ │ │ │ │ + centered, │ │ │ │ │ + sz, │ │ │ │ │ + imgLocation); │ │ │ │ │ + } │ │ │ │ │ + div.style.cursor = "pointer"; │ │ │ │ │ + div.className = "olButton"; │ │ │ │ │ + this.zoombarDiv = div; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {String} The name to be displayed in the layer switcher, default is set │ │ │ │ │ - * by {}. │ │ │ │ │ - */ │ │ │ │ │ - layerName: null, │ │ │ │ │ + this.div.appendChild(div); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: labelled │ │ │ │ │ - * {Boolean} Should the graticule lines be labelled?. default=true │ │ │ │ │ - */ │ │ │ │ │ - labelled: true, │ │ │ │ │ + this.startTop = parseInt(div.style.top); │ │ │ │ │ + this.div.appendChild(slider); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: labelFormat │ │ │ │ │ - * {String} the format of the labels, default = 'dm'. See │ │ │ │ │ - * for other options. │ │ │ │ │ - */ │ │ │ │ │ - labelFormat: 'dm', │ │ │ │ │ + this.map.events.register("zoomend", this, this.moveZoomBar); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: lineSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render lines │ │ │ │ │ - */ │ │ │ │ │ - lineSymbolizer: { │ │ │ │ │ - strokeColor: "#333", │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeOpacity: 0.5 │ │ │ │ │ + centered = centered.add(0, │ │ │ │ │ + this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom)); │ │ │ │ │ + return centered; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: labelSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render labels │ │ │ │ │ - */ │ │ │ │ │ - labelSymbolizer: {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: gratLayer │ │ │ │ │ - * {} vector layer used to draw the graticule on │ │ │ │ │ + * Method: _removeZoomBar │ │ │ │ │ */ │ │ │ │ │ - gratLayer: null, │ │ │ │ │ + _removeZoomBar: function() { │ │ │ │ │ + this.sliderEvents.un({ │ │ │ │ │ + "touchstart": this.zoomBarDown, │ │ │ │ │ + "touchmove": this.zoomBarDrag, │ │ │ │ │ + "touchend": this.zoomBarUp, │ │ │ │ │ + "mousedown": this.zoomBarDown, │ │ │ │ │ + "mousemove": this.zoomBarDrag, │ │ │ │ │ + "mouseup": this.zoomBarUp │ │ │ │ │ + }); │ │ │ │ │ + this.sliderEvents.destroy(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Graticule │ │ │ │ │ - * Create a new graticule control to display a grid of latitude longitude │ │ │ │ │ - * lines. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.layerName = options.layerName || OpenLayers.i18n("Graticule"); │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.div.removeChild(this.zoombarDiv); │ │ │ │ │ + this.zoombarDiv = null; │ │ │ │ │ + this.div.removeChild(this.slider); │ │ │ │ │ + this.slider = null; │ │ │ │ │ │ │ │ │ │ - this.labelSymbolizer.stroke = false; │ │ │ │ │ - this.labelSymbolizer.fill = false; │ │ │ │ │ - this.labelSymbolizer.label = "${label}"; │ │ │ │ │ - this.labelSymbolizer.labelAlign = "${labelAlign}"; │ │ │ │ │ - this.labelSymbolizer.labelXOffset = "${xOffset}"; │ │ │ │ │ - this.labelSymbolizer.labelYOffset = "${yOffset}"; │ │ │ │ │ + this.map.events.unregister("zoomend", this, this.moveZoomBar); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.gratLayer) { │ │ │ │ │ - this.gratLayer.destroy(); │ │ │ │ │ - this.gratLayer = null; │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.onButtonClick.apply(this, arguments); │ │ │ │ │ + if (evt.buttonElement === this.zoombarDiv) { │ │ │ │ │ + var levels = evt.buttonXY.y / this.zoomStopHeight; │ │ │ │ │ + if (this.forceFixedZoomLevel || !this.map.fractionalZoom) { │ │ │ │ │ + levels = Math.floor(levels); │ │ │ │ │ + } │ │ │ │ │ + var zoom = (this.map.getNumZoomLevels() - 1) - levels; │ │ │ │ │ + zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); │ │ │ │ │ + this.map.zoomTo(zoom); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: passEventToSlider │ │ │ │ │ + * This function is used to pass events that happen on the div, or the map, │ │ │ │ │ + * through to the slider, which then does its moving thing. │ │ │ │ │ * │ │ │ │ │ - * initializes the graticule layer and does the initial update │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (!this.gratLayer) { │ │ │ │ │ - var gratStyle = new OpenLayers.Style({}, { │ │ │ │ │ - rules: [new OpenLayers.Rule({ │ │ │ │ │ - 'symbolizer': { │ │ │ │ │ - "Point": this.labelSymbolizer, │ │ │ │ │ - "Line": this.lineSymbolizer │ │ │ │ │ - } │ │ │ │ │ - })] │ │ │ │ │ - }); │ │ │ │ │ - this.gratLayer = new OpenLayers.Layer.Vector(this.layerName, { │ │ │ │ │ - styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ - 'default': gratStyle │ │ │ │ │ - }), │ │ │ │ │ - visibility: this.visible, │ │ │ │ │ - displayInLayerSwitcher: this.displayInLayerSwitcher │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return this.div; │ │ │ │ │ + passEventToSlider: function(evt) { │ │ │ │ │ + this.sliderEvents.handleBrowserEvent(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarDown │ │ │ │ │ + * event listener for clicks on the slider │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.map.addLayer(this.gratLayer); │ │ │ │ │ - this.map.events.register('moveend', this, this.update); │ │ │ │ │ - this.update(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + zoomBarDown: function(evt) { │ │ │ │ │ + if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "touchmove": this.passEventToSlider, │ │ │ │ │ + "mousemove": this.passEventToSlider, │ │ │ │ │ + "mouseup": this.passEventToSlider, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ + this.zoomStart = evt.xy.clone(); │ │ │ │ │ + this.div.style.cursor = "move"; │ │ │ │ │ + // reset the div offsets just in case the div moved │ │ │ │ │ + this.zoombarDiv.offsets = null; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarDrag │ │ │ │ │ + * This is what happens when a click has occurred, and the client is │ │ │ │ │ + * dragging. Here we must ensure that the slider doesn't go beyond the │ │ │ │ │ + * bottom/top of the zoombar div, as well as moving the slider to its new │ │ │ │ │ + * visual location │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.map.events.unregister('moveend', this, this.update); │ │ │ │ │ - this.map.removeLayer(this.gratLayer); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + zoomBarDrag: function(evt) { │ │ │ │ │ + if (this.mouseDragStart != null) { │ │ │ │ │ + var deltaY = this.mouseDragStart.y - evt.xy.y; │ │ │ │ │ + var offsets = OpenLayers.Util.pagePosition(this.zoombarDiv); │ │ │ │ │ + if ((evt.clientY - offsets[1]) > 0 && │ │ │ │ │ + (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { │ │ │ │ │ + var newTop = parseInt(this.slider.style.top) - deltaY; │ │ │ │ │ + this.slider.style.top = newTop + "px"; │ │ │ │ │ + this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ + } │ │ │ │ │ + // set cumulative displacement │ │ │ │ │ + this.deltaY = this.zoomStart.y - evt.xy.y; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ - /** │ │ │ │ │ - * Method: update │ │ │ │ │ + │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarUp │ │ │ │ │ + * Perform cleanup when a mouseup event is received -- discover new zoom │ │ │ │ │ + * level and switch to it. │ │ │ │ │ * │ │ │ │ │ - * calculates the grid to be displayed and actually draws it │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - //wait for the map to be initialized before proceeding │ │ │ │ │ - var mapBounds = this.map.getExtent(); │ │ │ │ │ - if (!mapBounds) { │ │ │ │ │ + zoomBarUp: function(evt) { │ │ │ │ │ + if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") { │ │ │ │ │ return; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //clear out the old grid │ │ │ │ │ - this.gratLayer.destroyFeatures(); │ │ │ │ │ - │ │ │ │ │ - //get the projection objects required │ │ │ │ │ - var llProj = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - var mapProj = this.map.getProjectionObject(); │ │ │ │ │ - var mapRes = this.map.getResolution(); │ │ │ │ │ - │ │ │ │ │ - //if the map is in lon/lat, then the lines are straight and only one │ │ │ │ │ - //point is required │ │ │ │ │ - if (mapProj.proj && mapProj.proj.projName == "longlat") { │ │ │ │ │ - this.numPoints = 1; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //get the map center in EPSG:4326 │ │ │ │ │ - var mapCenter = this.map.getCenter(); //lon and lat here are really map x and y │ │ │ │ │ - var mapCenterLL = new OpenLayers.Pixel(mapCenter.lon, mapCenter.lat); │ │ │ │ │ - OpenLayers.Projection.transform(mapCenterLL, mapProj, llProj); │ │ │ │ │ - │ │ │ │ │ - /* This block of code determines the lon/lat interval to use for the │ │ │ │ │ - * grid by calculating the diagonal size of one grid cell at the map │ │ │ │ │ - * center. Iterates through the intervals array until the diagonal │ │ │ │ │ - * length is less than the targetSize option. │ │ │ │ │ - */ │ │ │ │ │ - //find lat/lon interval that results in a grid of less than the target size │ │ │ │ │ - var testSq = this.targetSize * mapRes; │ │ │ │ │ - testSq *= testSq; //compare squares rather than doing a square root to save time │ │ │ │ │ - var llInterval; │ │ │ │ │ - for (var i = 0; i < this.intervals.length; ++i) { │ │ │ │ │ - llInterval = this.intervals[i]; //could do this for both x and y?? │ │ │ │ │ - var delta = llInterval / 2; │ │ │ │ │ - var p1 = mapCenterLL.offset({ │ │ │ │ │ - x: -delta, │ │ │ │ │ - y: -delta │ │ │ │ │ - }); //test coords in EPSG:4326 space │ │ │ │ │ - var p2 = mapCenterLL.offset({ │ │ │ │ │ - x: delta, │ │ │ │ │ - y: delta │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Projection.transform(p1, llProj, mapProj); // convert them back to map projection │ │ │ │ │ - OpenLayers.Projection.transform(p2, llProj, mapProj); │ │ │ │ │ - var distSq = (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y); │ │ │ │ │ - if (distSq <= testSq) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - //alert(llInterval); │ │ │ │ │ - │ │ │ │ │ - //round the LL center to an even number based on the interval │ │ │ │ │ - mapCenterLL.x = Math.floor(mapCenterLL.x / llInterval) * llInterval; │ │ │ │ │ - mapCenterLL.y = Math.floor(mapCenterLL.y / llInterval) * llInterval; │ │ │ │ │ - //TODO adjust for minutses/seconds? │ │ │ │ │ - │ │ │ │ │ - /* The following 2 blocks calculate the nodes of the grid along a │ │ │ │ │ - * line of constant longitude (then latitiude) running through the │ │ │ │ │ - * center of the map until it reaches the map edge. The calculation │ │ │ │ │ - * goes from the center in both directions to the edge. │ │ │ │ │ - */ │ │ │ │ │ - //get the central longitude line, increment the latitude │ │ │ │ │ - var iter = 0; │ │ │ │ │ - var centerLonPoints = [mapCenterLL.clone()]; │ │ │ │ │ - var newPoint = mapCenterLL.clone(); │ │ │ │ │ - var mapXY; │ │ │ │ │ - do { │ │ │ │ │ - newPoint = newPoint.offset({ │ │ │ │ │ - x: 0, │ │ │ │ │ - y: llInterval │ │ │ │ │ - }); │ │ │ │ │ - mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); │ │ │ │ │ - centerLonPoints.unshift(newPoint); │ │ │ │ │ - } while (mapBounds.containsPixel(mapXY) && ++iter < 1000); │ │ │ │ │ - newPoint = mapCenterLL.clone(); │ │ │ │ │ - do { │ │ │ │ │ - newPoint = newPoint.offset({ │ │ │ │ │ - x: 0, │ │ │ │ │ - y: -llInterval │ │ │ │ │ - }); │ │ │ │ │ - mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); │ │ │ │ │ - centerLonPoints.push(newPoint); │ │ │ │ │ - } while (mapBounds.containsPixel(mapXY) && ++iter < 1000); │ │ │ │ │ - │ │ │ │ │ - //get the central latitude line, increment the longitude │ │ │ │ │ - iter = 0; │ │ │ │ │ - var centerLatPoints = [mapCenterLL.clone()]; │ │ │ │ │ - newPoint = mapCenterLL.clone(); │ │ │ │ │ - do { │ │ │ │ │ - newPoint = newPoint.offset({ │ │ │ │ │ - x: -llInterval, │ │ │ │ │ - y: 0 │ │ │ │ │ - }); │ │ │ │ │ - mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); │ │ │ │ │ - centerLatPoints.unshift(newPoint); │ │ │ │ │ - } while (mapBounds.containsPixel(mapXY) && ++iter < 1000); │ │ │ │ │ - newPoint = mapCenterLL.clone(); │ │ │ │ │ - do { │ │ │ │ │ - newPoint = newPoint.offset({ │ │ │ │ │ - x: llInterval, │ │ │ │ │ - y: 0 │ │ │ │ │ + if (this.mouseDragStart) { │ │ │ │ │ + this.div.style.cursor = ""; │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "touchmove": this.passEventToSlider, │ │ │ │ │ + "mouseup": this.passEventToSlider, │ │ │ │ │ + "mousemove": this.passEventToSlider, │ │ │ │ │ + scope: this │ │ │ │ │ }); │ │ │ │ │ - mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); │ │ │ │ │ - centerLatPoints.push(newPoint); │ │ │ │ │ - } while (mapBounds.containsPixel(mapXY) && ++iter < 1000); │ │ │ │ │ - │ │ │ │ │ - //now generate a line for each node in the central lat and lon lines │ │ │ │ │ - //first loop over constant longitude │ │ │ │ │ - var lines = []; │ │ │ │ │ - for (var i = 0; i < centerLatPoints.length; ++i) { │ │ │ │ │ - var lon = centerLatPoints[i].x; │ │ │ │ │ - var pointList = []; │ │ │ │ │ - var labelPoint = null; │ │ │ │ │ - var latEnd = Math.min(centerLonPoints[0].y, 90); │ │ │ │ │ - var latStart = Math.max(centerLonPoints[centerLonPoints.length - 1].y, -90); │ │ │ │ │ - var latDelta = (latEnd - latStart) / this.numPoints; │ │ │ │ │ - var lat = latStart; │ │ │ │ │ - for (var j = 0; j <= this.numPoints; ++j) { │ │ │ │ │ - var gridPoint = new OpenLayers.Geometry.Point(lon, lat); │ │ │ │ │ - gridPoint.transform(llProj, mapProj); │ │ │ │ │ - pointList.push(gridPoint); │ │ │ │ │ - lat += latDelta; │ │ │ │ │ - if (gridPoint.y >= mapBounds.bottom && !labelPoint) { │ │ │ │ │ - labelPoint = gridPoint; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.labelled) { │ │ │ │ │ - //keep track of when this grid line crosses the map bounds to set │ │ │ │ │ - //the label position │ │ │ │ │ - //labels along the bottom, add 10 pixel offset up into the map │ │ │ │ │ - //TODO add option for labels on top │ │ │ │ │ - var labelPos = new OpenLayers.Geometry.Point(labelPoint.x, mapBounds.bottom); │ │ │ │ │ - var labelAttrs = { │ │ │ │ │ - value: lon, │ │ │ │ │ - label: this.labelled ? OpenLayers.Util.getFormattedLonLat(lon, "lon", this.labelFormat) : "", │ │ │ │ │ - labelAlign: "cb", │ │ │ │ │ - xOffset: 0, │ │ │ │ │ - yOffset: 2 │ │ │ │ │ - }; │ │ │ │ │ - this.gratLayer.addFeatures(new OpenLayers.Feature.Vector(labelPos, labelAttrs)); │ │ │ │ │ + var zoomLevel = this.map.zoom; │ │ │ │ │ + if (!this.forceFixedZoomLevel && this.map.fractionalZoom) { │ │ │ │ │ + zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ + zoomLevel = Math.min(Math.max(zoomLevel, 0), │ │ │ │ │ + this.map.getNumZoomLevels() - 1); │ │ │ │ │ + } else { │ │ │ │ │ + zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ + zoomLevel = Math.max(Math.round(zoomLevel), 0); │ │ │ │ │ } │ │ │ │ │ - var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ - lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ + this.map.zoomTo(zoomLevel); │ │ │ │ │ + this.mouseDragStart = null; │ │ │ │ │ + this.zoomStart = null; │ │ │ │ │ + this.deltaY = 0; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //now draw the lines of constant latitude │ │ │ │ │ - for (var j = 0; j < centerLonPoints.length; ++j) { │ │ │ │ │ - lat = centerLonPoints[j].y; │ │ │ │ │ - if (lat < -90 || lat > 90) { //latitudes only valid between -90 and 90 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - var pointList = []; │ │ │ │ │ - var lonStart = centerLatPoints[0].x; │ │ │ │ │ - var lonEnd = centerLatPoints[centerLatPoints.length - 1].x; │ │ │ │ │ - var lonDelta = (lonEnd - lonStart) / this.numPoints; │ │ │ │ │ - var lon = lonStart; │ │ │ │ │ - var labelPoint = null; │ │ │ │ │ - for (var i = 0; i <= this.numPoints; ++i) { │ │ │ │ │ - var gridPoint = new OpenLayers.Geometry.Point(lon, lat); │ │ │ │ │ - gridPoint.transform(llProj, mapProj); │ │ │ │ │ - pointList.push(gridPoint); │ │ │ │ │ - lon += lonDelta; │ │ │ │ │ - if (gridPoint.x < mapBounds.right) { │ │ │ │ │ - labelPoint = gridPoint; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.labelled) { │ │ │ │ │ - //keep track of when this grid line crosses the map bounds to set │ │ │ │ │ - //the label position │ │ │ │ │ - //labels along the right, 30 pixel offset left into the map │ │ │ │ │ - //TODO add option for labels on left │ │ │ │ │ - var labelPos = new OpenLayers.Geometry.Point(mapBounds.right, labelPoint.y); │ │ │ │ │ - var labelAttrs = { │ │ │ │ │ - value: lat, │ │ │ │ │ - label: this.labelled ? OpenLayers.Util.getFormattedLonLat(lat, "lat", this.labelFormat) : "", │ │ │ │ │ - labelAlign: "rb", │ │ │ │ │ - xOffset: -2, │ │ │ │ │ - yOffset: 2 │ │ │ │ │ - }; │ │ │ │ │ - this.gratLayer.addFeatures(new OpenLayers.Feature.Vector(labelPos, labelAttrs)); │ │ │ │ │ - } │ │ │ │ │ - var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ - lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ - } │ │ │ │ │ - this.gratLayer.addFeatures(lines); │ │ │ │ │ + /* │ │ │ │ │ + * Method: moveZoomBar │ │ │ │ │ + * Change the location of the slider to match the current zoom level. │ │ │ │ │ + */ │ │ │ │ │ + moveZoomBar: function() { │ │ │ │ │ + var newTop = │ │ │ │ │ + ((this.map.getNumZoomLevels() - 1) - this.map.getZoom()) * │ │ │ │ │ + this.zoomStopHeight + this.startTop + 1; │ │ │ │ │ + this.slider.style.top = newTop + "px"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Graticule" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.PanZoomBar" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Layer/Vector/RootContainer.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 │ │ │ │ │ @@ -55677,10744 +48189,11219 @@ │ │ │ │ │ this.activate(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.SelectFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/KeyboardDefaults.js │ │ │ │ │ + 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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ - * The KeyboardDefaults control adds panning and zooming functions, controlled │ │ │ │ │ - * with the keyboard. By default arrow keys pan, +/- keys zoom & Page Up/Page │ │ │ │ │ - * Down/Home/End scroll by three quarters of a page. │ │ │ │ │ - * │ │ │ │ │ - * This control has no visible appearance. │ │ │ │ │ + * 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.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + started: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * Pixels to slide by. │ │ │ │ │ + * Property: stopDown │ │ │ │ │ + * {Boolean} Stop propagation of touchstart events from getting to │ │ │ │ │ + * listeners on the same element. Default is false. │ │ │ │ │ */ │ │ │ │ │ - slideFactor: 75, │ │ │ │ │ + stopDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: observeElement │ │ │ │ │ - * {DOMelement|String} The DOM element to handle keys for. You │ │ │ │ │ - * can use the map div here, to have the navigation keys │ │ │ │ │ - * work when the map div has the focus. If undefined the │ │ │ │ │ - * document is used. │ │ │ │ │ + * Property: pinching │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ + pinching: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ + * Property: last │ │ │ │ │ + * {Object} Object that store informations related to pinch last touch. │ │ │ │ │ */ │ │ │ │ │ + last: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Create handler. │ │ │ │ │ + * Property: start │ │ │ │ │ + * {Object} Object that store informations related to pinch touchstart. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var observeElement = this.observeElement || document; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Keyboard(this, { │ │ │ │ │ - "keydown": this.defaultKeyPress │ │ │ │ │ - }, { │ │ │ │ │ - observeElement: observeElement │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + start: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultKeyPress │ │ │ │ │ - * When handling the key event, we only use evt.keyCode. This holds │ │ │ │ │ - * some drawbacks, though we get around them below. When interpretting │ │ │ │ │ - * the keycodes below (including the comments associated with them), │ │ │ │ │ - * consult the URL below. For instance, the Safari browser returns │ │ │ │ │ - * "IE keycodes", and so is supported by any keycode labeled "IE". │ │ │ │ │ - * │ │ │ │ │ - * Very informative URL: │ │ │ │ │ - * http://unixpapa.com/js/key.html │ │ │ │ │ + * Constructor: OpenLayers.Handler.Pinch │ │ │ │ │ + * Returns OpenLayers.Handler.Pinch │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - defaultKeyPress: function(evt) { │ │ │ │ │ - var size, handled = true; │ │ │ │ │ │ │ │ │ │ - var target = OpenLayers.Event.element(evt); │ │ │ │ │ - if (target && │ │ │ │ │ - (target.tagName == 'INPUT' || │ │ │ │ │ - target.tagName == 'TEXTAREA' || │ │ │ │ │ - target.tagName == 'SELECT')) { │ │ │ │ │ - return; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + } else { │ │ │ │ │ + this.started = false; │ │ │ │ │ + this.start = null; │ │ │ │ │ + this.last = null; │ │ │ │ │ } │ │ │ │ │ + // prevent document dragging │ │ │ │ │ + OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + return propagate; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - switch (evt.keyCode) { │ │ │ │ │ - case OpenLayers.Event.KEY_LEFT: │ │ │ │ │ - this.map.pan(-this.slideFactor, 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_RIGHT: │ │ │ │ │ - this.map.pan(this.slideFactor, 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_UP: │ │ │ │ │ - this.map.pan(0, -this.slideFactor); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_DOWN: │ │ │ │ │ - this.map.pan(0, this.slideFactor); │ │ │ │ │ - break; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - case 33: // Page Up. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0, -0.75 * size.h); │ │ │ │ │ - break; │ │ │ │ │ - case 34: // Page Down. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0, 0.75 * size.h); │ │ │ │ │ - break; │ │ │ │ │ - case 35: // End. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0.75 * size.w, 0); │ │ │ │ │ - break; │ │ │ │ │ - case 36: // Home. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(-0.75 * size.w, 0); │ │ │ │ │ - break; │ │ │ │ │ + /** │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Handle touchend events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - case 43: // +/= (ASCII), keypad + (ASCII, Opera) │ │ │ │ │ - case 61: // +/= (Mozilla, Opera, some ASCII) │ │ │ │ │ - case 187: // +/= (IE) │ │ │ │ │ - case 107: // keypad + (IE, Mozilla) │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - break; │ │ │ │ │ - case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) │ │ │ │ │ - case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) │ │ │ │ │ - case 189: // -/_ (IE) │ │ │ │ │ - case 95: // -/_ (some ASCII) │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - handled = false; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - if (handled) { │ │ │ │ │ - // prevent browser default not to move the page │ │ │ │ │ - // when moving the page with the keyboard │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ + return activated; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" │ │ │ │ │ + /** │ │ │ │ │ + * Method: getDistance │ │ │ │ │ + * Get the distance in pixels between two touches. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * touches - {Array(Object)} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The distance in pixels. │ │ │ │ │ + */ │ │ │ │ │ + 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) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getPinchData │ │ │ │ │ + * Get informations about the pinch event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Object that contains data about the current pinch. │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Pinch" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ScaleLine.js │ │ │ │ │ + OpenLayers/Control/PinchZoom.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Pinch.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ScaleLine │ │ │ │ │ - * The ScaleLine displays a small line indicator representing the current │ │ │ │ │ - * map scale on the map. By default it is drawn in the lower left corner of │ │ │ │ │ - * the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ + * Class: OpenLayers.Control.PinchZoom │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ * - │ │ │ │ │ - * │ │ │ │ │ - * Is a very close copy of: │ │ │ │ │ - * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ScaleLine = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: maxWidth │ │ │ │ │ - * {Integer} Maximum width of the scale line in pixels. Default is 100. │ │ │ │ │ - */ │ │ │ │ │ - maxWidth: 100, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: topOutUnits │ │ │ │ │ - * {String} Units for zoomed out on top bar. Default is km. │ │ │ │ │ - */ │ │ │ │ │ - topOutUnits: "km", │ │ │ │ │ +OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: topInUnits │ │ │ │ │ - * {String} Units for zoomed in on top bar. Default is m. │ │ │ │ │ + /** │ │ │ │ │ + * Property: type │ │ │ │ │ + * {OpenLayers.Control.TYPES} │ │ │ │ │ */ │ │ │ │ │ - topInUnits: "m", │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: bottomOutUnits │ │ │ │ │ - * {String} Units for zoomed out on bottom bar. Default is mi. │ │ │ │ │ + * Property: pinchOrigin │ │ │ │ │ + * {Object} Cached object representing the pinch start (in pixels). │ │ │ │ │ */ │ │ │ │ │ - bottomOutUnits: "mi", │ │ │ │ │ + pinchOrigin: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: bottomInUnits │ │ │ │ │ - * {String} Units for zoomed in on bottom bar. Default is ft. │ │ │ │ │ + * Property: currentCenter │ │ │ │ │ + * {Object} Cached object representing the latest pinch center (in pixels). │ │ │ │ │ */ │ │ │ │ │ - bottomInUnits: "ft", │ │ │ │ │ + currentCenter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: eTop │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - eTop: null, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: eBottom │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIProperty: preserveCenter │ │ │ │ │ + * {Boolean} Set this to true if you don't want the map center to change │ │ │ │ │ + * while pinching. For example you may want to set preserveCenter to │ │ │ │ │ + * true when the user location is being watched and you want to preserve │ │ │ │ │ + * the user location at the center of the map even if he zooms in or │ │ │ │ │ + * out using pinch. This property's value can be changed any time on an │ │ │ │ │ + * existing instance. Default is false. │ │ │ │ │ */ │ │ │ │ │ - eBottom: null, │ │ │ │ │ + preserveCenter: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ - * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ - * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ - * pixel in the center of the map viewport. │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the pinch handler │ │ │ │ │ */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ScaleLine │ │ │ │ │ - * Create a new scale line control. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.PinchZoom │ │ │ │ │ + * Create a control for zooming with pinch gestures. This works on devices │ │ │ │ │ + * with multi-touch support. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * the control │ │ │ │ │ */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.handler = new OpenLayers.Handler.Pinch(this, { │ │ │ │ │ + start: this.pinchStart, │ │ │ │ │ + move: this.pinchMove, │ │ │ │ │ + done: this.pinchDone │ │ │ │ │ + }, this.handlerOptions); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Method: pinchStart │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ + * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (!this.eTop) { │ │ │ │ │ - // stick in the top bar │ │ │ │ │ - this.eTop = document.createElement("div"); │ │ │ │ │ - this.eTop.className = this.displayClass + "Top"; │ │ │ │ │ - var theLen = this.topInUnits.length; │ │ │ │ │ - this.div.appendChild(this.eTop); │ │ │ │ │ - if ((this.topOutUnits == "") || (this.topInUnits == "")) { │ │ │ │ │ - this.eTop.style.visibility = "hidden"; │ │ │ │ │ - } else { │ │ │ │ │ - this.eTop.style.visibility = "visible"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // and the bottom bar │ │ │ │ │ - this.eBottom = document.createElement("div"); │ │ │ │ │ - this.eBottom.className = this.displayClass + "Bottom"; │ │ │ │ │ - this.div.appendChild(this.eBottom); │ │ │ │ │ - if ((this.bottomOutUnits == "") || (this.bottomInUnits == "")) { │ │ │ │ │ - this.eBottom.style.visibility = "hidden"; │ │ │ │ │ - } else { │ │ │ │ │ - this.eBottom.style.visibility = "visible"; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.map.events.register('moveend', this, this.update); │ │ │ │ │ - this.update(); │ │ │ │ │ - return this.div; │ │ │ │ │ + pinchStart: function(evt, pinchData) { │ │ │ │ │ + var xy = (this.preserveCenter) ? │ │ │ │ │ + this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ + this.pinchOrigin = xy; │ │ │ │ │ + this.currentCenter = xy; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getBarLen │ │ │ │ │ - * Given a number, round it down to the nearest 1,2,5 times a power of 10. │ │ │ │ │ - * That seems a fairly useful set of number groups to use. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: pinchMove │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * maxLen - {float} the number we're rounding down from │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} the rounded number (less than or equal to maxLen) │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ + * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ */ │ │ │ │ │ - getBarLen: function(maxLen) { │ │ │ │ │ - // nearest power of 10 lower than maxLen │ │ │ │ │ - var digits = parseInt(Math.log(maxLen) / Math.log(10)); │ │ │ │ │ - var pow10 = Math.pow(10, digits); │ │ │ │ │ - │ │ │ │ │ - // ok, find first character │ │ │ │ │ - var firstChar = parseInt(maxLen / pow10); │ │ │ │ │ + pinchMove: function(evt, pinchData) { │ │ │ │ │ + var scale = pinchData.scale; │ │ │ │ │ + var containerOrigin = this.map.layerContainerOriginPx; │ │ │ │ │ + var pinchOrigin = this.pinchOrigin; │ │ │ │ │ + var current = (this.preserveCenter) ? │ │ │ │ │ + this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ │ │ │ │ │ - // right, put it into the correct bracket │ │ │ │ │ - var barLen; │ │ │ │ │ - if (firstChar > 5) { │ │ │ │ │ - barLen = 5; │ │ │ │ │ - } else if (firstChar > 2) { │ │ │ │ │ - barLen = 2; │ │ │ │ │ - } else { │ │ │ │ │ - barLen = 1; │ │ │ │ │ - } │ │ │ │ │ + var dx = Math.round((containerOrigin.x + current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x)); │ │ │ │ │ + var dy = Math.round((containerOrigin.y + current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y)); │ │ │ │ │ │ │ │ │ │ - // scale it up the correct power of 10 │ │ │ │ │ - return barLen * pow10; │ │ │ │ │ + this.map.applyTransform(dx, dy, scale); │ │ │ │ │ + this.currentCenter = current; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Update the size of the bars, and the labels they contain. │ │ │ │ │ + * Method: pinchDone │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * start - {Object} pinch data object related to the touchstart event that │ │ │ │ │ + * started the pinch gesture. │ │ │ │ │ + * last - {Object} pinch data object related to the last touchmove event │ │ │ │ │ + * of the pinch gesture. This give us the final scale of the pinch. │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - var res = this.map.getResolution(); │ │ │ │ │ - if (!res) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var curMapUnits = this.map.getUnits(); │ │ │ │ │ - var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ - │ │ │ │ │ - // convert maxWidth to map units │ │ │ │ │ - var maxSizeData = this.maxWidth * res * inches[curMapUnits]; │ │ │ │ │ - var geodesicRatio = 1; │ │ │ │ │ - if (this.geodesic === true) { │ │ │ │ │ - var maxSizeGeodesic = (this.map.getGeodesicPixelSize().w || │ │ │ │ │ - 0.000001) * this.maxWidth; │ │ │ │ │ - var maxSizeKilometers = maxSizeData / inches["km"]; │ │ │ │ │ - geodesicRatio = maxSizeGeodesic / maxSizeKilometers; │ │ │ │ │ - maxSizeData *= geodesicRatio; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // decide whether to use large or small scale units │ │ │ │ │ - var topUnits; │ │ │ │ │ - var bottomUnits; │ │ │ │ │ - if (maxSizeData > 100000) { │ │ │ │ │ - topUnits = this.topOutUnits; │ │ │ │ │ - bottomUnits = this.bottomOutUnits; │ │ │ │ │ - } else { │ │ │ │ │ - topUnits = this.topInUnits; │ │ │ │ │ - bottomUnits = this.bottomInUnits; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // and to map units units │ │ │ │ │ - var topMax = maxSizeData / inches[topUnits]; │ │ │ │ │ - var bottomMax = maxSizeData / inches[bottomUnits]; │ │ │ │ │ - │ │ │ │ │ - // now trim this down to useful block length │ │ │ │ │ - var topRounded = this.getBarLen(topMax); │ │ │ │ │ - var bottomRounded = this.getBarLen(bottomMax); │ │ │ │ │ - │ │ │ │ │ - // and back to display units │ │ │ │ │ - topMax = topRounded / inches[curMapUnits] * inches[topUnits]; │ │ │ │ │ - bottomMax = bottomRounded / inches[curMapUnits] * inches[bottomUnits]; │ │ │ │ │ + pinchDone: function(evt, start, last) { │ │ │ │ │ + this.map.applyTransform(); │ │ │ │ │ + var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true); │ │ │ │ │ + if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) { │ │ │ │ │ + var resolution = this.map.getResolutionForZoom(zoom); │ │ │ │ │ │ │ │ │ │ - // and to pixel units │ │ │ │ │ - var topPx = topMax / res / geodesicRatio; │ │ │ │ │ - var bottomPx = bottomMax / res / geodesicRatio; │ │ │ │ │ + var location = this.map.getLonLatFromPixel(this.pinchOrigin); │ │ │ │ │ + var zoomPixel = this.currentCenter; │ │ │ │ │ + var size = this.map.getSize(); │ │ │ │ │ │ │ │ │ │ - // now set the pixel widths │ │ │ │ │ - // and the values inside them │ │ │ │ │ + location.lon += resolution * ((size.w / 2) - zoomPixel.x); │ │ │ │ │ + location.lat -= resolution * ((size.h / 2) - zoomPixel.y); │ │ │ │ │ │ │ │ │ │ - if (this.eBottom.style.visibility == "visible") { │ │ │ │ │ - this.eBottom.style.width = Math.round(bottomPx) + "px"; │ │ │ │ │ - this.eBottom.innerHTML = bottomRounded + " " + bottomUnits; │ │ │ │ │ - } │ │ │ │ │ + // Force a reflow before calling setCenter. This is to work │ │ │ │ │ + // around an issue occuring in iOS. │ │ │ │ │ + // │ │ │ │ │ + // See https://github.com/openlayers/openlayers/pull/351. │ │ │ │ │ + // │ │ │ │ │ + // Without a reflow setting the layer container div's top left │ │ │ │ │ + // style properties to "0px" - as done in Map.moveTo when zoom │ │ │ │ │ + // is changed - won't actually correctly reposition the layer │ │ │ │ │ + // container div. │ │ │ │ │ + // │ │ │ │ │ + // Also, we need to use a statement that the Google Closure │ │ │ │ │ + // compiler won't optimize away. │ │ │ │ │ + this.map.div.clientWidth = this.map.div.clientWidth; │ │ │ │ │ │ │ │ │ │ - if (this.eTop.style.visibility == "visible") { │ │ │ │ │ - this.eTop.style.width = Math.round(topPx) + "px"; │ │ │ │ │ - this.eTop.innerHTML = topRounded + " " + topUnits; │ │ │ │ │ + this.map.setCenter(location, zoom); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ScaleLine" │ │ │ │ │ -}); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.PinchZoom" │ │ │ │ │ │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/WMTSGetFeatureInfo.js │ │ │ │ │ + OpenLayers/Control/TouchNavigation.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ + * @requires OpenLayers/Control/PinchZoom.js │ │ │ │ │ * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.WMTSGetFeatureInfo │ │ │ │ │ - * The WMTSGetFeatureInfo control uses a WMTS query to get information about a │ │ │ │ │ - * point on the map. The information may be in a display-friendly format │ │ │ │ │ - * such as HTML, or a machine-friendly format such as GML, depending on the │ │ │ │ │ - * server's capabilities and the client's configuration. This control │ │ │ │ │ - * handles click or hover events, attempts to parse the results using an │ │ │ │ │ - * OpenLayers.Format, and fires a 'getfeatureinfo' event for each layer │ │ │ │ │ - * queried. │ │ │ │ │ + * Class: OpenLayers.Control.TouchNavigation │ │ │ │ │ + * The navigation control handles map browsing with touch events (dragging, │ │ │ │ │ + * double-tapping, tap with two fingers, and pinch zoom). Create a new │ │ │ │ │ + * control with the constructor. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ + * If you’re only targeting touch enabled devices with your mapping application, │ │ │ │ │ + * you can create a map with only a TouchNavigation control. The │ │ │ │ │ + * control is mobile ready by default, but │ │ │ │ │ + * you can generate a smaller build of the library by only including this │ │ │ │ │ + * touch navigation control if you aren't concerned about mouse interaction. │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: dragPan │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + dragPan: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: requestEncoding │ │ │ │ │ - * {String} One of "KVP" or "REST". Only KVP encoding is supported at this │ │ │ │ │ - * time. │ │ │ │ │ + * APIProperty: dragPanOptions │ │ │ │ │ + * {Object} Options passed to the DragPan control. │ │ │ │ │ */ │ │ │ │ │ - requestEncoding: "KVP", │ │ │ │ │ + dragPanOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: drillDown │ │ │ │ │ - * {Boolean} Drill down over all WMTS layers in the map. When │ │ │ │ │ - * using drillDown mode, hover is not possible. A getfeatureinfo event │ │ │ │ │ - * will be fired for each layer queried. │ │ │ │ │ + * Property: pinchZoom │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - drillDown: false, │ │ │ │ │ + pinchZoom: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a WMTS query. This │ │ │ │ │ - * sets the feature_count parameter on WMTS GetFeatureInfo │ │ │ │ │ - * requests. │ │ │ │ │ + * APIProperty: pinchZoomOptions │ │ │ │ │ + * {Object} Options passed to the PinchZoom control. │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ + pinchZoomOptions: null, │ │ │ │ │ │ │ │ │ │ - /** APIProperty: clickCallback │ │ │ │ │ - * {String} The click callback to register in the │ │ │ │ │ - * {} object created when the hover │ │ │ │ │ - * option is set to false. Default is "click". │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: clickHandlerOptions │ │ │ │ │ + * {Object} Options passed to the Click handler. │ │ │ │ │ */ │ │ │ │ │ - clickCallback: "click", │ │ │ │ │ + clickHandlerOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layers │ │ │ │ │ - * {Array()} The layers to query for feature info. │ │ │ │ │ - * If omitted, all map WMTS layers will be considered. │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: queryVisible │ │ │ │ │ - * {Boolean} Filter out hidden layers when searching the map for layers to │ │ │ │ │ - * query. Default is true. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - queryVisible: true, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: infoFormat │ │ │ │ │ - * {String} The mimetype to request from the server │ │ │ │ │ + * Constructor: OpenLayers.Control.TouchNavigation │ │ │ │ │ + * Create a new navigation control │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * the control │ │ │ │ │ */ │ │ │ │ │ - infoFormat: 'text/html', │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: vendorParams │ │ │ │ │ - * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ - * WMTS implementations that support them. This could e.g. look like │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * radius: 5 │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - vendorParams: {}, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + if (this.dragPan) { │ │ │ │ │ + this.dragPan.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.dragPan = null; │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.destroy(); │ │ │ │ │ + delete this.pinchZoom; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ - * Default is . │ │ │ │ │ + * Method: activate │ │ │ │ │ */ │ │ │ │ │ - format: null, │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragPan.activate(); │ │ │ │ │ + this.handlers.click.activate(); │ │ │ │ │ + this.pinchZoom.activate(); │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: formatOptions │ │ │ │ │ - * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ - * in the property. │ │ │ │ │ + * Method: deactivate │ │ │ │ │ */ │ │ │ │ │ - formatOptions: null, │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.dragPan.deactivate(); │ │ │ │ │ + this.handlers.click.deactivate(); │ │ │ │ │ + this.pinchZoom.deactivate(); │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * "click": {delay: 100}, │ │ │ │ │ - * "hover": {delay: 300} │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Method: draw │ │ │ │ │ */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + var clickCallbacks = { │ │ │ │ │ + click: this.defaultClick, │ │ │ │ │ + dblclick: this.defaultDblClick │ │ │ │ │ + }; │ │ │ │ │ + var clickOptions = OpenLayers.Util.extend({ │ │ │ │ │ + "double": true, │ │ │ │ │ + stopDouble: true, │ │ │ │ │ + pixelTolerance: 2 │ │ │ │ │ + }, this.clickHandlerOptions); │ │ │ │ │ + this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ + this, clickCallbacks, clickOptions │ │ │ │ │ + ); │ │ │ │ │ + this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map, │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + }, this.dragPanOptions) │ │ │ │ │ + ); │ │ │ │ │ + this.dragPan.draw(); │ │ │ │ │ + this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map │ │ │ │ │ + }, this.pinchZoomOptions) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {Object} Reference to the for this control │ │ │ │ │ + * Method: defaultClick │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + defaultClick: function(evt) { │ │ │ │ │ + if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverRequest │ │ │ │ │ - * {} contains the currently running hover request │ │ │ │ │ - * (if any). │ │ │ │ │ - */ │ │ │ │ │ - hoverRequest: 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) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforegetfeatureinfo - Triggered before each request is sent. │ │ │ │ │ - * The event object has an *xy* property with the position of the │ │ │ │ │ - * mouse click or hover event that triggers the request and a *layer* │ │ │ │ │ - * property referencing the layer about to be queried. If a listener │ │ │ │ │ - * returns false, the request will not be issued. │ │ │ │ │ - * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ - * The event object has a *text* property with the body of the │ │ │ │ │ - * response (String), a *features* property with an array of the │ │ │ │ │ - * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ - * click or hover event that triggered the request, a *layer* property │ │ │ │ │ - * referencing the layer queried and a *request* property with the │ │ │ │ │ - * request itself. If drillDown is set to true, one event will be fired │ │ │ │ │ - * for each layer queried. │ │ │ │ │ - * exception - Triggered when a GetFeatureInfo request fails (with a │ │ │ │ │ - * status other than 200) or whenparsing fails. Listeners will receive │ │ │ │ │ - * an event with *request*, *xy*, and *layer* properties. In the case │ │ │ │ │ - * of a parsing error, the event will also contain an *error* property. │ │ │ │ │ + * Method: defaultDblClick │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ + defaultDblClick: function(evt) { │ │ │ │ │ + this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: pending │ │ │ │ │ - * {Number} The number of pending requests. │ │ │ │ │ - */ │ │ │ │ │ - pending: 0, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.TouchNavigation" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (!this.format) { │ │ │ │ │ - this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ - options.formatOptions │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ + * Class to read GetFeatureInfo responses from Web Mapping Services │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ - if (this.drillDown === true) { │ │ │ │ │ - this.hover = false; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of layer nodes. │ │ │ │ │ + */ │ │ │ │ │ + layerIdentifier: '_layer', │ │ │ │ │ │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - move: this.cancelHover, │ │ │ │ │ - pause: this.getInfoForHover │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend( │ │ │ │ │ - this.handlerOptions.hover || {}, { │ │ │ │ │ - delay: 250 │ │ │ │ │ - } │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - var callbacks = {}; │ │ │ │ │ - callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, callbacks, this.handlerOptions.click || {} │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: featureIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of feature nodes for each layer node found. │ │ │ │ │ + */ │ │ │ │ │ + featureIdentifier: '_feature', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ + */ │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForClick │ │ │ │ │ - * Called on click │ │ │ │ │ + * Property: gmlFormat │ │ │ │ │ + * {} internal GML format for parsing geometries │ │ │ │ │ + * in msGMLOutput │ │ │ │ │ + */ │ │ │ │ │ + gmlFormat: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ + * Create a new parser for WMS GetFeatureInfo responses │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - getInfoForClick: function(evt) { │ │ │ │ │ - this.request(evt.xy, {}); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForHover │ │ │ │ │ - * Pause callback for the hover handler │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read WMS GetFeatureInfo data from a string, and return an array of features │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - getInfoForHover: function(evt) { │ │ │ │ │ - this.request(evt.xy, { │ │ │ │ │ - hover: true │ │ │ │ │ - }); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + var result; │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + var root = data.documentElement; │ │ │ │ │ + if (root) { │ │ │ │ │ + var scope = this; │ │ │ │ │ + var read = this["read_" + root.nodeName]; │ │ │ │ │ + if (read) { │ │ │ │ │ + result = read.call(this, root); │ │ │ │ │ + } else { │ │ │ │ │ + // fall-back to GML since this is a common output format for WMS │ │ │ │ │ + // GetFeatureInfo responses │ │ │ │ │ + result = new OpenLayers.Format.GML((this.options ? this.options : {})).read(data); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + result = data; │ │ │ │ │ + } │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelHover │ │ │ │ │ - * Cancel callback for the hover handler │ │ │ │ │ + * Method: read_msGMLOutput │ │ │ │ │ + * Parse msGMLOutput nodes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - cancelHover: function() { │ │ │ │ │ - if (this.hoverRequest) { │ │ │ │ │ - --this.pending; │ │ │ │ │ - if (this.pending <= 0) { │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.pending = 0; │ │ │ │ │ + read_msGMLOutput: function(data) { │ │ │ │ │ + var response = []; │ │ │ │ │ + var layerNodes = this.getSiblingNodesByTagCriteria(data, │ │ │ │ │ + this.layerIdentifier); │ │ │ │ │ + if (layerNodes) { │ │ │ │ │ + for (var i = 0, len = layerNodes.length; i < len; ++i) { │ │ │ │ │ + var node = layerNodes[i]; │ │ │ │ │ + var layerName = node.nodeName; │ │ │ │ │ + if (node.prefix) { │ │ │ │ │ + layerName = layerName.split(':')[1]; │ │ │ │ │ + } │ │ │ │ │ + var layerName = layerName.replace(this.layerIdentifier, ''); │ │ │ │ │ + var featureNodes = this.getSiblingNodesByTagCriteria(node, │ │ │ │ │ + this.featureIdentifier); │ │ │ │ │ + if (featureNodes) { │ │ │ │ │ + for (var j = 0; j < featureNodes.length; j++) { │ │ │ │ │ + var featureNode = featureNodes[j]; │ │ │ │ │ + var geomInfo = this.parseGeometry(featureNode); │ │ │ │ │ + var attributes = this.parseAttributes(featureNode); │ │ │ │ │ + var feature = new OpenLayers.Feature.Vector(geomInfo.geometry, │ │ │ │ │ + attributes, null); │ │ │ │ │ + feature.bounds = geomInfo.bounds; │ │ │ │ │ + feature.type = layerName; │ │ │ │ │ + response.push(feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.hoverRequest.abort(); │ │ │ │ │ - this.hoverRequest = null; │ │ │ │ │ } │ │ │ │ │ + return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ + * Method: read_FeatureInfoResponse │ │ │ │ │ + * Parse FeatureInfoResponse nodes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - findLayers: function() { │ │ │ │ │ - var candidates = this.layers || this.map.layers; │ │ │ │ │ - var layers = []; │ │ │ │ │ - var layer; │ │ │ │ │ - for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = candidates[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.WMTS && │ │ │ │ │ - layer.requestEncoding === this.requestEncoding && │ │ │ │ │ - (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - if (!this.drillDown || this.hover) { │ │ │ │ │ - break; │ │ │ │ │ + read_FeatureInfoResponse: function(data) { │ │ │ │ │ + var response = []; │ │ │ │ │ + var featureNodes = this.getElementsByTagNameNS(data, '*', │ │ │ │ │ + 'FIELDS'); │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = featureNodes.length; i < len; i++) { │ │ │ │ │ + var featureNode = featureNodes[i]; │ │ │ │ │ + var geom = null; │ │ │ │ │ + │ │ │ │ │ + // attributes can be actual attributes on the FIELDS tag, │ │ │ │ │ + // or FIELD children │ │ │ │ │ + var attributes = {}; │ │ │ │ │ + var j; │ │ │ │ │ + var jlen = featureNode.attributes.length; │ │ │ │ │ + if (jlen > 0) { │ │ │ │ │ + for (j = 0; j < jlen; j++) { │ │ │ │ │ + var attribute = featureNode.attributes[j]; │ │ │ │ │ + attributes[attribute.nodeName] = attribute.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var nodes = featureNode.childNodes; │ │ │ │ │ + for (j = 0, jlen = nodes.length; j < jlen; ++j) { │ │ │ │ │ + var node = nodes[j]; │ │ │ │ │ + if (node.nodeType != 3) { │ │ │ │ │ + attributes[node.getAttribute("name")] = │ │ │ │ │ + node.getAttribute("value"); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + response.push( │ │ │ │ │ + new OpenLayers.Feature.Vector(geom, attributes, null) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return layers; │ │ │ │ │ + return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildRequestOptions │ │ │ │ │ - * Build an object with the relevant options for the GetFeatureInfo request. │ │ │ │ │ - * │ │ │ │ │ + * Method: getSiblingNodesByTagCriteria │ │ │ │ │ + * Recursively searches passed xml node and all it's descendant levels for │ │ │ │ │ + * nodes whose tagName contains the passed search string. This returns an │ │ │ │ │ + * array of all sibling nodes which match the criteria from the highest │ │ │ │ │ + * hierarchial level from which a match is found. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} A WMTS layer. │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ + * node - {DOMElement} An xml node │ │ │ │ │ + * criteria - {String} Search string which will match some part of a tagName │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * Array({DOMElement}) An array of sibling xml nodes │ │ │ │ │ */ │ │ │ │ │ - buildRequestOptions: function(layer, xy) { │ │ │ │ │ - var loc = this.map.getLonLatFromPixel(xy); │ │ │ │ │ - var getTileUrl = layer.getURL( │ │ │ │ │ - new OpenLayers.Bounds(loc.lon, loc.lat, loc.lon, loc.lat) │ │ │ │ │ - ); │ │ │ │ │ - var params = OpenLayers.Util.getParameters(getTileUrl); │ │ │ │ │ - var tileInfo = layer.getTileInfo(loc); │ │ │ │ │ - OpenLayers.Util.extend(params, { │ │ │ │ │ - service: "WMTS", │ │ │ │ │ - version: layer.version, │ │ │ │ │ - request: "GetFeatureInfo", │ │ │ │ │ - infoFormat: this.infoFormat, │ │ │ │ │ - i: tileInfo.i, │ │ │ │ │ - j: tileInfo.j │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ - return { │ │ │ │ │ - url: OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url, │ │ │ │ │ - params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - this.handleResponse(xy, request, layer); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }; │ │ │ │ │ + getSiblingNodesByTagCriteria: function(node, criteria) { │ │ │ │ │ + var nodes = []; │ │ │ │ │ + var children, tagName, n, matchNodes, child; │ │ │ │ │ + if (node && node.hasChildNodes()) { │ │ │ │ │ + children = node.childNodes; │ │ │ │ │ + n = children.length; │ │ │ │ │ + │ │ │ │ │ + for (var k = 0; k < n; k++) { │ │ │ │ │ + child = children[k]; │ │ │ │ │ + while (child && child.nodeType != 1) { │ │ │ │ │ + child = child.nextSibling; │ │ │ │ │ + k++; │ │ │ │ │ + } │ │ │ │ │ + tagName = (child ? child.nodeName : ''); │ │ │ │ │ + if (tagName.length > 0 && tagName.indexOf(criteria) > -1) { │ │ │ │ │ + nodes.push(child); │ │ │ │ │ + } else { │ │ │ │ │ + matchNodes = this.getSiblingNodesByTagCriteria( │ │ │ │ │ + child, criteria); │ │ │ │ │ + │ │ │ │ │ + if (matchNodes.length > 0) { │ │ │ │ │ + (nodes.length == 0) ? │ │ │ │ │ + nodes = matchNodes: nodes.push(matchNodes); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ + return nodes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeatureInfo request to the WMTS │ │ │ │ │ - * │ │ │ │ │ + * Method: parseAttributes │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The position on the map where the mouse event │ │ │ │ │ - * occurred. │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ + * node - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An attributes object. │ │ │ │ │ * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ + * Notes: │ │ │ │ │ + * Assumes that attributes are direct child xml nodes of the passed node │ │ │ │ │ + * and contain only a single text node. │ │ │ │ │ */ │ │ │ │ │ - request: function(xy, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - var layers = this.findLayers(); │ │ │ │ │ - if (layers.length > 0) { │ │ │ │ │ - var issue, layer; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - layer = layers[i]; │ │ │ │ │ - issue = this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - if (issue !== false) { │ │ │ │ │ - ++this.pending; │ │ │ │ │ - var requestOptions = this.buildRequestOptions(layer, xy); │ │ │ │ │ - var request = OpenLayers.Request.GET(requestOptions); │ │ │ │ │ - if (options.hover === true) { │ │ │ │ │ - this.hoverRequest = request; │ │ │ │ │ + parseAttributes: function(node) { │ │ │ │ │ + var attributes = {}; │ │ │ │ │ + if (node.nodeType == 1) { │ │ │ │ │ + var children = node.childNodes; │ │ │ │ │ + var n = children.length; │ │ │ │ │ + for (var i = 0; i < n; ++i) { │ │ │ │ │ + var child = children[i]; │ │ │ │ │ + if (child.nodeType == 1) { │ │ │ │ │ + var grandchildren = child.childNodes; │ │ │ │ │ + var name = (child.prefix) ? │ │ │ │ │ + child.nodeName.split(":")[1] : child.nodeName; │ │ │ │ │ + if (grandchildren.length == 0) { │ │ │ │ │ + attributes[name] = null; │ │ │ │ │ + } else if (grandchildren.length == 1) { │ │ │ │ │ + var grandchild = grandchildren[0]; │ │ │ │ │ + if (grandchild.nodeType == 3 || │ │ │ │ │ + grandchild.nodeType == 4) { │ │ │ │ │ + var value = grandchild.nodeValue.replace( │ │ │ │ │ + this.regExes.trimSpace, ""); │ │ │ │ │ + attributes[name] = value; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (this.pending > 0) { │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - } │ │ │ │ │ } │ │ │ │ │ + return attributes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleResponse │ │ │ │ │ - * Handler for the GetFeatureInfo response. │ │ │ │ │ - * │ │ │ │ │ + * Method: parseGeometry │ │ │ │ │ + * Parse the geometry and the feature bounds out of the node using │ │ │ │ │ + * Format.GML │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The position on the map where the mouse event │ │ │ │ │ - * occurred. │ │ │ │ │ - * request - {XMLHttpRequest} The request object. │ │ │ │ │ - * layer - {} The queried layer. │ │ │ │ │ + * node - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object containing the geometry and the feature bounds │ │ │ │ │ */ │ │ │ │ │ - handleResponse: function(xy, request, layer) { │ │ │ │ │ - --this.pending; │ │ │ │ │ - if (this.pending <= 0) { │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.pending = 0; │ │ │ │ │ + parseGeometry: function(node) { │ │ │ │ │ + // we need to use the old Format.GML parser since we do not know the │ │ │ │ │ + // geometry name │ │ │ │ │ + if (!this.gmlFormat) { │ │ │ │ │ + this.gmlFormat = new OpenLayers.Format.GML(); │ │ │ │ │ } │ │ │ │ │ - if (request.status && (request.status < 200 || request.status >= 300)) { │ │ │ │ │ - this.events.triggerEvent("exception", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - request: request, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ - } │ │ │ │ │ - var features, except; │ │ │ │ │ - try { │ │ │ │ │ - features = this.format.read(doc); │ │ │ │ │ - } catch (error) { │ │ │ │ │ - except = true; │ │ │ │ │ - this.events.triggerEvent("exception", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - request: request, │ │ │ │ │ - error: error, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!except) { │ │ │ │ │ - this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ - text: request.responseText, │ │ │ │ │ - features: features, │ │ │ │ │ - request: request, │ │ │ │ │ - xy: xy, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + var feature = this.gmlFormat.parseFeature(node); │ │ │ │ │ + var geometry, bounds = null; │ │ │ │ │ + if (feature) { │ │ │ │ │ + geometry = feature.geometry && feature.geometry.clone(); │ │ │ │ │ + bounds = feature.bounds && feature.bounds.clone(); │ │ │ │ │ + feature.destroy(); │ │ │ │ │ } │ │ │ │ │ + return { │ │ │ │ │ + geometry: geometry, │ │ │ │ │ + bounds: bounds │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.WMTSGetFeatureInfo" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/GetFeature.js │ │ │ │ │ + OpenLayers/Control/WMSGetFeatureInfo.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/Control.js │ │ │ │ │ * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Box.js │ │ │ │ │ * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.GetFeature │ │ │ │ │ - * Gets vector features for locations underneath the mouse cursor. Can be │ │ │ │ │ - * configured to act on click, hover or dragged boxes. Uses an │ │ │ │ │ - * that supports spatial filters to retrieve │ │ │ │ │ - * features from a server and fires events that notify applications of the │ │ │ │ │ - * selected features. │ │ │ │ │ + * Class: OpenLayers.Control.WMSGetFeatureInfo │ │ │ │ │ + * The WMSGetFeatureInfo control uses a WMS query to get information about a point on the map. The │ │ │ │ │ + * information may be in a display-friendly format such as HTML, or a machine-friendly format such │ │ │ │ │ + * as GML, depending on the server's capabilities and the client's configuration. This control │ │ │ │ │ + * handles click or hover events, attempts to parse the results using an OpenLayers.Format, and │ │ │ │ │ + * fires a 'getfeatureinfo' event with the click position, the raw body of the response, and an │ │ │ │ │ + * array of features if it successfully read the response. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: protocol │ │ │ │ │ - * {} Required. The protocol used for fetching │ │ │ │ │ - * features. │ │ │ │ │ - */ │ │ │ │ │ - protocol: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multipleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - multipleKey: null, │ │ │ │ │ +OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: toggleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ + * APIProperty: hover │ │ │ │ │ + * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - toggleKey: null, │ │ │ │ │ + hover: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: modifiers │ │ │ │ │ - * {Object} The event modifiers to use, according to the current event │ │ │ │ │ - * being handled by this control's handlers │ │ │ │ │ + * APIProperty: drillDown │ │ │ │ │ + * {Boolean} Drill down over all WMS layers in the map. When │ │ │ │ │ + * using drillDown mode, hover is not possible, and an infoFormat that │ │ │ │ │ + * returns parseable features is required. Default is false. │ │ │ │ │ */ │ │ │ │ │ - modifiers: null, │ │ │ │ │ + drillDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: multiple │ │ │ │ │ - * {Boolean} Allow selection of multiple geometries. Default is false. │ │ │ │ │ + * APIProperty: maxFeatures │ │ │ │ │ + * {Integer} Maximum number of features to return from a WMS query. This │ │ │ │ │ + * sets the feature_count parameter on WMS GetFeatureInfo │ │ │ │ │ + * requests. │ │ │ │ │ */ │ │ │ │ │ - multiple: false, │ │ │ │ │ + maxFeatures: 10, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: click │ │ │ │ │ - * {Boolean} Use a click handler for selecting/unselecting features. If │ │ │ │ │ - * both and are set to true, the click handler takes │ │ │ │ │ - * precedence over the box handler if a box with zero extent was │ │ │ │ │ - * selected. Default is true. │ │ │ │ │ + * APIProperty: clickCallback │ │ │ │ │ + * {String} The click callback to register in the │ │ │ │ │ + * {} object created when the hover │ │ │ │ │ + * option is set to false. Default is "click". │ │ │ │ │ */ │ │ │ │ │ - click: true, │ │ │ │ │ + clickCallback: "click", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: single │ │ │ │ │ - * {Boolean} Tells whether select by click should select a single │ │ │ │ │ - * feature. If set to false, all matching features are selected. │ │ │ │ │ - * If set to true, only the best matching feature is selected. │ │ │ │ │ - * This option has an effect only of the option is set │ │ │ │ │ - * to true. Default is true. │ │ │ │ │ + * APIProperty: output │ │ │ │ │ + * {String} Either "features" or "object". When triggering a getfeatureinfo │ │ │ │ │ + * request should we pass on an array of features or an object with with │ │ │ │ │ + * a "features" property and other properties (such as the url of the │ │ │ │ │ + * WMS). Default is "features". │ │ │ │ │ */ │ │ │ │ │ - single: true, │ │ │ │ │ + output: "features", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickout │ │ │ │ │ - * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ - * Applies only if is true. Default is true. │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} The layers to query for feature info. │ │ │ │ │ + * If omitted, all map WMS layers with a url that matches this or │ │ │ │ │ + * will be considered. │ │ │ │ │ */ │ │ │ │ │ - clickout: true, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: toggle │ │ │ │ │ - * {Boolean} Unselect a selected feature on click. Applies only if │ │ │ │ │ - * is true. Default is false. │ │ │ │ │ + * APIProperty: queryVisible │ │ │ │ │ + * {Boolean} If true, filter out hidden layers when searching the map for │ │ │ │ │ + * layers to query. Default is false. │ │ │ │ │ */ │ │ │ │ │ - toggle: false, │ │ │ │ │ + queryVisible: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickTolerance │ │ │ │ │ - * {Integer} Tolerance for the filter query in pixels. This has the │ │ │ │ │ - * same effect as the tolerance parameter on WMS GetFeatureInfo │ │ │ │ │ - * requests. Will be ignored for box selections. Applies only if │ │ │ │ │ - * or is true. Default is 5. Note that this not │ │ │ │ │ - * only affects requests on click, but also on hover. │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} The URL of the WMS service to use. If not provided, the url │ │ │ │ │ + * of the first eligible layer will be used. │ │ │ │ │ */ │ │ │ │ │ - clickTolerance: 5, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send feature requests on mouse moves. Default is false. │ │ │ │ │ + * APIProperty: layerUrls │ │ │ │ │ + * {Array(String)} Optional list of urls for layers that should be queried. │ │ │ │ │ + * This can be used when the layer url differs from the url used for │ │ │ │ │ + * making GetFeatureInfo requests (in the case of a layer using cached │ │ │ │ │ + * tiles). │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + layerUrls: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: box │ │ │ │ │ - * {Boolean} Allow feature selection by drawing a box. If set to │ │ │ │ │ - * true set to false to disable the click handler and │ │ │ │ │ - * rely on the box handler only, even for "zero extent" boxes. │ │ │ │ │ - * See the description of the option for additional │ │ │ │ │ - * information. Default is false. │ │ │ │ │ + * APIProperty: infoFormat │ │ │ │ │ + * {String} The mimetype to request from the server. If you are using │ │ │ │ │ + * drillDown mode and have multiple servers that do not share a common │ │ │ │ │ + * infoFormat, you can override the control's infoFormat by providing an │ │ │ │ │ + * INFO_FORMAT parameter in your instance(s). │ │ │ │ │ */ │ │ │ │ │ - box: false, │ │ │ │ │ + infoFormat: 'text/html', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a query in single mode │ │ │ │ │ - * if supported by the . This set of features is then used to │ │ │ │ │ - * determine the best match client-side. Default is 10. │ │ │ │ │ + * APIProperty: vendorParams │ │ │ │ │ + * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ + * WMS implementations that support them. This could e.g. look like │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * radius: 5 │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ + vendorParams: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: features │ │ │ │ │ - * {Object} Hash of {}, keyed by fid, holding │ │ │ │ │ - * the currently selected features │ │ │ │ │ + * APIProperty: format │ │ │ │ │ + * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ + * Default is . │ │ │ │ │ */ │ │ │ │ │ - features: null, │ │ │ │ │ + format: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Proeprty: hoverFeature │ │ │ │ │ - * {} The feature currently selected by the │ │ │ │ │ - * hover handler │ │ │ │ │ + * APIProperty: formatOptions │ │ │ │ │ + * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ + * in the property. │ │ │ │ │ */ │ │ │ │ │ - hoverFeature: null, │ │ │ │ │ + formatOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control. This │ │ │ │ │ - * is a hash with the keys "click", "box" and "hover". │ │ │ │ │ + * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * "click": {delay: 100}, │ │ │ │ │ + * "hover": {delay: 300} │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} Object with references to multiple │ │ │ │ │ - * instances. │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {Object} Reference to the for this control │ │ │ │ │ */ │ │ │ │ │ - handlers: null, │ │ │ │ │ + handler: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverResponse │ │ │ │ │ - * {} The response object associated with │ │ │ │ │ - * the currently running hover request (if any). │ │ │ │ │ + * Property: hoverRequest │ │ │ │ │ + * {} contains the currently running hover request │ │ │ │ │ + * (if any). │ │ │ │ │ */ │ │ │ │ │ - hoverResponse: null, │ │ │ │ │ + hoverRequest: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: filterType │ │ │ │ │ - * {} The type of filter to use when sending off a request. │ │ │ │ │ - * Possible values: │ │ │ │ │ - * OpenLayers.Filter.Spatial. │ │ │ │ │ - * Defaults to: OpenLayers.Filter.Spatial.BBOX │ │ │ │ │ - */ │ │ │ │ │ - filterType: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ * 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) │ │ │ │ │ * │ │ │ │ │ * Supported event types (in addition to those from ): │ │ │ │ │ - * beforefeatureselected - Triggered when is true before a │ │ │ │ │ - * feature is selected. The event object has a feature property with │ │ │ │ │ - * the feature about to select │ │ │ │ │ - * featureselected - Triggered when is true and a feature is │ │ │ │ │ - * selected. The event object has a feature property with the │ │ │ │ │ - * selected feature │ │ │ │ │ - * beforefeaturesselected - Triggered when is true before a │ │ │ │ │ - * set of features is selected. The event object is an array of │ │ │ │ │ - * feature properties with the features about to be selected. │ │ │ │ │ - * Return false after receiving this event to discontinue processing │ │ │ │ │ - * of all featureselected events and the featuresselected event. │ │ │ │ │ - * featuresselected - Triggered when is true and a set of │ │ │ │ │ - * features is selected. The event object is an array of feature │ │ │ │ │ - * properties of the selected features │ │ │ │ │ - * featureunselected - Triggered when is true and a feature is │ │ │ │ │ - * unselected. The event object has a feature property with the │ │ │ │ │ - * unselected feature │ │ │ │ │ - * clickout - Triggered when when is true and no feature was │ │ │ │ │ - * selected. │ │ │ │ │ - * hoverfeature - Triggered when is true and the mouse has │ │ │ │ │ - * stopped over a feature │ │ │ │ │ - * outfeature - Triggered when is true and the mouse moves │ │ │ │ │ - * moved away from a hover-selected feature │ │ │ │ │ + * beforegetfeatureinfo - Triggered before the request is sent. │ │ │ │ │ + * The event object has an *xy* property with the position of the │ │ │ │ │ + * mouse click or hover event that triggers the request. │ │ │ │ │ + * nogetfeatureinfo - no queryable layers were found. │ │ │ │ │ + * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ + * The event object has a *text* property with the body of the │ │ │ │ │ + * response (String), a *features* property with an array of the │ │ │ │ │ + * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ + * click or hover event that triggered the request, and a *request* │ │ │ │ │ + * property with the request itself. If drillDown is set to true and │ │ │ │ │ + * multiple requests were issued to collect feature info from all │ │ │ │ │ + * layers, *text* and *request* will only contain the response body │ │ │ │ │ + * and request object of the last request. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.GetFeature │ │ │ │ │ - * Create a new control for fetching remote features. │ │ │ │ │ + * Constructor: │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} A configuration object which at least has to contain │ │ │ │ │ - * a property (if not, it has to be set before a request is │ │ │ │ │ - * made) │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ │ │ │ │ │ OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ │ │ │ │ │ - this.features = {}; │ │ │ │ │ - │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - │ │ │ │ │ - if (this.click) { │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click(this, { │ │ │ │ │ - click: this.selectClick │ │ │ │ │ - }, this.handlerOptions.click || {}); │ │ │ │ │ + if (!this.format) { │ │ │ │ │ + this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ + options.formatOptions │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.box) { │ │ │ │ │ - this.handlers.box = new OpenLayers.Handler.Box( │ │ │ │ │ - this, { │ │ │ │ │ - done: this.selectBox │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.box, { │ │ │ │ │ - boxDivClassName: "olHandlerBoxSelectFeature" │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ + if (this.drillDown === true) { │ │ │ │ │ + this.hover = false; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ if (this.hover) { │ │ │ │ │ - this.handlers.hover = new OpenLayers.Handler.Hover( │ │ │ │ │ + this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ this, { │ │ │ │ │ 'move': this.cancelHover, │ │ │ │ │ - 'pause': this.selectHover │ │ │ │ │ + 'pause': this.getInfoForHover │ │ │ │ │ }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.hover, { │ │ │ │ │ - 'delay': 250, │ │ │ │ │ - 'pixelTolerance': 2 │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].activate(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Control.prototype.activate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].deactivate(); │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Util.extend(this.handlerOptions.hover || {}, { │ │ │ │ │ + 'delay': 250 │ │ │ │ │ + })); │ │ │ │ │ + } else { │ │ │ │ │ + var callbacks = {}; │ │ │ │ │ + callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ + this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ + this, callbacks, this.handlerOptions.click || {}); │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectClick │ │ │ │ │ + * Method: getInfoForClick │ │ │ │ │ * Called on click │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - selectClick: function(evt) { │ │ │ │ │ - var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ - │ │ │ │ │ - this.setModifiers(evt); │ │ │ │ │ - this.request(bounds, { │ │ │ │ │ - single: this.single │ │ │ │ │ + getInfoForClick: function(evt) { │ │ │ │ │ + this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ + xy: evt.xy │ │ │ │ │ }); │ │ │ │ │ + // Set the cursor to "wait" to tell the user we're working on their │ │ │ │ │ + // click. │ │ │ │ │ + OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + this.request(evt.xy, {}); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectBox │ │ │ │ │ - * Callback from the handlers.box set up when selection is on │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * position - {|Object} An OpenLayers.Bounds or │ │ │ │ │ - * an object with a 'left', 'bottom', 'right' and 'top' properties. │ │ │ │ │ - */ │ │ │ │ │ - selectBox: function(position) { │ │ │ │ │ - var bounds; │ │ │ │ │ - if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ - var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.left, │ │ │ │ │ - y: position.bottom │ │ │ │ │ - }); │ │ │ │ │ - var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.right, │ │ │ │ │ - y: position.top │ │ │ │ │ - }); │ │ │ │ │ - bounds = new OpenLayers.Bounds( │ │ │ │ │ - minXY.lon, minXY.lat, maxXY.lon, maxXY.lat │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - if (this.click) { │ │ │ │ │ - // box without extent - let the click handler take care of it │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - bounds = this.pixelToBounds(position); │ │ │ │ │ - } │ │ │ │ │ - this.setModifiers(this.handlers.box.dragHandler.evt); │ │ │ │ │ - this.request(bounds); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: selectHover │ │ │ │ │ - * Callback from the handlers.hover set up when selection is on │ │ │ │ │ + * Method: getInfoForHover │ │ │ │ │ + * Pause callback for the hover handler │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} event object with an xy property │ │ │ │ │ + * evt - {Object} │ │ │ │ │ */ │ │ │ │ │ - selectHover: function(evt) { │ │ │ │ │ - var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ - this.request(bounds, { │ │ │ │ │ - single: true, │ │ │ │ │ + getInfoForHover: function(evt) { │ │ │ │ │ + this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ + xy: evt.xy │ │ │ │ │ + }); │ │ │ │ │ + this.request(evt.xy, { │ │ │ │ │ hover: true │ │ │ │ │ }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: cancelHover │ │ │ │ │ - * Callback from the handlers.hover set up when selection is on │ │ │ │ │ + * Cancel callback for the hover handler │ │ │ │ │ */ │ │ │ │ │ cancelHover: function() { │ │ │ │ │ - if (this.hoverResponse) { │ │ │ │ │ - this.protocol.abort(this.hoverResponse); │ │ │ │ │ - this.hoverResponse = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + if (this.hoverRequest) { │ │ │ │ │ + this.hoverRequest.abort(); │ │ │ │ │ + this.hoverRequest = null; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeature request to the WFS │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} bounds for the request's BBOX filter │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ - * │ │ │ │ │ - * Supported options include: │ │ │ │ │ - * single - {Boolean} A single feature should be returned. │ │ │ │ │ - * Note that this will be ignored if the protocol does not │ │ │ │ │ - * return the geometries of the features. │ │ │ │ │ - * hover - {Boolean} Do the request for the hover handler. │ │ │ │ │ + * Method: findLayers │ │ │ │ │ + * Internal method to get the layers, independent of whether we are │ │ │ │ │ + * inspecting the map or using a client-provided array │ │ │ │ │ */ │ │ │ │ │ - request: function(bounds, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: this.filterType, │ │ │ │ │ - value: bounds │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - // Set the cursor to "wait" to tell the user we're working. │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + findLayers: function() { │ │ │ │ │ │ │ │ │ │ - var response = this.protocol.read({ │ │ │ │ │ - maxFeatures: options.single == true ? this.maxFeatures : undefined, │ │ │ │ │ - filter: filter, │ │ │ │ │ - callback: function(result) { │ │ │ │ │ - if (result.success()) { │ │ │ │ │ - if (result.features.length) { │ │ │ │ │ - if (options.single == true) { │ │ │ │ │ - this.selectBestFeature(result.features, │ │ │ │ │ - bounds.getCenterLonLat(), options); │ │ │ │ │ - } else { │ │ │ │ │ - this.select(result.features); │ │ │ │ │ - } │ │ │ │ │ - } else if (options.hover) { │ │ │ │ │ - this.hoverSelect(); │ │ │ │ │ - } else { │ │ │ │ │ - this.events.triggerEvent("clickout"); │ │ │ │ │ - if (this.clickout) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + var candidates = this.layers || this.map.layers; │ │ │ │ │ + var layers = []; │ │ │ │ │ + var layer, url; │ │ │ │ │ + for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ + layer = candidates[i]; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.WMS && │ │ │ │ │ + (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ + url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ + // if the control was not configured with a url, set it │ │ │ │ │ + // to the first layer url │ │ │ │ │ + if (this.drillDown === false && !this.url) { │ │ │ │ │ + this.url = url; │ │ │ │ │ } │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - if (options.hover == true) { │ │ │ │ │ - this.hoverResponse = response; │ │ │ │ │ + if (this.drillDown === true || this.urlMatches(url)) { │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return layers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectBestFeature │ │ │ │ │ - * Selects the feature from an array of features that is the best match │ │ │ │ │ - * for the click position. │ │ │ │ │ - * │ │ │ │ │ + * Method: urlMatches │ │ │ │ │ + * Test to see if the provided url matches either the control or one │ │ │ │ │ + * of the . │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ - * clickPosition - {} │ │ │ │ │ - * options - {Object} additional options for this method │ │ │ │ │ - * │ │ │ │ │ - * Supported options include: │ │ │ │ │ - * hover - {Boolean} Do the selection for the hover handler. │ │ │ │ │ + * url - {String} The url to test. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The provided url matches the control or one of the │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - selectBestFeature: function(features, clickPosition, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - if (features.length) { │ │ │ │ │ - var point = new OpenLayers.Geometry.Point(clickPosition.lon, │ │ │ │ │ - clickPosition.lat); │ │ │ │ │ - var feature, resultFeature, dist; │ │ │ │ │ - var minDist = Number.MAX_VALUE; │ │ │ │ │ - for (var i = 0; i < features.length; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - dist = point.distanceTo(feature.geometry, { │ │ │ │ │ - edge: false │ │ │ │ │ - }); │ │ │ │ │ - if (dist < minDist) { │ │ │ │ │ - minDist = dist; │ │ │ │ │ - resultFeature = feature; │ │ │ │ │ - if (minDist == 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + urlMatches: function(url) { │ │ │ │ │ + var matches = OpenLayers.Util.isEquivalentUrl(this.url, url); │ │ │ │ │ + if (!matches && this.layerUrls) { │ │ │ │ │ + for (var i = 0, len = this.layerUrls.length; i < len; ++i) { │ │ │ │ │ + if (OpenLayers.Util.isEquivalentUrl(this.layerUrls[i], url)) { │ │ │ │ │ + matches = true; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (options.hover == true) { │ │ │ │ │ - this.hoverSelect(resultFeature); │ │ │ │ │ - } else { │ │ │ │ │ - this.select(resultFeature || features); │ │ │ │ │ - } │ │ │ │ │ } │ │ │ │ │ + return matches; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setModifiers │ │ │ │ │ - * Sets the multiple and toggle modifiers according to the current event │ │ │ │ │ - * │ │ │ │ │ + * Method: buildWMSOptions │ │ │ │ │ + * Build an object with the relevant WMS options for the GetFeatureInfo request │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * url - {String} The url to be used for sending the request │ │ │ │ │ + * layers - {Array(} The position on the map where the mouse │ │ │ │ │ + * event occurred. │ │ │ │ │ + * format - {String} The format from the corresponding GetMap request │ │ │ │ │ */ │ │ │ │ │ - setModifiers: function(evt) { │ │ │ │ │ - this.modifiers = { │ │ │ │ │ - multiple: this.multiple || (this.multipleKey && evt[this.multipleKey]), │ │ │ │ │ - toggle: this.toggle || (this.toggleKey && evt[this.toggleKey]) │ │ │ │ │ + buildWMSOptions: function(url, layers, clickPosition, format) { │ │ │ │ │ + var layerNames = [], │ │ │ │ │ + styleNames = []; │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + if (layers[i].params.LAYERS != null) { │ │ │ │ │ + layerNames = layerNames.concat(layers[i].params.LAYERS); │ │ │ │ │ + styleNames = styleNames.concat(this.getStyleNames(layers[i])); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var firstLayer = layers[0]; │ │ │ │ │ + // use the firstLayer's projection if it matches the map projection - │ │ │ │ │ + // this assumes that all layers will be available in this projection │ │ │ │ │ + var projection = this.map.getProjection(); │ │ │ │ │ + var layerProj = firstLayer.projection; │ │ │ │ │ + if (layerProj && layerProj.equals(this.map.getProjectionObject())) { │ │ │ │ │ + projection = layerProj.getCode(); │ │ │ │ │ + } │ │ │ │ │ + var params = OpenLayers.Util.extend({ │ │ │ │ │ + service: "WMS", │ │ │ │ │ + version: firstLayer.params.VERSION, │ │ │ │ │ + request: "GetFeatureInfo", │ │ │ │ │ + exceptions: firstLayer.params.EXCEPTIONS, │ │ │ │ │ + bbox: this.map.getExtent().toBBOX(null, │ │ │ │ │ + firstLayer.reverseAxisOrder()), │ │ │ │ │ + feature_count: this.maxFeatures, │ │ │ │ │ + height: this.map.getSize().h, │ │ │ │ │ + width: this.map.getSize().w, │ │ │ │ │ + format: format, │ │ │ │ │ + info_format: firstLayer.params.INFO_FORMAT || this.infoFormat │ │ │ │ │ + }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ? { │ │ │ │ │ + crs: projection, │ │ │ │ │ + i: parseInt(clickPosition.x), │ │ │ │ │ + j: parseInt(clickPosition.y) │ │ │ │ │ + } : { │ │ │ │ │ + srs: projection, │ │ │ │ │ + x: parseInt(clickPosition.x), │ │ │ │ │ + y: parseInt(clickPosition.y) │ │ │ │ │ + }); │ │ │ │ │ + if (layerNames.length != 0) { │ │ │ │ │ + params = OpenLayers.Util.extend({ │ │ │ │ │ + layers: layerNames, │ │ │ │ │ + query_layers: layerNames, │ │ │ │ │ + styles: styleNames │ │ │ │ │ + }, params); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ + return { │ │ │ │ │ + url: url, │ │ │ │ │ + params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ + callback: function(request) { │ │ │ │ │ + this.handleResponse(clickPosition, request, url); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: select │ │ │ │ │ - * Add feature to the hash of selected features and trigger the │ │ │ │ │ - * featureselected and featuresselected events. │ │ │ │ │ - * │ │ │ │ │ + * Method: getStyleNames │ │ │ │ │ + * Gets the STYLES parameter for the layer. Make sure the STYLES parameter │ │ │ │ │ + * matches the LAYERS parameter │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {} or an array of features │ │ │ │ │ + * layer - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array(String)} The STYLES parameter │ │ │ │ │ */ │ │ │ │ │ - select: function(features) { │ │ │ │ │ - if (!this.modifiers.multiple && !this.modifiers.toggle) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var cont = this.events.triggerEvent("beforefeaturesselected", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - var selectedFeatures = []; │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (this.features[feature.fid || feature.id]) { │ │ │ │ │ - if (this.modifiers.toggle) { │ │ │ │ │ - this.unselect(this.features[feature.fid || feature.id]); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - cont = this.events.triggerEvent("beforefeatureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - this.features[feature.fid || feature.id] = feature; │ │ │ │ │ - selectedFeatures.push(feature); │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("featureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getStyleNames: function(layer) { │ │ │ │ │ + // in the event of a WMS layer bundling multiple layers but not │ │ │ │ │ + // specifying styles,we need the same number of commas to specify │ │ │ │ │ + // the default style for each of the layers. We can't just leave it │ │ │ │ │ + // blank as we may be including other layers that do specify styles. │ │ │ │ │ + var styleNames; │ │ │ │ │ + if (layer.params.STYLES) { │ │ │ │ │ + styleNames = layer.params.STYLES; │ │ │ │ │ + } else { │ │ │ │ │ + if (OpenLayers.Util.isArray(layer.params.LAYERS)) { │ │ │ │ │ + styleNames = new Array(layer.params.LAYERS.length); │ │ │ │ │ + } else { // Assume it's a String │ │ │ │ │ + styleNames = layer.params.LAYERS.replace(/[^,]/g, ""); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("featuresselected", { │ │ │ │ │ - features: selectedFeatures │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ + return styleNames; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: hoverSelect │ │ │ │ │ - * Sets/unsets the │ │ │ │ │ - * │ │ │ │ │ + * Method: request │ │ │ │ │ + * Sends a GetFeatureInfo request to the WMS │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} the feature to hover-select. │ │ │ │ │ - * If none is provided, the current will be nulled and │ │ │ │ │ - * the outfeature event will be triggered. │ │ │ │ │ + * clickPosition - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * options - {Object} additional options for this method. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ */ │ │ │ │ │ - hoverSelect: function(feature) { │ │ │ │ │ - var fid = feature ? feature.fid || feature.id : null; │ │ │ │ │ - var hfid = this.hoverFeature ? │ │ │ │ │ - this.hoverFeature.fid || this.hoverFeature.id : null; │ │ │ │ │ - │ │ │ │ │ - if (hfid && hfid != fid) { │ │ │ │ │ - this.events.triggerEvent("outfeature", { │ │ │ │ │ - feature: this.hoverFeature │ │ │ │ │ - }); │ │ │ │ │ - this.hoverFeature = null; │ │ │ │ │ + request: function(clickPosition, options) { │ │ │ │ │ + var layers = this.findLayers(); │ │ │ │ │ + if (layers.length == 0) { │ │ │ │ │ + this.events.triggerEvent("nogetfeatureinfo"); │ │ │ │ │ + // Reset the cursor. │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - if (fid && fid != hfid) { │ │ │ │ │ - this.events.triggerEvent("hoverfeature", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - this.hoverFeature = feature; │ │ │ │ │ + │ │ │ │ │ + options = options || {}; │ │ │ │ │ + if (this.drillDown === false) { │ │ │ │ │ + var wmsOptions = this.buildWMSOptions(this.url, layers, │ │ │ │ │ + clickPosition, layers[0].params.FORMAT); │ │ │ │ │ + var request = OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ + │ │ │ │ │ + if (options.hover === true) { │ │ │ │ │ + this.hoverRequest = request; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + this._requestCount = 0; │ │ │ │ │ + this._numRequests = 0; │ │ │ │ │ + this.features = []; │ │ │ │ │ + // group according to service url to combine requests │ │ │ │ │ + var services = {}, │ │ │ │ │ + url; │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + var layer = layers[i]; │ │ │ │ │ + var service, found = false; │ │ │ │ │ + url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ + if (url in services) { │ │ │ │ │ + services[url].push(layer); │ │ │ │ │ + } else { │ │ │ │ │ + this._numRequests++; │ │ │ │ │ + services[url] = [layer]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var layers; │ │ │ │ │ + for (var url in services) { │ │ │ │ │ + layers = services[url]; │ │ │ │ │ + var wmsOptions = this.buildWMSOptions(url, layers, │ │ │ │ │ + clickPosition, layers[0].params.FORMAT); │ │ │ │ │ + OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unselect │ │ │ │ │ - * Remove feature from the hash of selected features and trigger the │ │ │ │ │ - * featureunselected event. │ │ │ │ │ + * Method: triggerGetFeatureInfo │ │ │ │ │ + * Trigger the getfeatureinfo event when all is done │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ + * request - {XMLHttpRequest} The request object │ │ │ │ │ + * xy - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * features - {Array()} or │ │ │ │ │ + * {Array({Object}) when output is "object". The object has a url and a │ │ │ │ │ + * features property which contains an array of features. │ │ │ │ │ */ │ │ │ │ │ - unselect: function(feature) { │ │ │ │ │ - delete this.features[feature.fid || feature.id]; │ │ │ │ │ - this.events.triggerEvent("featureunselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ + triggerGetFeatureInfo: function(request, xy, features) { │ │ │ │ │ + this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ + text: request.responseText, │ │ │ │ │ + features: features, │ │ │ │ │ + request: request, │ │ │ │ │ + xy: xy │ │ │ │ │ }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unselectAll │ │ │ │ │ - * Unselect all selected features. │ │ │ │ │ - */ │ │ │ │ │ - unselectAll: function() { │ │ │ │ │ - // we'll want an option to supress notification here │ │ │ │ │ - for (var fid in this.features) { │ │ │ │ │ - this.unselect(this.features[fid]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].setMap(map); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + // Reset the cursor. │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: pixelToBounds │ │ │ │ │ - * Takes a pixel as argument and creates bounds after adding the │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ + * Method: handleResponse │ │ │ │ │ + * Handler for the GetFeatureInfo response. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} │ │ │ │ │ + * xy - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * request - {XMLHttpRequest} The request object. │ │ │ │ │ + * url - {String} The url which was used for this request. │ │ │ │ │ */ │ │ │ │ │ - pixelToBounds: function(pixel) { │ │ │ │ │ - var llPx = pixel.add(-this.clickTolerance / 2, this.clickTolerance / 2); │ │ │ │ │ - var urPx = pixel.add(this.clickTolerance / 2, -this.clickTolerance / 2); │ │ │ │ │ - var ll = this.map.getLonLatFromPixel(llPx); │ │ │ │ │ - var ur = this.map.getLonLatFromPixel(urPx); │ │ │ │ │ - return new OpenLayers.Bounds(ll.lon, ll.lat, ur.lon, ur.lat); │ │ │ │ │ + handleResponse: function(xy, request, url) { │ │ │ │ │ + │ │ │ │ │ + var doc = request.responseXML; │ │ │ │ │ + if (!doc || !doc.documentElement) { │ │ │ │ │ + doc = request.responseText; │ │ │ │ │ + } │ │ │ │ │ + var features = this.format.read(doc); │ │ │ │ │ + if (this.drillDown === false) { │ │ │ │ │ + this.triggerGetFeatureInfo(request, xy, features); │ │ │ │ │ + } else { │ │ │ │ │ + this._requestCount++; │ │ │ │ │ + if (this.output === "object") { │ │ │ │ │ + this._features = (this._features || []).concat({ │ │ │ │ │ + url: url, │ │ │ │ │ + features: features │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + this._features = (this._features || []).concat(features); │ │ │ │ │ + } │ │ │ │ │ + if (this._requestCount === this._numRequests) { │ │ │ │ │ + this.triggerGetFeatureInfo(request, xy, this._features.concat()); │ │ │ │ │ + delete this._features; │ │ │ │ │ + delete this._requestCount; │ │ │ │ │ + delete this._numRequests; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.GetFeature" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/ArcXML.js │ │ │ │ │ + OpenLayers/Handler/MouseWheel.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/Geometry/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LinearRing.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.ArcXML │ │ │ │ │ - * Read/Write ArcXML. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Handler.MouseWheel │ │ │ │ │ + * Handler for wheel up/down events. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.ArcXML = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: fontStyleKeys │ │ │ │ │ - * {Array} List of keys used in font styling. │ │ │ │ │ +OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: wheelListener │ │ │ │ │ + * {function} │ │ │ │ │ */ │ │ │ │ │ - fontStyleKeys: [ │ │ │ │ │ - 'antialiasing', 'blockout', 'font', 'fontcolor', 'fontsize', 'fontstyle', │ │ │ │ │ - 'glowing', 'interval', 'outline', 'printmode', 'shadow', 'transparency' │ │ │ │ │ - ], │ │ │ │ │ + wheelListener: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: request │ │ │ │ │ - * A get_image request destined for an ArcIMS server. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - request: null, │ │ │ │ │ + interval: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: response │ │ │ │ │ - * A parsed response from an ArcIMS server. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - response: null, │ │ │ │ │ + maxDelta: Number.POSITIVE_INFINITY, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.ArcXML │ │ │ │ │ - * Create a new parser/writer for ArcXML. Create an instance of this class │ │ │ │ │ - * to begin authoring a request to an ArcIMS service. This is used │ │ │ │ │ - * primarily by the ArcIMS layer, but could be used to do other wild │ │ │ │ │ - * stuff, like geocoding. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.request = new OpenLayers.Format.ArcXML.Request(); │ │ │ │ │ - this.response = new OpenLayers.Format.ArcXML.Response(); │ │ │ │ │ - │ │ │ │ │ - if (options) { │ │ │ │ │ - if (options.requesttype == "feature") { │ │ │ │ │ - this.request.get_image = null; │ │ │ │ │ - │ │ │ │ │ - var qry = this.request.get_feature.query; │ │ │ │ │ - this.addCoordSys(qry.featurecoordsys, options.featureCoordSys); │ │ │ │ │ - this.addCoordSys(qry.filtercoordsys, options.filterCoordSys); │ │ │ │ │ - │ │ │ │ │ - if (options.polygon) { │ │ │ │ │ - qry.isspatial = true; │ │ │ │ │ - qry.spatialfilter.polygon = options.polygon; │ │ │ │ │ - } else if (options.envelope) { │ │ │ │ │ - qry.isspatial = true; │ │ │ │ │ - qry.spatialfilter.envelope = { │ │ │ │ │ - minx: 0, │ │ │ │ │ - miny: 0, │ │ │ │ │ - maxx: 0, │ │ │ │ │ - maxy: 0 │ │ │ │ │ - }; │ │ │ │ │ - this.parseEnvelope(qry.spatialfilter.envelope, options.envelope); │ │ │ │ │ - } │ │ │ │ │ - } else if (options.requesttype == "image") { │ │ │ │ │ - this.request.get_feature = null; │ │ │ │ │ - │ │ │ │ │ - var props = this.request.get_image.properties; │ │ │ │ │ - this.parseEnvelope(props.envelope, options.envelope); │ │ │ │ │ - │ │ │ │ │ - this.addLayers(props.layerlist, options.layers); │ │ │ │ │ - this.addImageSize(props.imagesize, options.tileSize); │ │ │ │ │ - this.addCoordSys(props.featurecoordsys, options.featureCoordSys); │ │ │ │ │ - this.addCoordSys(props.filtercoordsys, options.filterCoordSys); │ │ │ │ │ - } else { │ │ │ │ │ - // if an arcxml object is being created with no request type, it is │ │ │ │ │ - // probably going to consume a response, so do not throw an error if │ │ │ │ │ - // the requesttype is not defined │ │ │ │ │ - this.request = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ - }, │ │ │ │ │ + delta: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseEnvelope │ │ │ │ │ - * Parse an array of coordinates into an ArcXML envelope structure. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * env - {Object} An envelope object that will contain the parsed coordinates. │ │ │ │ │ - * arr - {Array(double)} An array of coordinates in the order: [ minx, miny, maxx, maxy ] │ │ │ │ │ - */ │ │ │ │ │ - parseEnvelope: function(env, arr) { │ │ │ │ │ - if (arr && arr.length == 4) { │ │ │ │ │ - env.minx = arr[0]; │ │ │ │ │ - env.miny = arr[1]; │ │ │ │ │ - env.maxx = arr[2]; │ │ │ │ │ - env.maxy = arr[3]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addLayers │ │ │ │ │ - * Add a collection of layers to another collection of layers. Each layer in the list is tuple of │ │ │ │ │ - * { id, visible }. These layer collections represent the │ │ │ │ │ - * /ARCXML/REQUEST/get_image/PROPERTIES/LAYERLIST/LAYERDEF items in ArcXML │ │ │ │ │ - * │ │ │ │ │ - * TODO: Add support for dynamic layer rendering. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * ll - {Array({id,visible})} A list of layer definitions. │ │ │ │ │ - * lyrs - {Array({id,visible})} A list of layer definitions. │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - addLayers: function(ll, lyrs) { │ │ │ │ │ - for (var lind = 0, len = lyrs.length; lind < len; lind++) { │ │ │ │ │ - ll.push(lyrs[lind]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + cumulative: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addImageSize │ │ │ │ │ - * Set the size of the requested image. │ │ │ │ │ + * Constructor: OpenLayers.Handler.MouseWheel │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * imsize - {Object} An ArcXML imagesize object. │ │ │ │ │ - * olsize - {} The image size to set. │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - addImageSize: function(imsize, olsize) { │ │ │ │ │ - if (olsize !== null) { │ │ │ │ │ - imsize.width = olsize.w; │ │ │ │ │ - imsize.height = olsize.h; │ │ │ │ │ - imsize.printwidth = olsize.w; │ │ │ │ │ - imsize.printheight = olsize.h; │ │ │ │ │ - } │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.wheelListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ + this.onWheelEvent, this │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addCoordSys │ │ │ │ │ - * Add the coordinate system information to an object. The object may be │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featOrFilt - {Object} A featurecoordsys or filtercoordsys ArcXML structure. │ │ │ │ │ - * fsys - {String} or {} or {filtercoordsys} or │ │ │ │ │ - * {featurecoordsys} A projection representation. If it's a {String}, │ │ │ │ │ - * the value is assumed to be the SRID. If it's a {OpenLayers.Projection} │ │ │ │ │ - * AND Proj4js is available, the projection number and name are extracted │ │ │ │ │ - * from there. If it's a filter or feature ArcXML structure, it is copied. │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - addCoordSys: function(featOrFilt, fsys) { │ │ │ │ │ - if (typeof fsys == "string") { │ │ │ │ │ - featOrFilt.id = parseInt(fsys); │ │ │ │ │ - featOrFilt.string = fsys; │ │ │ │ │ - } │ │ │ │ │ - // is this a proj4js instance? │ │ │ │ │ - else if (typeof fsys == "object" && fsys.proj !== null) { │ │ │ │ │ - featOrFilt.id = fsys.proj.srsProjNumber; │ │ │ │ │ - featOrFilt.string = fsys.proj.srsCode; │ │ │ │ │ - } else { │ │ │ │ │ - featOrFilt = fsys; │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ + this.wheelListener = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: iserror │ │ │ │ │ - * Check to see if the response from the server was an error. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. If nothing is supplied, │ │ │ │ │ - * the current response is examined. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the response was an error. │ │ │ │ │ + * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ │ │ │ │ │ */ │ │ │ │ │ - iserror: function(data) { │ │ │ │ │ - var ret = null; │ │ │ │ │ - │ │ │ │ │ - if (!data) { │ │ │ │ │ - ret = (this.response.error !== ''); │ │ │ │ │ - } else { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - var errorNodes = data.documentElement.getElementsByTagName("ERROR"); │ │ │ │ │ - ret = (errorNodes !== null && errorNodes.length > 0); │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - return ret; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read data from a string, and return an response. │ │ │ │ │ + /** │ │ │ │ │ + * Method: onWheelEvent │ │ │ │ │ + * Catch the wheel event and handle it xbrowserly │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An ArcXML response. Note that this response │ │ │ │ │ - * data may change in the future. │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var arcNode = null; │ │ │ │ │ - if (data && data.documentElement) { │ │ │ │ │ - if (data.documentElement.nodeName == "ARCXML") { │ │ │ │ │ - arcNode = data.documentElement; │ │ │ │ │ - } else { │ │ │ │ │ - arcNode = data.documentElement.getElementsByTagName("ARCXML")[0]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // in Safari, arcNode will be there but will have a child named │ │ │ │ │ - // parsererror │ │ │ │ │ - if (!arcNode || arcNode.firstChild.nodeName === 'parsererror') { │ │ │ │ │ - var error, source; │ │ │ │ │ - try { │ │ │ │ │ - error = data.firstChild.nodeValue; │ │ │ │ │ - source = data.firstChild.childNodes[1].firstChild.nodeValue; │ │ │ │ │ - } catch (err) { │ │ │ │ │ - // pass │ │ │ │ │ - } │ │ │ │ │ - throw { │ │ │ │ │ - message: "Error parsing the ArcXML request", │ │ │ │ │ - error: error, │ │ │ │ │ - source: source │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var response = this.parseResponse(arcNode); │ │ │ │ │ - return response; │ │ │ │ │ - }, │ │ │ │ │ + onWheelEvent: function(e) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Generate an ArcXml document string for sending to an ArcIMS server. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representing the ArcXML document request. │ │ │ │ │ - */ │ │ │ │ │ - write: function(request) { │ │ │ │ │ - if (!request) { │ │ │ │ │ - request = this.request; │ │ │ │ │ + // make sure we have a map and check keyboard modifiers │ │ │ │ │ + if (!this.map || !this.checkModifiers(e)) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - var root = this.createElementNS("", "ARCXML"); │ │ │ │ │ - root.setAttribute("version", "1.1"); │ │ │ │ │ - │ │ │ │ │ - var reqElem = this.createElementNS("", "REQUEST"); │ │ │ │ │ - │ │ │ │ │ - if (request.get_image != null) { │ │ │ │ │ - var getElem = this.createElementNS("", "GET_IMAGE"); │ │ │ │ │ - reqElem.appendChild(getElem); │ │ │ │ │ - │ │ │ │ │ - var propElem = this.createElementNS("", "PROPERTIES"); │ │ │ │ │ - getElem.appendChild(propElem); │ │ │ │ │ - │ │ │ │ │ - var props = request.get_image.properties; │ │ │ │ │ - if (props.featurecoordsys != null) { │ │ │ │ │ - var feat = this.createElementNS("", "FEATURECOORDSYS"); │ │ │ │ │ - propElem.appendChild(feat); │ │ │ │ │ - │ │ │ │ │ - if (props.featurecoordsys.id === 0) { │ │ │ │ │ - feat.setAttribute("string", props.featurecoordsys['string']); │ │ │ │ │ - } else { │ │ │ │ │ - feat.setAttribute("id", props.featurecoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.filtercoordsys != null) { │ │ │ │ │ - var filt = this.createElementNS("", "FILTERCOORDSYS"); │ │ │ │ │ - propElem.appendChild(filt); │ │ │ │ │ - │ │ │ │ │ - if (props.filtercoordsys.id === 0) { │ │ │ │ │ - filt.setAttribute("string", props.filtercoordsys.string); │ │ │ │ │ - } else { │ │ │ │ │ - filt.setAttribute("id", props.filtercoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.envelope != null) { │ │ │ │ │ - var env = this.createElementNS("", "ENVELOPE"); │ │ │ │ │ - propElem.appendChild(env); │ │ │ │ │ - │ │ │ │ │ - env.setAttribute("minx", props.envelope.minx); │ │ │ │ │ - env.setAttribute("miny", props.envelope.miny); │ │ │ │ │ - env.setAttribute("maxx", props.envelope.maxx); │ │ │ │ │ - env.setAttribute("maxy", props.envelope.maxy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var imagesz = this.createElementNS("", "IMAGESIZE"); │ │ │ │ │ - propElem.appendChild(imagesz); │ │ │ │ │ - │ │ │ │ │ - imagesz.setAttribute("height", props.imagesize.height); │ │ │ │ │ - imagesz.setAttribute("width", props.imagesize.width); │ │ │ │ │ - │ │ │ │ │ - if (props.imagesize.height != props.imagesize.printheight || │ │ │ │ │ - props.imagesize.width != props.imagesize.printwidth) { │ │ │ │ │ - imagesz.setAttribute("printheight", props.imagesize.printheight); │ │ │ │ │ - imagesz.setArrtibute("printwidth", props.imagesize.printwidth); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.background != null) { │ │ │ │ │ - var backgrnd = this.createElementNS("", "BACKGROUND"); │ │ │ │ │ - propElem.appendChild(backgrnd); │ │ │ │ │ - │ │ │ │ │ - backgrnd.setAttribute("color", │ │ │ │ │ - props.background.color.r + "," + │ │ │ │ │ - props.background.color.g + "," + │ │ │ │ │ - props.background.color.b); │ │ │ │ │ - │ │ │ │ │ - if (props.background.transcolor !== null) { │ │ │ │ │ - backgrnd.setAttribute("transcolor", │ │ │ │ │ - props.background.transcolor.r + "," + │ │ │ │ │ - props.background.transcolor.g + "," + │ │ │ │ │ - props.background.transcolor.b); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.layerlist != null && props.layerlist.length > 0) { │ │ │ │ │ - var layerlst = this.createElementNS("", "LAYERLIST"); │ │ │ │ │ - propElem.appendChild(layerlst); │ │ │ │ │ - │ │ │ │ │ - for (var ld = 0; ld < props.layerlist.length; ld++) { │ │ │ │ │ - var ldef = this.createElementNS("", "LAYERDEF"); │ │ │ │ │ - layerlst.appendChild(ldef); │ │ │ │ │ - │ │ │ │ │ - ldef.setAttribute("id", props.layerlist[ld].id); │ │ │ │ │ - ldef.setAttribute("visible", props.layerlist[ld].visible); │ │ │ │ │ - │ │ │ │ │ - if (typeof props.layerlist[ld].query == "object") { │ │ │ │ │ - var query = props.layerlist[ld].query; │ │ │ │ │ - │ │ │ │ │ - if (query.where.length < 0) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var queryElem = null; │ │ │ │ │ - if (typeof query.spatialfilter == "boolean" && query.spatialfilter) { │ │ │ │ │ - // handle spatial filter madness │ │ │ │ │ - queryElem = this.createElementNS("", "SPATIALQUERY"); │ │ │ │ │ - } else { │ │ │ │ │ - queryElem = this.createElementNS("", "QUERY"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - queryElem.setAttribute("where", query.where); │ │ │ │ │ - │ │ │ │ │ - if (typeof query.accuracy == "number" && query.accuracy > 0) { │ │ │ │ │ - queryElem.setAttribute("accuracy", query.accuracy); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.featurelimit == "number" && query.featurelimit < 2000) { │ │ │ │ │ - queryElem.setAttribute("featurelimit", query.featurelimit); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.subfields == "string" && query.subfields != "#ALL#") { │ │ │ │ │ - queryElem.setAttribute("subfields", query.subfields); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.joinexpression == "string" && query.joinexpression.length > 0) { │ │ │ │ │ - queryElem.setAttribute("joinexpression", query.joinexpression); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.jointables == "string" && query.jointables.length > 0) { │ │ │ │ │ - queryElem.setAttribute("jointables", query.jointables); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - ldef.appendChild(queryElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (typeof props.layerlist[ld].renderer == "object") { │ │ │ │ │ - this.addRenderer(ldef, props.layerlist[ld].renderer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else if (request.get_feature != null) { │ │ │ │ │ - var getElem = this.createElementNS("", "GET_FEATURES"); │ │ │ │ │ - getElem.setAttribute("outputmode", "newxml"); │ │ │ │ │ - getElem.setAttribute("checkesc", "true"); │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.geometry) { │ │ │ │ │ - getElem.setAttribute("geometry", request.get_feature.geometry); │ │ │ │ │ - } else { │ │ │ │ │ - getElem.setAttribute("geometry", "false"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.compact) { │ │ │ │ │ - getElem.setAttribute("compact", request.get_feature.compact); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.featurelimit == "number") { │ │ │ │ │ - getElem.setAttribute("featurelimit", request.get_feature.featurelimit); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - getElem.setAttribute("globalenvelope", "true"); │ │ │ │ │ - reqElem.appendChild(getElem); │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.layer != null && request.get_feature.layer.length > 0) { │ │ │ │ │ - var lyrElem = this.createElementNS("", "LAYER"); │ │ │ │ │ - lyrElem.setAttribute("id", request.get_feature.layer); │ │ │ │ │ - getElem.appendChild(lyrElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var fquery = request.get_feature.query; │ │ │ │ │ - if (fquery != null) { │ │ │ │ │ - var qElem = null; │ │ │ │ │ - if (fquery.isspatial) { │ │ │ │ │ - qElem = this.createElementNS("", "SPATIALQUERY"); │ │ │ │ │ - } else { │ │ │ │ │ - qElem = this.createElementNS("", "QUERY"); │ │ │ │ │ - } │ │ │ │ │ - getElem.appendChild(qElem); │ │ │ │ │ - │ │ │ │ │ - if (typeof fquery.accuracy == "number") { │ │ │ │ │ - qElem.setAttribute("accuracy", fquery.accuracy); │ │ │ │ │ - } │ │ │ │ │ - //qElem.setAttribute("featurelimit", "5"); │ │ │ │ │ - │ │ │ │ │ - if (fquery.featurecoordsys != null) { │ │ │ │ │ - var fcsElem1 = this.createElementNS("", "FEATURECOORDSYS"); │ │ │ │ │ │ │ │ │ │ - if (fquery.featurecoordsys.id == 0) { │ │ │ │ │ - fcsElem1.setAttribute("string", fquery.featurecoordsys.string); │ │ │ │ │ - } else { │ │ │ │ │ - fcsElem1.setAttribute("id", fquery.featurecoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - qElem.appendChild(fcsElem1); │ │ │ │ │ - } │ │ │ │ │ + // 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; │ │ │ │ │ │ │ │ │ │ - if (fquery.filtercoordsys != null) { │ │ │ │ │ - var fcsElem2 = this.createElementNS("", "FILTERCOORDSYS"); │ │ │ │ │ + var elem = OpenLayers.Event.element(e); │ │ │ │ │ + while ((elem != null) && !overMapDiv && !overScrollableDiv) { │ │ │ │ │ │ │ │ │ │ - if (fquery.filtercoordsys.id === 0) { │ │ │ │ │ - fcsElem2.setAttribute("string", fquery.filtercoordsys.string); │ │ │ │ │ + if (!overScrollableDiv) { │ │ │ │ │ + try { │ │ │ │ │ + var overflow; │ │ │ │ │ + if (elem.currentStyle) { │ │ │ │ │ + overflow = elem.currentStyle["overflow"]; │ │ │ │ │ } else { │ │ │ │ │ - fcsElem2.setAttribute("id", fquery.filtercoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - qElem.appendChild(fcsElem2); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (fquery.buffer > 0) { │ │ │ │ │ - var bufElem = this.createElementNS("", "BUFFER"); │ │ │ │ │ - bufElem.setAttribute("distance", fquery.buffer); │ │ │ │ │ - qElem.appendChild(bufElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (fquery.isspatial) { │ │ │ │ │ - var spfElem = this.createElementNS("", "SPATIALFILTER"); │ │ │ │ │ - spfElem.setAttribute("relation", fquery.spatialfilter.relation); │ │ │ │ │ - qElem.appendChild(spfElem); │ │ │ │ │ - │ │ │ │ │ - if (fquery.spatialfilter.envelope) { │ │ │ │ │ - var envElem = this.createElementNS("", "ENVELOPE"); │ │ │ │ │ - envElem.setAttribute("minx", fquery.spatialfilter.envelope.minx); │ │ │ │ │ - envElem.setAttribute("miny", fquery.spatialfilter.envelope.miny); │ │ │ │ │ - envElem.setAttribute("maxx", fquery.spatialfilter.envelope.maxx); │ │ │ │ │ - envElem.setAttribute("maxy", fquery.spatialfilter.envelope.maxy); │ │ │ │ │ - spfElem.appendChild(envElem); │ │ │ │ │ - } else if (typeof fquery.spatialfilter.polygon == "object") { │ │ │ │ │ - spfElem.appendChild(this.writePolygonGeometry(fquery.spatialfilter.polygon)); │ │ │ │ │ + var style = │ │ │ │ │ + document.defaultView.getComputedStyle(elem, null); │ │ │ │ │ + overflow = style.getPropertyValue("overflow"); │ │ │ │ │ } │ │ │ │ │ + overScrollableDiv = (overflow && │ │ │ │ │ + (overflow == "auto") || (overflow == "scroll")); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + //sometimes when scrolling in a popup, this causes │ │ │ │ │ + // obscure browser error │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (fquery.where != null && fquery.where.length > 0) { │ │ │ │ │ - qElem.setAttribute("where", fquery.where); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - root.appendChild(reqElem); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addGroupRenderer: function(ldef, toprenderer) { │ │ │ │ │ - var topRelem = this.createElementNS("", "GROUPRENDERER"); │ │ │ │ │ - ldef.appendChild(topRelem); │ │ │ │ │ - │ │ │ │ │ - for (var rind = 0; rind < toprenderer.length; rind++) { │ │ │ │ │ - var renderer = toprenderer[rind]; │ │ │ │ │ - this.addRenderer(topRelem, renderer); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addRenderer: function(topRelem, renderer) { │ │ │ │ │ - if (OpenLayers.Util.isArray(renderer)) { │ │ │ │ │ - this.addGroupRenderer(topRelem, renderer); │ │ │ │ │ - } else { │ │ │ │ │ - var renderElem = this.createElementNS("", renderer.type.toUpperCase() + "RENDERER"); │ │ │ │ │ - topRelem.appendChild(renderElem); │ │ │ │ │ - │ │ │ │ │ - if (renderElem.tagName == "VALUEMAPRENDERER") { │ │ │ │ │ - this.addValueMapRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "VALUEMAPLABELRENDERER") { │ │ │ │ │ - this.addValueMapLabelRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "SIMPLELABELRENDERER") { │ │ │ │ │ - this.addSimpleLabelRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "SCALEDEPENDENTRENDERER") { │ │ │ │ │ - this.addScaleDependentRenderer(renderElem, renderer); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addScaleDependentRenderer: function(renderElem, renderer) { │ │ │ │ │ - if (typeof renderer.lower == "string" || typeof renderer.lower == "number") { │ │ │ │ │ - renderElem.setAttribute("lower", renderer.lower); │ │ │ │ │ - } │ │ │ │ │ - if (typeof renderer.upper == "string" || typeof renderer.upper == "number") { │ │ │ │ │ - renderElem.setAttribute("upper", renderer.upper); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.addRenderer(renderElem, renderer.renderer); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addValueMapLabelRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("lookupfield", renderer.lookupfield); │ │ │ │ │ - renderElem.setAttribute("labelfield", renderer.labelfield); │ │ │ │ │ - │ │ │ │ │ - if (typeof renderer.exacts == "object") { │ │ │ │ │ - for (var ext = 0, extlen = renderer.exacts.length; ext < extlen; ext++) { │ │ │ │ │ - var exact = renderer.exacts[ext]; │ │ │ │ │ - │ │ │ │ │ - var eelem = this.createElementNS("", "EXACT"); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.value == "string") { │ │ │ │ │ - eelem.setAttribute("value", exact.value); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.label == "string") { │ │ │ │ │ - eelem.setAttribute("label", exact.label); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.method == "string") { │ │ │ │ │ - eelem.setAttribute("method", exact.method); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(eelem); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ - │ │ │ │ │ - if (exact.symbol.type == "text") { │ │ │ │ │ - selem = this.createElementNS("", "TEXTSYMBOL"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - var keys = this.fontStyleKeys; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (exact.symbol[key]) { │ │ │ │ │ - selem.setAttribute(key, exact.symbol[key]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - eelem.appendChild(selem); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } // for each exact │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - addValueMapRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("lookupfield", renderer.lookupfield); │ │ │ │ │ │ │ │ │ │ - if (typeof renderer.ranges == "object") { │ │ │ │ │ - for (var rng = 0, rnglen = renderer.ranges.length; rng < rnglen; rng++) { │ │ │ │ │ - var range = renderer.ranges[rng]; │ │ │ │ │ - │ │ │ │ │ - var relem = this.createElementNS("", "RANGE"); │ │ │ │ │ - relem.setAttribute("lower", range.lower); │ │ │ │ │ - relem.setAttribute("upper", range.upper); │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(relem); │ │ │ │ │ - │ │ │ │ │ - if (typeof range.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ - │ │ │ │ │ - if (range.symbol.type == "simplepolygon") { │ │ │ │ │ - selem = this.createElementNS("", "SIMPLEPOLYGONSYMBOL"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - if (typeof range.symbol.boundarycolor == "string") { │ │ │ │ │ - selem.setAttribute("boundarycolor", range.symbol.boundarycolor); │ │ │ │ │ - } │ │ │ │ │ - if (typeof range.symbol.fillcolor == "string") { │ │ │ │ │ - selem.setAttribute("fillcolor", range.symbol.fillcolor); │ │ │ │ │ - } │ │ │ │ │ - if (typeof range.symbol.filltransparency == "number") { │ │ │ │ │ - selem.setAttribute("filltransparency", range.symbol.filltransparency); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - relem.appendChild(selem); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } // for each range │ │ │ │ │ - } else if (typeof renderer.exacts == "object") { │ │ │ │ │ - for (var ext = 0, extlen = renderer.exacts.length; ext < extlen; ext++) { │ │ │ │ │ - var exact = renderer.exacts[ext]; │ │ │ │ │ - │ │ │ │ │ - var eelem = this.createElementNS("", "EXACT"); │ │ │ │ │ - if (typeof exact.value == "string") { │ │ │ │ │ - eelem.setAttribute("value", exact.value); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.label == "string") { │ │ │ │ │ - eelem.setAttribute("label", exact.label); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.method == "string") { │ │ │ │ │ - eelem.setAttribute("method", exact.method); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(eelem); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ + } │ │ │ │ │ + overMapDiv = (elem == this.map.div); │ │ │ │ │ │ │ │ │ │ - if (exact.symbol.type == "simplemarker") { │ │ │ │ │ - selem = this.createElementNS("", "SIMPLEMARKERSYMBOL"); │ │ │ │ │ - } │ │ │ │ │ + elem = elem.parentNode; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - if (typeof exact.symbol.antialiasing == "string") { │ │ │ │ │ - selem.setAttribute("antialiasing", exact.symbol.antialiasing); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.color == "string") { │ │ │ │ │ - selem.setAttribute("color", exact.symbol.color); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.outline == "string") { │ │ │ │ │ - selem.setAttribute("outline", exact.symbol.outline); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.overlap == "string") { │ │ │ │ │ - selem.setAttribute("overlap", exact.symbol.overlap); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.shadow == "string") { │ │ │ │ │ - selem.setAttribute("shadow", exact.symbol.shadow); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.transparency == "number") { │ │ │ │ │ - selem.setAttribute("transparency", exact.symbol.transparency); │ │ │ │ │ - } │ │ │ │ │ - //if (typeof exact.symbol.type == "string") │ │ │ │ │ - // selem.setAttribute("type", exact.symbol.type); │ │ │ │ │ - if (typeof exact.symbol.usecentroid == "string") { │ │ │ │ │ - selem.setAttribute("usecentroid", exact.symbol.usecentroid); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.width == "number") { │ │ │ │ │ - selem.setAttribute("width", exact.symbol.width); │ │ │ │ │ - } │ │ │ │ │ + // 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; │ │ │ │ │ │ │ │ │ │ - eelem.appendChild(selem); │ │ │ │ │ + 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)); │ │ │ │ │ } │ │ │ │ │ - } // for each exact │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addSimpleLabelRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("field", renderer.field); │ │ │ │ │ - var keys = ['featureweight', 'howmanylabels', 'labelbufferratio', │ │ │ │ │ - 'labelpriorities', 'labelweight', 'linelabelposition', │ │ │ │ │ - 'rotationalangles' │ │ │ │ │ - ]; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (renderer[key]) { │ │ │ │ │ - renderElem.setAttribute(key, renderer[key]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (renderer.symbol.type == "text") { │ │ │ │ │ - var symbol = renderer.symbol; │ │ │ │ │ - var selem = this.createElementNS("", "TEXTSYMBOL"); │ │ │ │ │ - renderElem.appendChild(selem); │ │ │ │ │ + this.delta += delta; │ │ │ │ │ │ │ │ │ │ - var keys = this.fontStyleKeys; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (symbol[key]) { │ │ │ │ │ - selem.setAttribute(key, renderer[key]); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - writePolygonGeometry: function(polygon) { │ │ │ │ │ - if (!(polygon instanceof OpenLayers.Geometry.Polygon)) { │ │ │ │ │ - throw { │ │ │ │ │ - message: 'Cannot write polygon geometry to ArcXML with an ' + │ │ │ │ │ - polygon.CLASS_NAME + ' object.', │ │ │ │ │ - geometry: polygon │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var polyElem = this.createElementNS("", "POLYGON"); │ │ │ │ │ - │ │ │ │ │ - for (var ln = 0, lnlen = polygon.components.length; ln < lnlen; ln++) { │ │ │ │ │ - var ring = polygon.components[ln]; │ │ │ │ │ - var ringElem = this.createElementNS("", "RING"); │ │ │ │ │ - │ │ │ │ │ - for (var rn = 0, rnlen = ring.components.length; rn < rnlen; rn++) { │ │ │ │ │ - var point = ring.components[rn]; │ │ │ │ │ - var pointElem = this.createElementNS("", "POINT"); │ │ │ │ │ - │ │ │ │ │ - pointElem.setAttribute("x", point.x); │ │ │ │ │ - pointElem.setAttribute("y", point.y); │ │ │ │ │ - │ │ │ │ │ - ringElem.appendChild(pointElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - polyElem.appendChild(ringElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return polyElem; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: parseResponse │ │ │ │ │ - * Take an ArcXML response, and parse in into this object's internal properties. │ │ │ │ │ - * │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} The ArcXML response, as either a string or the │ │ │ │ │ - * top level DOMElement of the response. │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - parseResponse: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - var newData = new OpenLayers.Format.XML(); │ │ │ │ │ - data = newData.read(data); │ │ │ │ │ - } │ │ │ │ │ - var response = new OpenLayers.Format.ArcXML.Response(); │ │ │ │ │ - │ │ │ │ │ - var errorNode = data.getElementsByTagName("ERROR"); │ │ │ │ │ - │ │ │ │ │ - if (errorNode != null && errorNode.length > 0) { │ │ │ │ │ - response.error = this.getChildValue(errorNode, "Unknown error."); │ │ │ │ │ - } else { │ │ │ │ │ - var responseNode = data.getElementsByTagName("RESPONSE"); │ │ │ │ │ - │ │ │ │ │ - if (responseNode == null || responseNode.length == 0) { │ │ │ │ │ - response.error = "No RESPONSE tag found in ArcXML response."; │ │ │ │ │ - return response; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var rtype = responseNode[0].firstChild.nodeName; │ │ │ │ │ - if (rtype == "#text") { │ │ │ │ │ - rtype = responseNode[0].firstChild.nextSibling.nodeName; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (rtype == "IMAGE") { │ │ │ │ │ - var envelopeNode = data.getElementsByTagName("ENVELOPE"); │ │ │ │ │ - var outputNode = data.getElementsByTagName("OUTPUT"); │ │ │ │ │ - │ │ │ │ │ - if (envelopeNode == null || envelopeNode.length == 0) { │ │ │ │ │ - response.error = "No ENVELOPE tag found in ArcXML response."; │ │ │ │ │ - } else if (outputNode == null || outputNode.length == 0) { │ │ │ │ │ - response.error = "No OUTPUT tag found in ArcXML response."; │ │ │ │ │ - } else { │ │ │ │ │ - var envAttr = this.parseAttributes(envelopeNode[0]); │ │ │ │ │ - var outputAttr = this.parseAttributes(outputNode[0]); │ │ │ │ │ - │ │ │ │ │ - if (typeof outputAttr.type == "string") { │ │ │ │ │ - response.image = { │ │ │ │ │ - envelope: envAttr, │ │ │ │ │ - output: { │ │ │ │ │ - type: outputAttr.type, │ │ │ │ │ - data: this.getChildValue(outputNode[0]) │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - response.image = { │ │ │ │ │ - envelope: envAttr, │ │ │ │ │ - output: outputAttr │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else if (rtype == "FEATURES") { │ │ │ │ │ - var features = responseNode[0].getElementsByTagName("FEATURES"); │ │ │ │ │ - │ │ │ │ │ - // get the feature count │ │ │ │ │ - var featureCount = features[0].getElementsByTagName("FEATURECOUNT"); │ │ │ │ │ - response.features.featurecount = featureCount[0].getAttribute("count"); │ │ │ │ │ - │ │ │ │ │ - if (response.features.featurecount > 0) { │ │ │ │ │ - // get the feature envelope │ │ │ │ │ - var envelope = features[0].getElementsByTagName("ENVELOPE"); │ │ │ │ │ - response.features.envelope = this.parseAttributes(envelope[0], typeof(0)); │ │ │ │ │ - │ │ │ │ │ - // get the field values per feature │ │ │ │ │ - var featureList = features[0].getElementsByTagName("FEATURE"); │ │ │ │ │ - for (var fn = 0; fn < featureList.length; fn++) { │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - var fields = featureList[fn].getElementsByTagName("FIELD"); │ │ │ │ │ - │ │ │ │ │ - for (var fdn = 0; fdn < fields.length; fdn++) { │ │ │ │ │ - var fieldName = fields[fdn].getAttribute("name"); │ │ │ │ │ - var fieldValue = fields[fdn].getAttribute("value"); │ │ │ │ │ - feature.attributes[fieldName] = fieldValue; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var geom = featureList[fn].getElementsByTagName("POLYGON"); │ │ │ │ │ - │ │ │ │ │ - if (geom.length > 0) { │ │ │ │ │ - // if there is a polygon, create an openlayers polygon, and assign │ │ │ │ │ - // it to the .geometry property of the feature │ │ │ │ │ - var ring = geom[0].getElementsByTagName("RING"); │ │ │ │ │ - │ │ │ │ │ - var polys = []; │ │ │ │ │ - for (var rn = 0; rn < ring.length; rn++) { │ │ │ │ │ - var linearRings = []; │ │ │ │ │ - linearRings.push(this.parsePointGeometry(ring[rn])); │ │ │ │ │ - │ │ │ │ │ - var holes = ring[rn].getElementsByTagName("HOLE"); │ │ │ │ │ - for (var hn = 0; hn < holes.length; hn++) { │ │ │ │ │ - linearRings.push(this.parsePointGeometry(holes[hn])); │ │ │ │ │ - } │ │ │ │ │ - holes = null; │ │ │ │ │ - polys.push(new OpenLayers.Geometry.Polygon(linearRings)); │ │ │ │ │ - linearRings = null; │ │ │ │ │ - } │ │ │ │ │ - ring = null; │ │ │ │ │ - │ │ │ │ │ - if (polys.length == 1) { │ │ │ │ │ - feature.geometry = polys[0]; │ │ │ │ │ - } else { │ │ │ │ │ - feature.geometry = new OpenLayers.Geometry.MultiPolygon(polys); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + wheelZoom: function(e) { │ │ │ │ │ + var delta = this.delta; │ │ │ │ │ + this.delta = 0; │ │ │ │ │ │ │ │ │ │ - response.features.feature.push(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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 { │ │ │ │ │ - response.error = "Unidentified response type."; │ │ │ │ │ + this.callback("up", │ │ │ │ │ + [e, this.cumulative ? Math.min(this.maxDelta, delta) : 1]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: parseAttributes │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} An element to parse attributes from. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An attributes object, with properties set to attribute values. │ │ │ │ │ + * Method: activate │ │ │ │ │ */ │ │ │ │ │ - parseAttributes: function(node, type) { │ │ │ │ │ - var attributes = {}; │ │ │ │ │ - for (var attr = 0; attr < node.attributes.length; attr++) { │ │ │ │ │ - if (type == "number") { │ │ │ │ │ - attributes[node.attributes[attr].nodeName] = parseFloat(node.attributes[attr].nodeValue); │ │ │ │ │ - } else { │ │ │ │ │ - attributes[node.attributes[attr].nodeName] = node.attributes[attr].nodeValue; │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return attributes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: parsePointGeometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} An element to parse or arcxml data from. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A linear ring represented by the node's points. │ │ │ │ │ + * Method: deactivate │ │ │ │ │ */ │ │ │ │ │ - parsePointGeometry: function(node) { │ │ │ │ │ - var ringPoints = []; │ │ │ │ │ - var coords = node.getElementsByTagName("COORDS"); │ │ │ │ │ - │ │ │ │ │ - if (coords.length > 0) { │ │ │ │ │ - // if coords is present, it's the only coords item │ │ │ │ │ - var coordArr = this.getChildValue(coords[0]); │ │ │ │ │ - coordArr = coordArr.split(/;/); │ │ │ │ │ - for (var cn = 0; cn < coordArr.length; cn++) { │ │ │ │ │ - var coordItems = coordArr[cn].split(/ /); │ │ │ │ │ - ringPoints.push(new OpenLayers.Geometry.Point(coordItems[0], coordItems[1])); │ │ │ │ │ - } │ │ │ │ │ - coords = null; │ │ │ │ │ + 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 { │ │ │ │ │ - var point = node.getElementsByTagName("POINT"); │ │ │ │ │ - if (point.length > 0) { │ │ │ │ │ - for (var pn = 0; pn < point.length; pn++) { │ │ │ │ │ - ringPoints.push( │ │ │ │ │ - new OpenLayers.Geometry.Point( │ │ │ │ │ - parseFloat(point[pn].getAttribute("x")), │ │ │ │ │ - parseFloat(point[pn].getAttribute("y")) │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - point = null; │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return new OpenLayers.Geometry.LinearRing(ringPoints); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Format.ArcXML.Request = OpenLayers.Class({ │ │ │ │ │ - initialize: function(params) { │ │ │ │ │ - var defaults = { │ │ │ │ │ - get_image: { │ │ │ │ │ - properties: { │ │ │ │ │ - background: null, │ │ │ │ │ - /*{ │ │ │ │ │ - color: { r:255, g:255, b:255 }, │ │ │ │ │ - transcolor: null │ │ │ │ │ - },*/ │ │ │ │ │ - draw: true, │ │ │ │ │ - envelope: { │ │ │ │ │ - minx: 0, │ │ │ │ │ - miny: 0, │ │ │ │ │ - maxx: 0, │ │ │ │ │ - maxy: 0 │ │ │ │ │ - }, │ │ │ │ │ - featurecoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - filtercoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - imagesize: { │ │ │ │ │ - height: 0, │ │ │ │ │ - width: 0, │ │ │ │ │ - dpi: 96, │ │ │ │ │ - printheight: 0, │ │ │ │ │ - printwidth: 0, │ │ │ │ │ - scalesymbols: false │ │ │ │ │ - }, │ │ │ │ │ - layerlist: [], │ │ │ │ │ - /* no support for legends */ │ │ │ │ │ - output: { │ │ │ │ │ - baseurl: "", │ │ │ │ │ - legendbaseurl: "", │ │ │ │ │ - legendname: "", │ │ │ │ │ - legendpath: "", │ │ │ │ │ - legendurl: "", │ │ │ │ │ - name: "", │ │ │ │ │ - path: "", │ │ │ │ │ - type: "jpg", │ │ │ │ │ - url: "" │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - get_feature: { │ │ │ │ │ - layer: "", │ │ │ │ │ - query: { │ │ │ │ │ - isspatial: false, │ │ │ │ │ - featurecoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - filtercoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - buffer: 0, │ │ │ │ │ - where: "", │ │ │ │ │ - spatialfilter: { │ │ │ │ │ - relation: "envelope_intersection", │ │ │ │ │ - envelope: null │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - environment: { │ │ │ │ │ - separators: { │ │ │ │ │ - cs: " ", │ │ │ │ │ - ts: ";" │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - layer: [], │ │ │ │ │ - workspaces: [] │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.extend(this, defaults); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML.Request" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Format.ArcXML.Response = OpenLayers.Class({ │ │ │ │ │ - initialize: function(params) { │ │ │ │ │ - var defaults = { │ │ │ │ │ - image: { │ │ │ │ │ - envelope: null, │ │ │ │ │ - output: '' │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - features: { │ │ │ │ │ - featurecount: 0, │ │ │ │ │ - envelope: null, │ │ │ │ │ - feature: [] │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - error: '' │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.extend(this, defaults); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML.Response" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.MouseWheel" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/ArcIMS.js │ │ │ │ │ + OpenLayers/Control/Navigation.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/Format/ArcXML.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ + * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ + * @requires OpenLayers/Handler/MouseWheel.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.ArcIMS │ │ │ │ │ - * Instances of OpenLayers.Layer.ArcIMS are used to display data from ESRI ArcIMS │ │ │ │ │ - * Mapping Services. Create a new ArcIMS layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Control.Navigation │ │ │ │ │ + * The navigation control handles map browsing with mouse events (dragging, │ │ │ │ │ + * double-clicking, and scrolling the wheel). Create a new navigation │ │ │ │ │ + * control with the control. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Note that this control is added to the map by default (if no controls │ │ │ │ │ + * array is sent in the options object to the │ │ │ │ │ + * constructor). │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: dragPan │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + dragPan: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_PARAMS │ │ │ │ │ - * {Object} Default query string parameters. │ │ │ │ │ + * APIProperty: dragPanOptions │ │ │ │ │ + * {Object} Options passed to the DragPan control. │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_PARAMS: { │ │ │ │ │ - ClientVersion: "9.2", │ │ │ │ │ - ServiceName: '' │ │ │ │ │ - }, │ │ │ │ │ + dragPanOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureCoordSys │ │ │ │ │ - * {String} Code for feature coordinate system. Default is "4326". │ │ │ │ │ + * Property: pinchZoom │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - featureCoordSys: "4326", │ │ │ │ │ + pinchZoom: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: filterCoordSys │ │ │ │ │ - * {String} Code for filter coordinate system. Default is "4326". │ │ │ │ │ + * APIProperty: pinchZoomOptions │ │ │ │ │ + * {Object} Options passed to the PinchZoom control. │ │ │ │ │ */ │ │ │ │ │ - filterCoordSys: "4326", │ │ │ │ │ + pinchZoomOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array} An array of objects with layer properties. │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + documentDrag: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomBox │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + zoomBox: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: async │ │ │ │ │ - * {Boolean} Request images asynchronously. Default is true. │ │ │ │ │ + * APIProperty: zoomBoxEnabled │ │ │ │ │ + * {Boolean} Whether the user can draw a box to zoom │ │ │ │ │ */ │ │ │ │ │ - async: true, │ │ │ │ │ + zoomBoxEnabled: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} Layer name. Default is "ArcIMS". │ │ │ │ │ + * APIProperty: zoomWheelEnabled │ │ │ │ │ + * {Boolean} Whether the mousewheel should zoom the map │ │ │ │ │ */ │ │ │ │ │ - name: "ArcIMS", │ │ │ │ │ + zoomWheelEnabled: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer is a base layer. Default is true. │ │ │ │ │ + * Property: mouseWheelOptions │ │ │ │ │ + * {Object} Options passed to the MouseWheel control (only useful if │ │ │ │ │ + * is set to true). Default is no options for maps │ │ │ │ │ + * with fractionalZoom set to true, otherwise │ │ │ │ │ + * {cumulative: false, interval: 50, maxDelta: 6} │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + mouseWheelOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_OPTIONS │ │ │ │ │ - * {Object} Default layers properties. │ │ │ │ │ + * APIProperty: handleRightClicks │ │ │ │ │ + * {Boolean} Whether or not to handle right clicks. Default is false. │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_OPTIONS: { │ │ │ │ │ - tileSize: new OpenLayers.Size(512, 512), │ │ │ │ │ - featureCoordSys: "4326", │ │ │ │ │ - filterCoordSys: "4326", │ │ │ │ │ - layers: null, │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - async: true, │ │ │ │ │ - name: "ArcIMS" │ │ │ │ │ - }, │ │ │ │ │ + handleRightClicks: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.ArcIMS │ │ │ │ │ - * Create a new ArcIMS layer object. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var arcims = new OpenLayers.Layer.ArcIMS( │ │ │ │ │ - * "Global Sample", │ │ │ │ │ - * "http://sample.avencia.com/servlet/com.esri.esrimap.Esrimap", │ │ │ │ │ - * { │ │ │ │ │ - * service: "OpenLayers_Sample", │ │ │ │ │ - * layers: [ │ │ │ │ │ - * // layers to manipulate │ │ │ │ │ - * {id: "1", visible: true} │ │ │ │ │ - * ] │ │ │ │ │ - * } │ │ │ │ │ - * ); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ + * APIProperty: zoomBoxKeyMask │ │ │ │ │ + * {Integer} key code of the key, which has to be │ │ │ │ │ + * pressed, while drawing the zoom box with the mouse on the screen. │ │ │ │ │ + * You should probably set handleRightClicks to true if you use this │ │ │ │ │ + * with MOD_CTRL, to disable the context menu for machines which use │ │ │ │ │ + * CTRL-Click as a right click. │ │ │ │ │ + * Default: │ │ │ │ │ + */ │ │ │ │ │ + zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ + */ │ │ │ │ │ + autoActivate: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Navigation │ │ │ │ │ + * Create a new navigation control │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * url - {String} Base url for the ArcIMS server │ │ │ │ │ - * options - {Object} Optional object with properties to be set on the │ │ │ │ │ - * layer. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * the control │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, options) { │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.tileSize = new OpenLayers.Size(512, 512); │ │ │ │ │ + /** │ │ │ │ │ + * 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() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ │ │ │ │ │ - // parameters │ │ │ │ │ - this.params = OpenLayers.Util.applyDefaults({ │ │ │ │ │ - ServiceName: options.serviceName │ │ │ │ │ - }, │ │ │ │ │ - this.DEFAULT_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - this.options = OpenLayers.Util.applyDefaults( │ │ │ │ │ - options, this.DEFAULT_OPTIONS │ │ │ │ │ - ); │ │ │ │ │ + if (this.dragPan) { │ │ │ │ │ + this.dragPan.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.dragPan = null; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply( │ │ │ │ │ - this, [name, url, this.params, options] │ │ │ │ │ - ); │ │ │ │ │ + if (this.zoomBox) { │ │ │ │ │ + this.zoomBox.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.zoomBox = null; │ │ │ │ │ │ │ │ │ │ - //layer is transparent │ │ │ │ │ - if (this.transparent) { │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.pinchZoom = null; │ │ │ │ │ │ │ │ │ │ - // unless explicitly set in options, make layer an overlay │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.isBaseLayer = false; │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // jpegs can never be transparent, so intelligently switch the │ │ │ │ │ - // format, depending on the browser's capabilities │ │ │ │ │ - if (this.format == "image/jpeg") { │ │ │ │ │ - this.format = OpenLayers.Util.alphaHack() ? "image/gif" : "image/png"; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + this.dragPan.activate(); │ │ │ │ │ + if (this.zoomWheelEnabled) { │ │ │ │ │ + this.handlers.wheel.activate(); │ │ │ │ │ + } │ │ │ │ │ + this.handlers.click.activate(); │ │ │ │ │ + if (this.zoomBoxEnabled) { │ │ │ │ │ + this.zoomBox.activate(); │ │ │ │ │ + } │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.activate(); │ │ │ │ │ } │ │ │ │ │ + return OpenLayers.Control.prototype.activate.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // create an empty layer list if no layers specified in the options │ │ │ │ │ - if (this.options.layers === null) { │ │ │ │ │ - this.options.layers = []; │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.deactivate(); │ │ │ │ │ } │ │ │ │ │ + this.zoomBox.deactivate(); │ │ │ │ │ + this.dragPan.deactivate(); │ │ │ │ │ + this.handlers.click.deactivate(); │ │ │ │ │ + this.handlers.wheel.deactivate(); │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * Return an image url this layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the map image's url. │ │ │ │ │ + * Method: draw │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - var url = ""; │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ + draw: function() { │ │ │ │ │ + // disable right mouse context menu for support of right click events │ │ │ │ │ + if (this.handleRightClicks) { │ │ │ │ │ + this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // create an arcxml request to generate the image │ │ │ │ │ - var axlReq = new OpenLayers.Format.ArcXML( │ │ │ │ │ - OpenLayers.Util.extend(this.options, { │ │ │ │ │ - requesttype: "image", │ │ │ │ │ - envelope: bounds.toArray(), │ │ │ │ │ - tileSize: this.tileSize │ │ │ │ │ - }) │ │ │ │ │ + var clickCallbacks = { │ │ │ │ │ + 'click': this.defaultClick, │ │ │ │ │ + 'dblclick': this.defaultDblClick, │ │ │ │ │ + 'dblrightclick': this.defaultDblRightClick │ │ │ │ │ + }; │ │ │ │ │ + var clickOptions = { │ │ │ │ │ + 'double': true, │ │ │ │ │ + 'stopDouble': true │ │ │ │ │ + }; │ │ │ │ │ + this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ + this, clickCallbacks, clickOptions │ │ │ │ │ ); │ │ │ │ │ - │ │ │ │ │ - // create a synchronous ajax request to get an arcims image │ │ │ │ │ - var req = new OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString(), │ │ │ │ │ - data: axlReq.write(), │ │ │ │ │ - async: false │ │ │ │ │ + this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map, │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + }, this.dragPanOptions) │ │ │ │ │ + ); │ │ │ │ │ + this.zoomBox = new OpenLayers.Control.ZoomBox({ │ │ │ │ │ + map: this.map, │ │ │ │ │ + keyMask: this.zoomBoxKeyMask │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ - // if the response exists │ │ │ │ │ - if (req != null) { │ │ │ │ │ - var doc = req.responseXML; │ │ │ │ │ - │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = req.responseText; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // create a new arcxml format to read the response │ │ │ │ │ - var axlResp = new OpenLayers.Format.ArcXML(); │ │ │ │ │ - var arcxml = axlResp.read(doc); │ │ │ │ │ - url = this.getUrlOrImage(arcxml.image.output); │ │ │ │ │ + this.dragPan.draw(); │ │ │ │ │ + this.zoomBox.draw(); │ │ │ │ │ + var wheelOptions = this.map.fractionalZoom ? {} : { │ │ │ │ │ + cumulative: false, │ │ │ │ │ + interval: 50, │ │ │ │ │ + maxDelta: 6 │ │ │ │ │ + }; │ │ │ │ │ + this.handlers.wheel = new OpenLayers.Handler.MouseWheel( │ │ │ │ │ + this, { │ │ │ │ │ + up: this.wheelUp, │ │ │ │ │ + down: this.wheelDown │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend(wheelOptions, this.mouseWheelOptions) │ │ │ │ │ + ); │ │ │ │ │ + if (OpenLayers.Control.PinchZoom) { │ │ │ │ │ + this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map │ │ │ │ │ + }, this.pinchZoomOptions)); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return url; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getURLasync │ │ │ │ │ - * Get an image url this layer asynchronously, and execute a callback │ │ │ │ │ - * when the image url is generated. │ │ │ │ │ + * Method: defaultClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ - * callback - {Function} Function to call when image url is retrieved. │ │ │ │ │ - * scope - {Object} The scope of the callback method. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getURLasync: function(bounds, callback, scope) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - │ │ │ │ │ - // create an arcxml request to generate the image │ │ │ │ │ - var axlReq = new OpenLayers.Format.ArcXML( │ │ │ │ │ - OpenLayers.Util.extend(this.options, { │ │ │ │ │ - requesttype: "image", │ │ │ │ │ - envelope: bounds.toArray(), │ │ │ │ │ - tileSize: this.tileSize │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // create an asynchronous ajax request to get an arcims image │ │ │ │ │ - OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString(), │ │ │ │ │ - async: true, │ │ │ │ │ - data: axlReq.write(), │ │ │ │ │ - callback: function(req) { │ │ │ │ │ - // process the response from ArcIMS, and call the callback function │ │ │ │ │ - // to set the image URL │ │ │ │ │ - var doc = req.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = req.responseText; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // create a new arcxml format to read the response │ │ │ │ │ - var axlResp = new OpenLayers.Format.ArcXML(); │ │ │ │ │ - var arcxml = axlResp.read(doc); │ │ │ │ │ + defaultClick: function(evt) { │ │ │ │ │ + if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - callback.call(scope, this.getUrlOrImage(arcxml.image.output)); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * Method: defaultDblClick │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + defaultDblClick: function(evt) { │ │ │ │ │ + this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getUrlOrImage │ │ │ │ │ - * Extract a url or image from the ArcXML image output. │ │ │ │ │ - * │ │ │ │ │ + * Method: defaultDblRightClick │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * output - {Object} The image.output property of the object returned from │ │ │ │ │ - * the ArcXML format read method. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A URL for an image (potentially with the data protocol). │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getUrlOrImage: function(output) { │ │ │ │ │ - var ret = ""; │ │ │ │ │ - if (output.url) { │ │ │ │ │ - // If the image response output url is a string, then the image │ │ │ │ │ - // data is not inline. │ │ │ │ │ - ret = output.url; │ │ │ │ │ - } else if (output.data) { │ │ │ │ │ - // The image data is inline and base64 encoded, create a data │ │ │ │ │ - // url for the image. This will only work for small images, │ │ │ │ │ - // due to browser url length limits. │ │ │ │ │ - ret = "data:image/" + output.type + │ │ │ │ │ - ";base64," + output.data; │ │ │ │ │ - } │ │ │ │ │ - return ret; │ │ │ │ │ + defaultDblRightClick: function(evt) { │ │ │ │ │ + this.map.zoomTo(this.map.zoom - 1, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayerQuery │ │ │ │ │ - * Set the query definition on this layer. Query definitions are used to │ │ │ │ │ - * render parts of the spatial data in an image, and can be used to │ │ │ │ │ - * filter features or layers in the ArcIMS service. │ │ │ │ │ + * Method: wheelChange │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * id - {String} The ArcIMS layer ID. │ │ │ │ │ - * querydef - {Object} The query definition to apply to this layer. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * deltaZ - {Integer} │ │ │ │ │ */ │ │ │ │ │ - setLayerQuery: function(id, querydef) { │ │ │ │ │ - // find the matching layer, if it exists │ │ │ │ │ - for (var lyr = 0; lyr < this.options.layers.length; lyr++) { │ │ │ │ │ - if (id == this.options.layers[lyr].id) { │ │ │ │ │ - // replace this layer definition │ │ │ │ │ - this.options.layers[lyr].query = querydef; │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + wheelChange: function(evt, deltaZ) { │ │ │ │ │ + if (!this.map.fractionalZoom) { │ │ │ │ │ + deltaZ = Math.round(deltaZ); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // no layer found, create a new definition │ │ │ │ │ - this.options.layers.push({ │ │ │ │ │ - id: id, │ │ │ │ │ - visible: true, │ │ │ │ │ - query: querydef │ │ │ │ │ - }); │ │ │ │ │ + var currentZoom = this.map.getZoom(), │ │ │ │ │ + newZoom = currentZoom + deltaZ; │ │ │ │ │ + newZoom = Math.max(newZoom, 0); │ │ │ │ │ + newZoom = Math.min(newZoom, this.map.getNumZoomLevels()); │ │ │ │ │ + if (newZoom === currentZoom) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.map.zoomTo(newZoom, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getFeatureInfo │ │ │ │ │ - * Get feature information from ArcIMS. Using the applied geometry, apply │ │ │ │ │ - * the options to the query (buffer, area/envelope intersection), and │ │ │ │ │ - * query the ArcIMS service. │ │ │ │ │ - * │ │ │ │ │ - * A note about accuracy: │ │ │ │ │ - * ArcIMS interprets the accuracy attribute in feature requests to be │ │ │ │ │ - * something like the 'modulus' operator on feature coordinates, │ │ │ │ │ - * applied to the database geometry of the feature. It doesn't round, │ │ │ │ │ - * so your feature coordinates may be up to (1 x accuracy) offset from │ │ │ │ │ - * the actual feature coordinates. If the accuracy of the layer is not │ │ │ │ │ - * specified, the accuracy will be computed to be approximately 1 │ │ │ │ │ - * feature coordinate per screen pixel. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: wheelUp │ │ │ │ │ + * User spun scroll wheel up │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} or {} The │ │ │ │ │ - * geometry to use when making the query. This should be a closed │ │ │ │ │ - * polygon for behavior approximating a free selection. │ │ │ │ │ - * layer - {Object} The ArcIMS layer definition. This is an anonymous object │ │ │ │ │ - * that looks like: │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * id: "ArcXML layer ID", // the ArcXML layer ID │ │ │ │ │ - * query: { │ │ │ │ │ - * where: "STATE = 'PA'", // the where clause of the query │ │ │ │ │ - * accuracy: 100 // the accuracy of the returned feature │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * options - {Object} Object with non-default properties to set on the layer. │ │ │ │ │ - * Supported properties are buffer, callback, scope, and any other │ │ │ │ │ - * properties applicable to the ArcXML format. Set the 'callback' and │ │ │ │ │ - * 'scope' for an object and function to recieve the parsed features │ │ │ │ │ - * from ArcIMS. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * delta - {Integer} │ │ │ │ │ */ │ │ │ │ │ - getFeatureInfo: function(geometry, layer, options) { │ │ │ │ │ - // set the buffer to 1 unit (dd/m/ft?) by default │ │ │ │ │ - var buffer = options.buffer || 1; │ │ │ │ │ - // empty callback by default │ │ │ │ │ - var callback = options.callback || function() {}; │ │ │ │ │ - // default scope is window (global) │ │ │ │ │ - var scope = options.scope || window; │ │ │ │ │ + wheelUp: function(evt, delta) { │ │ │ │ │ + this.wheelChange(evt, delta || 1); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // apply these option to the request options │ │ │ │ │ - var requestOptions = {}; │ │ │ │ │ - OpenLayers.Util.extend(requestOptions, this.options); │ │ │ │ │ + /** │ │ │ │ │ + * Method: wheelDown │ │ │ │ │ + * User spun scroll wheel down │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * delta - {Integer} │ │ │ │ │ + */ │ │ │ │ │ + wheelDown: function(evt, delta) { │ │ │ │ │ + this.wheelChange(evt, delta || -1); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // this is a feature request │ │ │ │ │ - requestOptions.requesttype = "feature"; │ │ │ │ │ + /** │ │ │ │ │ + * Method: disableZoomBox │ │ │ │ │ + */ │ │ │ │ │ + disableZoomBox: function() { │ │ │ │ │ + this.zoomBoxEnabled = false; │ │ │ │ │ + this.zoomBox.deactivate(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (geometry instanceof OpenLayers.LonLat) { │ │ │ │ │ - // create an envelope if the geometry is really a lon/lat │ │ │ │ │ - requestOptions.polygon = null; │ │ │ │ │ - requestOptions.envelope = [ │ │ │ │ │ - geometry.lon - buffer, │ │ │ │ │ - geometry.lat - buffer, │ │ │ │ │ - geometry.lon + buffer, │ │ │ │ │ - geometry.lat + buffer │ │ │ │ │ - ]; │ │ │ │ │ - } else if (geometry instanceof OpenLayers.Geometry.Polygon) { │ │ │ │ │ - // use the polygon assigned, and empty the envelope │ │ │ │ │ - requestOptions.envelope = null; │ │ │ │ │ - requestOptions.polygon = geometry; │ │ │ │ │ + /** │ │ │ │ │ + * Method: enableZoomBox │ │ │ │ │ + */ │ │ │ │ │ + enableZoomBox: function() { │ │ │ │ │ + this.zoomBoxEnabled = true; │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.zoomBox.activate(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // create an arcxml request to get feature requests │ │ │ │ │ - var arcxml = new OpenLayers.Format.ArcXML(requestOptions); │ │ │ │ │ + /** │ │ │ │ │ + * Method: disableZoomWheel │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // apply any get feature options to the arcxml request │ │ │ │ │ - OpenLayers.Util.extend(arcxml.request.get_feature, options); │ │ │ │ │ + disableZoomWheel: function() { │ │ │ │ │ + this.zoomWheelEnabled = false; │ │ │ │ │ + this.handlers.wheel.deactivate(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - arcxml.request.get_feature.layer = layer.id; │ │ │ │ │ - if (typeof layer.query.accuracy == "number") { │ │ │ │ │ - // set the accuracy if it was specified │ │ │ │ │ - arcxml.request.get_feature.query.accuracy = layer.query.accuracy; │ │ │ │ │ - } else { │ │ │ │ │ - // guess that the accuracy is 1 per screen pixel │ │ │ │ │ - var mapCenter = this.map.getCenter(); │ │ │ │ │ - var viewPx = this.map.getViewPortPxFromLonLat(mapCenter); │ │ │ │ │ - viewPx.x++; │ │ │ │ │ - var mapOffCenter = this.map.getLonLatFromPixel(viewPx); │ │ │ │ │ - arcxml.request.get_feature.query.accuracy = mapOffCenter.lon - mapCenter.lon; │ │ │ │ │ + /** │ │ │ │ │ + * Method: enableZoomWheel │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + enableZoomWheel: function() { │ │ │ │ │ + this.zoomWheelEnabled = true; │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.handlers.wheel.activate(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // set the get_feature query to be the same as the layer passed in │ │ │ │ │ - arcxml.request.get_feature.query.where = layer.query.where; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Navigation" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/NavToolbar.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // use area_intersection │ │ │ │ │ - arcxml.request.get_feature.query.spatialfilter.relation = "area_intersection"; │ │ │ │ │ +/* 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. */ │ │ │ │ │ │ │ │ │ │ - // create a new asynchronous request to get the feature info │ │ │ │ │ - OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString({ │ │ │ │ │ - 'CustomService': 'Query' │ │ │ │ │ - }), │ │ │ │ │ - data: arcxml.write(), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - // parse the arcxml response │ │ │ │ │ - var response = arcxml.parseResponse(request.responseText); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (!arcxml.iserror()) { │ │ │ │ │ - // if the arcxml is not an error, call the callback with the features parsed │ │ │ │ │ - callback.call(scope, response.features); │ │ │ │ │ - } else { │ │ │ │ │ - // if the arcxml is an error, return null features selected │ │ │ │ │ - callback.call(scope, null); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.NavToolbar │ │ │ │ │ + * This Toolbar is an alternative to the Navigation control that displays │ │ │ │ │ + * the state of the control, and provides a UI for changing state to │ │ │ │ │ + * use the zoomBox via a Panel control. │ │ │ │ │ + * │ │ │ │ │ + * If you wish to change the properties of the Navigation control used │ │ │ │ │ + * in the NavToolbar, see: │ │ │ │ │ + * http://trac.openlayers.org/wiki/Toolbars#SubclassingNavToolbar │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.NavToolbar = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * Constructor: OpenLayers.Control.NavToolbar │ │ │ │ │ + * Add our two mousedefaults controls. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.addControls([ │ │ │ │ │ + new OpenLayers.Control.Navigation(), │ │ │ │ │ + new OpenLayers.Control.ZoomBox() │ │ │ │ │ + ]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.ArcIMS(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * calls the default draw, and then activates mouse defaults. │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.defaultControl === null) { │ │ │ │ │ + this.defaultControl = this.controls[0]; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + return div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.ArcIMS" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.NavToolbar" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Image.js │ │ │ │ │ + OpenLayers/Control/DrawFeature.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 │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Image │ │ │ │ │ - * Instances of OpenLayers.Layer.Image are used to display data from a web │ │ │ │ │ - * accessible image as a map layer. Create a new image layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Control.DrawFeature │ │ │ │ │ + * The DrawFeature control draws point, line or polygon features on a vector │ │ │ │ │ + * layer when active. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: isBaseLayer │ │ │ │ │ - * {Boolean} The layer is a base layer. Default is true. Set this property │ │ │ │ │ - * in the layer options │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} URL of the image to use │ │ │ │ │ + * Property: callbacks │ │ │ │ │ + * {Object} The functions that are sent to the handler for callback │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: extent │ │ │ │ │ - * {} The image bounds in map units. This extent will │ │ │ │ │ - * also be used as the default maxExtent for the layer. If you wish │ │ │ │ │ - * to have a maxExtent that is different than the image extent, set the │ │ │ │ │ - * maxExtent property of the options argument (as with any other layer). │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * featureadded - Triggered when a feature is added │ │ │ │ │ */ │ │ │ │ │ - extent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} The image size in pixels │ │ │ │ │ + * APIProperty: multi │ │ │ │ │ + * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ + * layer. Default is false. │ │ │ │ │ */ │ │ │ │ │ - size: null, │ │ │ │ │ + multi: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: tile │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: featureAdded │ │ │ │ │ + * {Function} Called after each feature is added │ │ │ │ │ */ │ │ │ │ │ - tile: null, │ │ │ │ │ + featureAdded: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: aspectRatio │ │ │ │ │ - * {Float} The ratio of height/width represented by a single pixel in the │ │ │ │ │ - * graphic │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - aspectRatio: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Image │ │ │ │ │ - * Create a new image layer │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.DrawFeature │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} A name for the layer. │ │ │ │ │ - * url - {String} Relative or absolute path to the image │ │ │ │ │ - * extent - {} The extent represented by the image │ │ │ │ │ - * size - {} The size (in pixels) of the image │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * layer - {} │ │ │ │ │ + * handler - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, extent, size, options) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - this.extent = extent; │ │ │ │ │ - this.maxExtent = extent; │ │ │ │ │ - this.size = size; │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); │ │ │ │ │ - │ │ │ │ │ - this.aspectRatio = (this.extent.getHeight() / this.size.h) / │ │ │ │ │ - (this.extent.getWidth() / this.size.w); │ │ │ │ │ + initialize: function(layer, handler, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.callbacks = OpenLayers.Util.extend({ │ │ │ │ │ + done: this.drawFeature, │ │ │ │ │ + modify: function(vertex, feature) { │ │ │ │ │ + this.layer.events.triggerEvent( │ │ │ │ │ + "sketchmodified", { │ │ │ │ │ + vertex: vertex, │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + create: function(vertex, feature) { │ │ │ │ │ + this.layer.events.triggerEvent( │ │ │ │ │ + "sketchstarted", { │ │ │ │ │ + vertex: vertex, │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + this.callbacks │ │ │ │ │ + ); │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.handlerOptions = this.handlerOptions || {}; │ │ │ │ │ + this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ + this.handlerOptions.layerOptions, { │ │ │ │ │ + renderers: layer.renderers, │ │ │ │ │ + rendererOptions: layer.rendererOptions │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + if (!("multi" in this.handlerOptions)) { │ │ │ │ │ + this.handlerOptions.multi = this.multi; │ │ │ │ │ + } │ │ │ │ │ + var sketchStyle = this.layer.styleMap && this.layer.styleMap.styles.temporary; │ │ │ │ │ + if (sketchStyle) { │ │ │ │ │ + this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ + this.handlerOptions.layerOptions, { │ │ │ │ │ + styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ + "default": sketchStyle │ │ │ │ │ + }) │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy this layer │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.tile) { │ │ │ │ │ - this.removeTileMonitoringHooks(this.tile); │ │ │ │ │ - this.tile.destroy(); │ │ │ │ │ - this.tile = null; │ │ │ │ │ + drawFeature: function(geometry) { │ │ │ │ │ + var feature = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + var proceed = this.layer.events.triggerEvent( │ │ │ │ │ + "sketchcomplete", { │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + feature.state = OpenLayers.State.INSERT; │ │ │ │ │ + this.layer.addFeatures([feature]); │ │ │ │ │ + this.featureAdded(feature); │ │ │ │ │ + this.events.triggerEvent("featureadded", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ - * │ │ │ │ │ - * Paramters: │ │ │ │ │ - * obj - {Object} An optional layer (is this ever used?) │ │ │ │ │ + * APIMethod: insertXY │ │ │ │ │ + * Insert a point in the current sketch given x & y coordinates. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact copy of this layer │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Number} The x-coordinate of the point. │ │ │ │ │ + * y - {Number} The y-coordinate of the point. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Image(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.extent, │ │ │ │ │ - this.size, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + insertXY: function(x, y) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertXY(x, y); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setMap │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: insertDeltaXY │ │ │ │ │ + * Insert a point given offsets from the previously inserted point. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * dx - {Number} The x-coordinate offset of the point. │ │ │ │ │ + * dy - {Number} The y-coordinate offset of the point. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - /** │ │ │ │ │ - * If nothing to do with resolutions has been set, assume a single │ │ │ │ │ - * resolution determined by ratio*extent/size - if an image has a │ │ │ │ │ - * pixel aspect ratio different than one (as calculated above), the │ │ │ │ │ - * image will be stretched in one dimension only. │ │ │ │ │ - */ │ │ │ │ │ - if (this.options.maxResolution == null) { │ │ │ │ │ - this.options.maxResolution = this.aspectRatio * │ │ │ │ │ - this.extent.getWidth() / │ │ │ │ │ - this.size.w; │ │ │ │ │ + insertDeltaXY: function(dx, dy) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDeltaXY(dx, dy); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Create the tile for the image or resize it for the new resolution │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: insertDirectionLength │ │ │ │ │ + * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ + * length - {Number} Distance from the previously drawn point. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - var firstRendering = (this.tile == null); │ │ │ │ │ - │ │ │ │ │ - if (zoomChanged || firstRendering) { │ │ │ │ │ - │ │ │ │ │ - //determine new tile size │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - │ │ │ │ │ - //determine new position (upper left corner of new bounds) │ │ │ │ │ - var ulPx = this.map.getLayerPxFromLonLat({ │ │ │ │ │ - lon: this.extent.left, │ │ │ │ │ - lat: this.extent.top │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (firstRendering) { │ │ │ │ │ - //create the new tile │ │ │ │ │ - this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent, │ │ │ │ │ - null, this.tileSize); │ │ │ │ │ - this.addTileMonitoringHooks(this.tile); │ │ │ │ │ - } else { │ │ │ │ │ - //just resize the tile and set it's new position │ │ │ │ │ - this.tile.size = this.tileSize.clone(); │ │ │ │ │ - this.tile.position = ulPx.clone(); │ │ │ │ │ - } │ │ │ │ │ - this.tile.draw(); │ │ │ │ │ + insertDirectionLength: function(direction, length) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDirectionLength(direction, length); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Set the tile size based on the map size. │ │ │ │ │ + * APIMethod: 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. │ │ │ │ │ */ │ │ │ │ │ - setTileSize: function() { │ │ │ │ │ - var tileWidth = this.extent.getWidth() / this.map.getResolution(); │ │ │ │ │ - var tileHeight = this.extent.getHeight() / this.map.getResolution(); │ │ │ │ │ - this.tileSize = new OpenLayers.Size(tileWidth, tileHeight); │ │ │ │ │ + insertDeflectionLength: function(deflection, length) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDeflectionLength(deflection, length); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: │ │ │ │ │ - * tile - {} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: undo │ │ │ │ │ + * Remove the most recently added point in the current sketch geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} An edit was undone. │ │ │ │ │ */ │ │ │ │ │ - addTileMonitoringHooks: function(tile) { │ │ │ │ │ - tile.onLoadStart = function() { │ │ │ │ │ - this.events.triggerEvent("loadstart"); │ │ │ │ │ - }; │ │ │ │ │ - tile.events.register("loadstart", this, tile.onLoadStart); │ │ │ │ │ - │ │ │ │ │ - tile.onLoadEnd = function() { │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - }; │ │ │ │ │ - tile.events.register("loadend", this, tile.onLoadEnd); │ │ │ │ │ - tile.events.register("unload", this, tile.onLoadEnd); │ │ │ │ │ + undo: function() { │ │ │ │ │ + return this.handler.undo && this.handler.undo(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTileMonitoringHooks │ │ │ │ │ - * This function takes a tile as input and removes the tile hooks │ │ │ │ │ - * that were added in . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: redo │ │ │ │ │ + * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ + * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} An edit was redone. │ │ │ │ │ */ │ │ │ │ │ - removeTileMonitoringHooks: function(tile) { │ │ │ │ │ - tile.unload(); │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + redo: function() { │ │ │ │ │ + return this.handler.redo && this.handler.redo(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setUrl │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newUrl - {String} │ │ │ │ │ + * APIMethod: finishSketch │ │ │ │ │ + * Finishes the sketch without including the currently drawn point. │ │ │ │ │ + * This method can be called to terminate drawing programmatically │ │ │ │ │ + * instead of waiting for the user to end the sketch. │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(newUrl) { │ │ │ │ │ - this.url = newUrl; │ │ │ │ │ - this.tile.draw(); │ │ │ │ │ + finishSketch: function() { │ │ │ │ │ + this.handler.finishGeometry(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getURL │ │ │ │ │ - * The url we return is always the same (the image itself never changes) │ │ │ │ │ - * so we can ignore the bounds parameter (it will always be the same, │ │ │ │ │ - * anyways) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Cancel the current sketch. This removes the current sketch and keeps │ │ │ │ │ + * the drawing control active. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - return this.url; │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.handler.cancel(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Image" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.DrawFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/EventPane.js │ │ │ │ │ + OpenLayers/Control/EditingToolbar.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/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ + * @requires OpenLayers/Control/DrawFeature.js │ │ │ │ │ + * @requires OpenLayers/Handler/Point.js │ │ │ │ │ + * @requires OpenLayers/Handler/Path.js │ │ │ │ │ + * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer.js │ │ │ │ │ + * Class: OpenLayers.Control.EditingToolbar │ │ │ │ │ + * The EditingToolbar is a panel of 4 controls to draw polygons, lines, │ │ │ │ │ + * points, or to navigate the map by panning. By default it appears in the │ │ │ │ │ + * upper right corner of the map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.EditingToolbar = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Control.Panel, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.EditingToolbar │ │ │ │ │ + * Create an editing toolbar for a given layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + this.addControls( │ │ │ │ │ + [new OpenLayers.Control.Navigation()] │ │ │ │ │ + ); │ │ │ │ │ + var controls = [ │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePoint', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }), │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePath', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }), │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePolygon', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }) │ │ │ │ │ + ]; │ │ │ │ │ + this.addControls(controls); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * calls the default draw, and then activates mouse defaults. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.defaultControl === null) { │ │ │ │ │ + this.defaultControl = this.controls[0]; │ │ │ │ │ + } │ │ │ │ │ + return div; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.EditingToolbar" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/LayerSwitcher.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Lang.js │ │ │ │ │ * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.EventPane │ │ │ │ │ - * Base class for 3rd party layers, providing a DOM element which isolates │ │ │ │ │ - * the 3rd-party layer from mouse events. │ │ │ │ │ - * Only used by Google layers. │ │ │ │ │ + * Class: OpenLayers.Control.LayerSwitcher │ │ │ │ │ + * The LayerSwitcher control displays a table of contents for the map. This │ │ │ │ │ + * allows the user interface to switch between BaseLasyers and to show or hide │ │ │ │ │ + * Overlays. By default the switcher is shown minimized on the right edge of │ │ │ │ │ + * the map, the user may expand it by clicking on the handle. │ │ │ │ │ * │ │ │ │ │ - * Automatically instantiated by the Google constructor, and not usually instantiated directly. │ │ │ │ │ + * To create the LayerSwitcher outside of the map, pass the Id of a html div │ │ │ │ │ + * as the first argument to the constructor. │ │ │ │ │ * │ │ │ │ │ - * Create a new event pane layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerStates │ │ │ │ │ + * {Array(Object)} Basically a copy of the "state" of the map's layers │ │ │ │ │ + * the last time the control was drawn. We have this in order to avoid │ │ │ │ │ + * unnecessarily redrawing the control. │ │ │ │ │ + */ │ │ │ │ │ + layerStates: null, │ │ │ │ │ + │ │ │ │ │ + // DOM Elements │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: smoothDragPan │ │ │ │ │ - * {Boolean} smoothDragPan determines whether non-public/internal API │ │ │ │ │ - * methods are used for better performance while dragging EventPane │ │ │ │ │ - * layers. When not in sphericalMercator mode, the smoother dragging │ │ │ │ │ - * doesn't actually move north/south directly with the number of │ │ │ │ │ - * pixels moved, resulting in a slight offset when you drag your mouse │ │ │ │ │ - * north south with this option on. If this visual disparity bothers │ │ │ │ │ - * you, you should turn this option off, or use spherical mercator. │ │ │ │ │ - * Default is on. │ │ │ │ │ + * Property: layersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - smoothDragPan: true, │ │ │ │ │ + layersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: isBaseLayer │ │ │ │ │ - * {Boolean} EventPaned layers are always base layers, by necessity. │ │ │ │ │ + * Property: baseLayersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + baseLayersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isFixed │ │ │ │ │ - * {Boolean} EventPaned layers are fixed by default. │ │ │ │ │ + * Property: baseLayers │ │ │ │ │ + * {Array(Object)} │ │ │ │ │ */ │ │ │ │ │ - isFixed: true, │ │ │ │ │ + baseLayers: null, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pane │ │ │ │ │ - * {DOMElement} A reference to the element that controls the events. │ │ │ │ │ + * Property: dataLbl │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - pane: null, │ │ │ │ │ + dataLbl: null, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Property: dataLayersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + dataLayersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: mapObject │ │ │ │ │ - * {Object} This is the object which will be used to load the 3rd party library │ │ │ │ │ - * in the case of the google layer, this will be of type GMap, │ │ │ │ │ - * in the case of the ve layer, this will be of type VEMap │ │ │ │ │ + * Property: dataLayers │ │ │ │ │ + * {Array(Object)} │ │ │ │ │ */ │ │ │ │ │ - mapObject: null, │ │ │ │ │ + dataLayers: null, │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.EventPane │ │ │ │ │ - * Create a new event pane layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * Property: minimizeDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - if (this.pane == null) { │ │ │ │ │ - this.pane = OpenLayers.Util.createDiv(this.div.id + "_EventPane"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + minimizeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct this layer. │ │ │ │ │ + * Property: maximizeDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.mapObject = null; │ │ │ │ │ - this.pane = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + maximizeDiv: null, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: ascending │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + ascending: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Constructor: OpenLayers.Control.LayerSwitcher │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.layerStates = []; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1; │ │ │ │ │ - this.pane.style.display = this.div.style.display; │ │ │ │ │ - this.pane.style.width = "100%"; │ │ │ │ │ - this.pane.style.height = "100%"; │ │ │ │ │ - if (OpenLayers.BROWSER_NAME == "msie") { │ │ │ │ │ - this.pane.style.background = │ │ │ │ │ - "url(" + OpenLayers.Util.getImageLocation("blank.gif") + ")"; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ │ │ │ │ │ - if (this.isFixed) { │ │ │ │ │ - this.map.viewPortDiv.appendChild(this.pane); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.layerContainerDiv.appendChild(this.pane); │ │ │ │ │ - } │ │ │ │ │ + //clear out layers info and unregister their events │ │ │ │ │ + this.clearLayersArray("base"); │ │ │ │ │ + this.clearLayersArray("data"); │ │ │ │ │ │ │ │ │ │ - // once our layer has been added to the map, we can load it │ │ │ │ │ - this.loadMapObject(); │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + addlayer: this.redraw, │ │ │ │ │ + changelayer: this.redraw, │ │ │ │ │ + removelayer: this.redraw, │ │ │ │ │ + changebaselayer: this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ │ │ │ │ │ - // if map didn't load, display warning │ │ │ │ │ - if (this.mapObject == null) { │ │ │ │ │ - this.loadWarningMessage(); │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: removeMap │ │ │ │ │ - * On being removed from the map, we'll like to remove the invisible 'pane' │ │ │ │ │ - * div that we added to it on creation. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * │ │ │ │ │ + * Properties: │ │ │ │ │ * map - {} │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - if (this.pane && this.pane.parentNode) { │ │ │ │ │ - this.pane.parentNode.removeChild(this.pane); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + addlayer: this.redraw, │ │ │ │ │ + changelayer: this.redraw, │ │ │ │ │ + removelayer: this.redraw, │ │ │ │ │ + changebaselayer: this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + if (this.outsideViewport) { │ │ │ │ │ + this.events.attachToElement(this.div); │ │ │ │ │ + this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.prototype.removeMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: loadWarningMessage │ │ │ │ │ - * If we can't load the map lib, then display an error message to the │ │ │ │ │ - * user and tell them where to go for help. │ │ │ │ │ - * │ │ │ │ │ - * This function sets up the layout for the warning message. Each 3rd │ │ │ │ │ - * party layer must implement its own getWarningHTML() function to │ │ │ │ │ - * provide the actual warning message. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the │ │ │ │ │ + * switcher tabs. │ │ │ │ │ */ │ │ │ │ │ - loadWarningMessage: function() { │ │ │ │ │ - │ │ │ │ │ - this.div.style.backgroundColor = "darkblue"; │ │ │ │ │ - │ │ │ │ │ - var viewSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - var msgW = Math.min(viewSize.w, 300); │ │ │ │ │ - var msgH = Math.min(viewSize.h, 200); │ │ │ │ │ - var size = new OpenLayers.Size(msgW, msgH); │ │ │ │ │ - │ │ │ │ │ - var centerPx = new OpenLayers.Pixel(viewSize.w / 2, viewSize.h / 2); │ │ │ │ │ - │ │ │ │ │ - var topLeft = centerPx.add(-size.w / 2, -size.h / 2); │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this); │ │ │ │ │ │ │ │ │ │ - var div = OpenLayers.Util.createDiv(this.name + "_warning", │ │ │ │ │ - topLeft, │ │ │ │ │ - size, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - "auto"); │ │ │ │ │ + // create layout divs │ │ │ │ │ + this.loadContents(); │ │ │ │ │ │ │ │ │ │ - div.style.padding = "7px"; │ │ │ │ │ - div.style.backgroundColor = "yellow"; │ │ │ │ │ + // set mode to minimize │ │ │ │ │ + if (!this.outsideViewport) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - div.innerHTML = this.getWarningHTML(); │ │ │ │ │ - this.div.appendChild(div); │ │ │ │ │ - }, │ │ │ │ │ + // populate div with current info │ │ │ │ │ + this.redraw(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getWarningHTML │ │ │ │ │ - * To be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} String with information on why layer is broken, how to get │ │ │ │ │ - * it working. │ │ │ │ │ - */ │ │ │ │ │ - getWarningHTML: function() { │ │ │ │ │ - //should be implemented by subclasses │ │ │ │ │ - return ""; │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Set the display on the pane │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - OpenLayers.Layer.prototype.display.apply(this, arguments); │ │ │ │ │ - this.pane.style.display = this.div.style.display; │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + var button = evt.buttonElement; │ │ │ │ │ + if (button === this.minimizeDiv) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else if (button === this.maximizeDiv) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } else if (button._layerSwitcher === this.id) { │ │ │ │ │ + if (button["for"]) { │ │ │ │ │ + button = document.getElementById(button["for"]); │ │ │ │ │ + } │ │ │ │ │ + if (!button.disabled) { │ │ │ │ │ + if (button.type == "radio") { │ │ │ │ │ + button.checked = true; │ │ │ │ │ + this.map.setBaseLayer(this.map.getLayer(button._layer)); │ │ │ │ │ + } else { │ │ │ │ │ + button.checked = !button.checked; │ │ │ │ │ + this.updateMap(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setZIndex │ │ │ │ │ - * Set the z-index order for the pane. │ │ │ │ │ - * │ │ │ │ │ + * Method: clearLayersArray │ │ │ │ │ + * User specifies either "base" or "data". we then clear all the │ │ │ │ │ + * corresponding listeners, the div, and reinitialize a new array. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zIndex - {int} │ │ │ │ │ + * layersType - {String} │ │ │ │ │ */ │ │ │ │ │ - setZIndex: function(zIndex) { │ │ │ │ │ - OpenLayers.Layer.prototype.setZIndex.apply(this, arguments); │ │ │ │ │ - this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1; │ │ │ │ │ + clearLayersArray: function(layersType) { │ │ │ │ │ + this[layersType + "LayersDiv"].innerHTML = ""; │ │ │ │ │ + this[layersType + "Layers"] = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ + * Method: checkRedraw │ │ │ │ │ + * Checks if the layer state has changed since the last redraw() call. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ - * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer state changed since the last redraw() call. │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveByPx.apply(this, arguments); │ │ │ │ │ + checkRedraw: function() { │ │ │ │ │ + if (!this.layerStates.length || │ │ │ │ │ + (this.map.layers.length != this.layerStates.length)) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (this.dragPanMapObject) { │ │ │ │ │ - this.dragPanMapObject(dx, -dy); │ │ │ │ │ - } else { │ │ │ │ │ - this.moveTo(this.map.getCachedCenter()); │ │ │ │ │ + for (var i = 0, len = this.layerStates.length; i < len; i++) { │ │ │ │ │ + var layerState = this.layerStates[i]; │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + if ((layerState.name != layer.name) || │ │ │ │ │ + (layerState.inRange != layer.inRange) || │ │ │ │ │ + (layerState.id != layer.id) || │ │ │ │ │ + (layerState.visibility != layer.visibility)) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Handle calls to move the layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * Method: redraw │ │ │ │ │ + * Goes through and takes the current state of the Map and rebuilds the │ │ │ │ │ + * control to display that state. Groups base layers into a │ │ │ │ │ + * radio-button group and lists each data layer with a checkbox. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); │ │ │ │ │ + redraw: function() { │ │ │ │ │ + //if the state hasn't changed since last redraw, no need │ │ │ │ │ + // to do anything. Just return the existing div. │ │ │ │ │ + if (!this.checkRedraw()) { │ │ │ │ │ + return this.div; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (this.mapObject != null) { │ │ │ │ │ + //clear out previous layers │ │ │ │ │ + this.clearLayersArray("base"); │ │ │ │ │ + this.clearLayersArray("data"); │ │ │ │ │ │ │ │ │ │ - var newCenter = this.map.getCenter(); │ │ │ │ │ - var newZoom = this.map.getZoom(); │ │ │ │ │ + var containsOverlays = false; │ │ │ │ │ + var containsBaseLayers = false; │ │ │ │ │ │ │ │ │ │ - if (newCenter != null) { │ │ │ │ │ + // Save state -- for checking layer if the map state changed. │ │ │ │ │ + // We save this before redrawing, because in the process of redrawing │ │ │ │ │ + // we will trigger more visibility changes, and we want to not redraw │ │ │ │ │ + // and enter an infinite loop. │ │ │ │ │ + var len = this.map.layers.length; │ │ │ │ │ + this.layerStates = new Array(len); │ │ │ │ │ + for (var i = 0; i < len; i++) { │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + this.layerStates[i] = { │ │ │ │ │ + 'name': layer.name, │ │ │ │ │ + 'visibility': layer.visibility, │ │ │ │ │ + 'inRange': layer.inRange, │ │ │ │ │ + 'id': layer.id │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var moOldCenter = this.getMapObjectCenter(); │ │ │ │ │ - var oldCenter = this.getOLLonLatFromMapObjectLonLat(moOldCenter); │ │ │ │ │ + var layers = this.map.layers.slice(); │ │ │ │ │ + if (!this.ascending) { │ │ │ │ │ + layers.reverse(); │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + var layer = layers[i]; │ │ │ │ │ + var baseLayer = layer.isBaseLayer; │ │ │ │ │ │ │ │ │ │ - var moOldZoom = this.getMapObjectZoom(); │ │ │ │ │ - var oldZoom = this.getOLZoomFromMapObjectZoom(moOldZoom); │ │ │ │ │ + if (layer.displayInLayerSwitcher) { │ │ │ │ │ │ │ │ │ │ - if (!(newCenter.equals(oldCenter)) || newZoom != oldZoom) { │ │ │ │ │ + if (baseLayer) { │ │ │ │ │ + containsBaseLayers = true; │ │ │ │ │ + } else { │ │ │ │ │ + containsOverlays = true; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (!zoomChanged && oldCenter && this.dragPanMapObject && │ │ │ │ │ - this.smoothDragPan) { │ │ │ │ │ - var oldPx = this.map.getViewPortPxFromLonLat(oldCenter); │ │ │ │ │ - var newPx = this.map.getViewPortPxFromLonLat(newCenter); │ │ │ │ │ - this.dragPanMapObject(newPx.x - oldPx.x, oldPx.y - newPx.y); │ │ │ │ │ - } else { │ │ │ │ │ - var center = this.getMapObjectLonLatFromOLLonLat(newCenter); │ │ │ │ │ - var zoom = this.getMapObjectZoomFromOLZoom(newZoom); │ │ │ │ │ - this.setMapObjectCenter(center, zoom, dragging); │ │ │ │ │ - } │ │ │ │ │ + // only check a baselayer if it is *the* baselayer, check data │ │ │ │ │ + // layers if they are visible │ │ │ │ │ + var checked = (baseLayer) ? (layer == this.map.baseLayer) : │ │ │ │ │ + layer.getVisibility(); │ │ │ │ │ + │ │ │ │ │ + // create input element │ │ │ │ │ + var inputElem = document.createElement("input"), │ │ │ │ │ + // The input shall have an id attribute so we can use │ │ │ │ │ + // labels to interact with them. │ │ │ │ │ + inputId = OpenLayers.Util.createUniqueID( │ │ │ │ │ + this.id + "_input_" │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + inputElem.id = inputId; │ │ │ │ │ + inputElem.name = (baseLayer) ? this.id + "_baseLayers" : layer.name; │ │ │ │ │ + inputElem.type = (baseLayer) ? "radio" : "checkbox"; │ │ │ │ │ + inputElem.value = layer.name; │ │ │ │ │ + inputElem.checked = checked; │ │ │ │ │ + inputElem.defaultChecked = checked; │ │ │ │ │ + inputElem.className = "olButton"; │ │ │ │ │ + inputElem._layer = layer.id; │ │ │ │ │ + inputElem._layerSwitcher = this.id; │ │ │ │ │ + │ │ │ │ │ + if (!baseLayer && !layer.inRange) { │ │ │ │ │ + inputElem.disabled = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // create span │ │ │ │ │ + var labelSpan = document.createElement("label"); │ │ │ │ │ + // this isn't the DOM attribute 'for', but an arbitrary name we │ │ │ │ │ + // use to find the appropriate input element in │ │ │ │ │ + labelSpan["for"] = inputElem.id; │ │ │ │ │ + OpenLayers.Element.addClass(labelSpan, "labelSpan olButton"); │ │ │ │ │ + labelSpan._layer = layer.id; │ │ │ │ │ + labelSpan._layerSwitcher = this.id; │ │ │ │ │ + if (!baseLayer && !layer.inRange) { │ │ │ │ │ + labelSpan.style.color = "gray"; │ │ │ │ │ } │ │ │ │ │ + labelSpan.innerHTML = layer.name; │ │ │ │ │ + labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : │ │ │ │ │ + "baseline"; │ │ │ │ │ + // create line break │ │ │ │ │ + var br = document.createElement("br"); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + var groupArray = (baseLayer) ? this.baseLayers : │ │ │ │ │ + this.dataLayers; │ │ │ │ │ + groupArray.push({ │ │ │ │ │ + 'layer': layer, │ │ │ │ │ + 'inputElem': inputElem, │ │ │ │ │ + 'labelSpan': labelSpan │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + var groupDiv = (baseLayer) ? this.baseLayersDiv : │ │ │ │ │ + this.dataLayersDiv; │ │ │ │ │ + groupDiv.appendChild(inputElem); │ │ │ │ │ + groupDiv.appendChild(labelSpan); │ │ │ │ │ + groupDiv.appendChild(br); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + // if no overlays, dont display the overlay label │ │ │ │ │ + this.dataLbl.style.display = (containsOverlays) ? "" : "none"; │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ + // if no baselayers, dont display the baselayer label │ │ │ │ │ + this.baseLbl.style.display = (containsBaseLayers) ? "" : "none"; │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromViewPortPx │ │ │ │ │ - * Get a map location from a pixel location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ - * port OpenLayers.Pixel, translated into lon/lat by map lib │ │ │ │ │ - * If the map lib is not loaded or not centered, returns null │ │ │ │ │ + * Method: updateMap │ │ │ │ │ + * Cycles through the loaded data and base layer input arrays and makes │ │ │ │ │ + * the necessary calls to the Map object such that that the map's │ │ │ │ │ + * visual state corresponds to what the user has selected in │ │ │ │ │ + * the control. │ │ │ │ │ */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - if ((this.mapObject != null) && │ │ │ │ │ - (this.getMapObjectCenter() != null)) { │ │ │ │ │ - var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx); │ │ │ │ │ - var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel); │ │ │ │ │ - lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat); │ │ │ │ │ + updateMap: function() { │ │ │ │ │ + │ │ │ │ │ + // set the newly selected base layer │ │ │ │ │ + for (var i = 0, len = this.baseLayers.length; i < len; i++) { │ │ │ │ │ + var layerEntry = this.baseLayers[i]; │ │ │ │ │ + if (layerEntry.inputElem.checked) { │ │ │ │ │ + this.map.setBaseLayer(layerEntry.layer, false); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // set the correct visibilities for the overlays │ │ │ │ │ + for (var i = 0, len = this.dataLayers.length; i < len; i++) { │ │ │ │ │ + var layerEntry = this.dataLayers[i]; │ │ │ │ │ + layerEntry.layer.setVisibility(layerEntry.inputElem.checked); │ │ │ │ │ } │ │ │ │ │ - return lonlat; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getViewPortPxFromLonLat │ │ │ │ │ - * Get a pixel location from a map location │ │ │ │ │ + * Method: maximizeControl │ │ │ │ │ + * Set up the labels and divs for the control │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * OpenLayers.LonLat, translated into view port pixels by map lib │ │ │ │ │ - * If map lib is not loaded or not centered, returns null │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ - var viewPortPx = null; │ │ │ │ │ - if ((this.mapObject != null) && │ │ │ │ │ - (this.getMapObjectCenter() != null)) { │ │ │ │ │ + maximizeControl: function(e) { │ │ │ │ │ │ │ │ │ │ - var moLonLat = this.getMapObjectLonLatFromOLLonLat(lonlat); │ │ │ │ │ - var moPixel = this.getMapObjectPixelFromMapObjectLonLat(moLonLat); │ │ │ │ │ + // set the div's width and height to empty values, so │ │ │ │ │ + // the div dimensions can be controlled by CSS │ │ │ │ │ + this.div.style.width = ""; │ │ │ │ │ + this.div.style.height = ""; │ │ │ │ │ │ │ │ │ │ - viewPortPx = this.getOLPixelFromMapObjectPixel(moPixel); │ │ │ │ │ + this.showControls(false); │ │ │ │ │ + │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ - return viewPortPx; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Translation Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions translate Map Object and */ │ │ │ │ │ - /* OL formats for Pixel, LonLat */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: MapObject LatLng <-> OpenLayers.LonLat │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getOLLonLatFromMapObjectLonLat │ │ │ │ │ - * Get an OL style map location from a 3rd party style map location │ │ │ │ │ + * Method: minimizeControl │ │ │ │ │ + * Hide all the contents of the control, shrink the size, │ │ │ │ │ + * add the maximize icon │ │ │ │ │ * │ │ │ │ │ - * Parameters │ │ │ │ │ - * moLonLat - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat, translated from the passed in │ │ │ │ │ - * MapObject LonLat │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - getOLLonLatFromMapObjectLonLat: function(moLonLat) { │ │ │ │ │ - var olLonLat = null; │ │ │ │ │ - if (moLonLat != null) { │ │ │ │ │ - var lon = this.getLongitudeFromMapObjectLonLat(moLonLat); │ │ │ │ │ - var lat = this.getLatitudeFromMapObjectLonLat(moLonLat); │ │ │ │ │ - olLonLat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ + minimizeControl: function(e) { │ │ │ │ │ + │ │ │ │ │ + // to minimize the control we set its div's width │ │ │ │ │ + // and height to 0px, we cannot just set "display" │ │ │ │ │ + // to "none" because it would hide the maximize │ │ │ │ │ + // div │ │ │ │ │ + this.div.style.width = "0px"; │ │ │ │ │ + this.div.style.height = "0px"; │ │ │ │ │ + │ │ │ │ │ + this.showControls(true); │ │ │ │ │ + │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ - return olLonLat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapObjectLonLatFromOLLonLat │ │ │ │ │ - * Get a 3rd party map location from an OL map location. │ │ │ │ │ + * Method: showControls │ │ │ │ │ + * Hide/Show all LayerSwitcher controls depending on whether we are │ │ │ │ │ + * minimized or not │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * olLonLat - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A MapObject LonLat, translated from the passed in │ │ │ │ │ - * OpenLayers.LonLat │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * minimize - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - getMapObjectLonLatFromOLLonLat: function(olLonLat) { │ │ │ │ │ - var moLatLng = null; │ │ │ │ │ - if (olLonLat != null) { │ │ │ │ │ - moLatLng = this.getMapObjectLonLatFromLonLat(olLonLat.lon, │ │ │ │ │ - olLonLat.lat); │ │ │ │ │ - } │ │ │ │ │ - return moLatLng; │ │ │ │ │ - }, │ │ │ │ │ + showControls: function(minimize) { │ │ │ │ │ │ │ │ │ │ + this.maximizeDiv.style.display = minimize ? "" : "none"; │ │ │ │ │ + this.minimizeDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: MapObject Pixel <-> OpenLayers.Pixel │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getOLPixelFromMapObjectPixel │ │ │ │ │ - * Get an OL pixel location from a 3rd party pixel location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * moPixel - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel, translated from the passed in │ │ │ │ │ - * MapObject Pixel │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ - */ │ │ │ │ │ - getOLPixelFromMapObjectPixel: function(moPixel) { │ │ │ │ │ - var olPixel = null; │ │ │ │ │ - if (moPixel != null) { │ │ │ │ │ - var x = this.getXFromMapObjectPixel(moPixel); │ │ │ │ │ - var y = this.getYFromMapObjectPixel(moPixel); │ │ │ │ │ - olPixel = new OpenLayers.Pixel(x, y); │ │ │ │ │ - } │ │ │ │ │ - return olPixel; │ │ │ │ │ + this.layersDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapObjectPixelFromOLPixel │ │ │ │ │ - * Get a 3rd party pixel location from an OL pixel location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * olPixel - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A MapObject Pixel, translated from the passed in │ │ │ │ │ - * OpenLayers.Pixel │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * Method: loadContents │ │ │ │ │ + * Set up the labels and divs for the control │ │ │ │ │ */ │ │ │ │ │ - getMapObjectPixelFromOLPixel: function(olPixel) { │ │ │ │ │ - var moPixel = null; │ │ │ │ │ - if (olPixel != null) { │ │ │ │ │ - moPixel = this.getMapObjectPixelFromXY(olPixel.x, olPixel.y); │ │ │ │ │ + loadContents: function() { │ │ │ │ │ + │ │ │ │ │ + // layers list div │ │ │ │ │ + this.layersDiv = document.createElement("div"); │ │ │ │ │ + this.layersDiv.id = this.id + "_layersDiv"; │ │ │ │ │ + OpenLayers.Element.addClass(this.layersDiv, "layersDiv"); │ │ │ │ │ + │ │ │ │ │ + this.baseLbl = document.createElement("div"); │ │ │ │ │ + this.baseLbl.innerHTML = OpenLayers.i18n("Base Layer"); │ │ │ │ │ + OpenLayers.Element.addClass(this.baseLbl, "baseLbl"); │ │ │ │ │ + │ │ │ │ │ + this.baseLayersDiv = document.createElement("div"); │ │ │ │ │ + OpenLayers.Element.addClass(this.baseLayersDiv, "baseLayersDiv"); │ │ │ │ │ + │ │ │ │ │ + this.dataLbl = document.createElement("div"); │ │ │ │ │ + this.dataLbl.innerHTML = OpenLayers.i18n("Overlays"); │ │ │ │ │ + OpenLayers.Element.addClass(this.dataLbl, "dataLbl"); │ │ │ │ │ + │ │ │ │ │ + this.dataLayersDiv = document.createElement("div"); │ │ │ │ │ + OpenLayers.Element.addClass(this.dataLayersDiv, "dataLayersDiv"); │ │ │ │ │ + │ │ │ │ │ + if (this.ascending) { │ │ │ │ │ + this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ + } else { │ │ │ │ │ + this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ } │ │ │ │ │ - return moPixel; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.layersDiv); │ │ │ │ │ + │ │ │ │ │ + // maximize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ + this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + "OpenLayers_Control_MaximizeDiv", │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + "absolute"); │ │ │ │ │ + OpenLayers.Element.addClass(this.maximizeDiv, "maximizeDiv olButton"); │ │ │ │ │ + this.maximizeDiv.style.display = "none"; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.maximizeDiv); │ │ │ │ │ + │ │ │ │ │ + // minimize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ + this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + "OpenLayers_Control_MinimizeDiv", │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + "absolute"); │ │ │ │ │ + OpenLayers.Element.addClass(this.minimizeDiv, "minimizeDiv olButton"); │ │ │ │ │ + this.minimizeDiv.style.display = "none"; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.minimizeDiv); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.EventPane" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.LayerSwitcher" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Zoomify.js │ │ │ │ │ + OpenLayers/Control/OverviewMap.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. */ │ │ │ │ │ │ │ │ │ │ -/* │ │ │ │ │ - * Development supported by a R&D grant DC08P02OUK006 - Old Maps Online │ │ │ │ │ - * (www.oldmapsonline.org) from Ministry of Culture of the Czech Republic. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + * @requires OpenLayers/Map.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Zoomify │ │ │ │ │ + * Class: OpenLayers.Control.OverviewMap │ │ │ │ │ + * The OverMap control creates a small overview map, useful to display the │ │ │ │ │ + * extent of a zoomed map and your main map and provide additional │ │ │ │ │ + * navigation options to the User. By default the overview map is drawn in │ │ │ │ │ + * the lower right corner of the main map. Create a new overview map with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.Zoomify = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} The Zoomify image size in pixels. │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} The DOM element that contains the overview map │ │ │ │ │ */ │ │ │ │ │ - size: null, │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * APIProperty: ovmap │ │ │ │ │ + * {} A reference to the overview map itself. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + ovmap: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: standardTileSize │ │ │ │ │ - * {Integer} The size of a standard (non-border) square tile in pixels. │ │ │ │ │ + * APIProperty: size │ │ │ │ │ + * {} The overvew map size in pixels. Note that this is │ │ │ │ │ + * the size of the map itself - the element that contains the map (default │ │ │ │ │ + * class name olControlOverviewMapElement) may have padding or other style │ │ │ │ │ + * attributes added via CSS. │ │ │ │ │ */ │ │ │ │ │ - standardTileSize: 256, │ │ │ │ │ + size: { │ │ │ │ │ + w: 180, │ │ │ │ │ + h: 90 │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileOriginCorner │ │ │ │ │ - * {String} This layer uses top-left as tile origin │ │ │ │ │ - **/ │ │ │ │ │ - tileOriginCorner: "tl", │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} Ordered list of layers in the overview map. │ │ │ │ │ + * If none are sent at construction, the base layer for the main map is used. │ │ │ │ │ + */ │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: numberOfTiers │ │ │ │ │ - * {Integer} Depth of the Zoomify pyramid, number of tiers (zoom levels) │ │ │ │ │ - * - filled during Zoomify pyramid initialization. │ │ │ │ │ + * APIProperty: minRectSize │ │ │ │ │ + * {Integer} The minimum width or height (in pixels) of the extent │ │ │ │ │ + * rectangle on the overview map. When the extent rectangle reaches │ │ │ │ │ + * this size, it will be replaced depending on the value of the │ │ │ │ │ + * property. Default is 15 pixels. │ │ │ │ │ */ │ │ │ │ │ - numberOfTiers: 0, │ │ │ │ │ + minRectSize: 15, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: tileCountUpToTier │ │ │ │ │ - * {Array(Integer)} Number of tiles up to the given tier of pyramid. │ │ │ │ │ - * - filled during Zoomify pyramid initialization. │ │ │ │ │ + * APIProperty: minRectDisplayClass │ │ │ │ │ + * {String} Replacement style class name for the extent rectangle when │ │ │ │ │ + * is reached. This string will be suffixed on to the │ │ │ │ │ + * displayClass. Default is "RectReplacement". │ │ │ │ │ + * │ │ │ │ │ + * Example CSS declaration: │ │ │ │ │ + * (code) │ │ │ │ │ + * .olControlOverviewMapRectReplacement { │ │ │ │ │ + * overflow: hidden; │ │ │ │ │ + * cursor: move; │ │ │ │ │ + * background-image: url("img/overview_replacement.gif"); │ │ │ │ │ + * background-repeat: no-repeat; │ │ │ │ │ + * background-position: center; │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - tileCountUpToTier: null, │ │ │ │ │ + minRectDisplayClass: "RectReplacement", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: tierSizeInTiles │ │ │ │ │ - * {Array()} Size (in tiles) for each tier of pyramid. │ │ │ │ │ - * - filled during Zoomify pyramid initialization. │ │ │ │ │ + * APIProperty: minRatio │ │ │ │ │ + * {Float} The ratio of the overview map resolution to the main map │ │ │ │ │ + * resolution at which to zoom farther out on the overview map. │ │ │ │ │ */ │ │ │ │ │ - tierSizeInTiles: null, │ │ │ │ │ + minRatio: 8, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: tierImageSize │ │ │ │ │ - * {Array()} Image size in pixels for each pyramid tier. │ │ │ │ │ - * - filled during Zoomify pyramid initialization. │ │ │ │ │ + * APIProperty: maxRatio │ │ │ │ │ + * {Float} The ratio of the overview map resolution to the main map │ │ │ │ │ + * resolution at which to zoom farther in on the overview map. │ │ │ │ │ */ │ │ │ │ │ - tierImageSize: null, │ │ │ │ │ + maxRatio: 32, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Zoomify │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} A name for the layer. │ │ │ │ │ - * url - {String} - Relative or absolute path to the image or more │ │ │ │ │ - * precisly to the TileGroup[X] directories root. │ │ │ │ │ - * Flash plugin use the variable name "zoomifyImagePath" for this. │ │ │ │ │ - * size - {} The size (in pixels) of the image. │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * APIProperty: mapOptions │ │ │ │ │ + * {Object} An object containing any non-default properties to be sent to │ │ │ │ │ + * the overview map's map constructor. These should include any │ │ │ │ │ + * non-default options that the main map was constructed with. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, size, options) { │ │ │ │ │ + mapOptions: null, │ │ │ │ │ │ │ │ │ │ - // initilize the Zoomify pyramid for given size │ │ │ │ │ - this.initializeZoomify(size); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: autoPan │ │ │ │ │ + * {Boolean} Always pan the overview map, so the extent marker remains in │ │ │ │ │ + * the center. Default is false. If true, when you drag the extent │ │ │ │ │ + * marker, the overview map will update itself so the marker returns │ │ │ │ │ + * to the center. │ │ │ │ │ + */ │ │ │ │ │ + autoPan: false, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, [ │ │ │ │ │ - name, url, size, {}, │ │ │ │ │ - options │ │ │ │ │ - ]); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: handlers │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + handlers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initializeZoomify │ │ │ │ │ - * It generates constants for all tiers of the Zoomify pyramid │ │ │ │ │ + * Property: resolutionFactor │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + resolutionFactor: 1, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maximized │ │ │ │ │ + * {Boolean} Start as maximized (visible). Defaults to false. │ │ │ │ │ + */ │ │ │ │ │ + maximized: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maximizeTitle │ │ │ │ │ + * {String} This property is used for showing a tooltip over the │ │ │ │ │ + * maximize div. Defaults to "" (no title). │ │ │ │ │ + */ │ │ │ │ │ + maximizeTitle: "", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minimizeTitle │ │ │ │ │ + * {String} This property is used for showing a tooltip over the │ │ │ │ │ + * minimize div. Defaults to "" (no title). │ │ │ │ │ + */ │ │ │ │ │ + minimizeTitle: "", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.OverviewMap │ │ │ │ │ + * Create a new overview map │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * size - {} The size of the image in pixels │ │ │ │ │ - * │ │ │ │ │ + * options - {Object} Properties of this object will be set on the overview │ │ │ │ │ + * map object. Note, to set options on the map object contained in this │ │ │ │ │ + * control, set as one of the options properties. │ │ │ │ │ */ │ │ │ │ │ - initializeZoomify: function(size) { │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.layers = []; │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var imageSize = size.clone(); │ │ │ │ │ - this.size = size.clone(); │ │ │ │ │ - var tiles = new OpenLayers.Size( │ │ │ │ │ - Math.ceil(imageSize.w / this.standardTileSize), │ │ │ │ │ - Math.ceil(imageSize.h / this.standardTileSize) │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Deconstruct the control │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (!this.mapDiv) { // we've already been destroyed │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.handlers.click) { │ │ │ │ │ + this.handlers.click.destroy(); │ │ │ │ │ + } │ │ │ │ │ + if (this.handlers.drag) { │ │ │ │ │ + this.handlers.drag.destroy(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.tierSizeInTiles = [tiles]; │ │ │ │ │ - this.tierImageSize = [imageSize]; │ │ │ │ │ + this.ovmap && this.ovmap.viewPortDiv.removeChild(this.extentRectangle); │ │ │ │ │ + this.extentRectangle = null; │ │ │ │ │ │ │ │ │ │ - while (imageSize.w > this.standardTileSize || │ │ │ │ │ - imageSize.h > this.standardTileSize) { │ │ │ │ │ + if (this.rectEvents) { │ │ │ │ │ + this.rectEvents.destroy(); │ │ │ │ │ + this.rectEvents = null; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - imageSize = new OpenLayers.Size( │ │ │ │ │ - Math.floor(imageSize.w / 2), │ │ │ │ │ - Math.floor(imageSize.h / 2) │ │ │ │ │ - ); │ │ │ │ │ - tiles = new OpenLayers.Size( │ │ │ │ │ - Math.ceil(imageSize.w / this.standardTileSize), │ │ │ │ │ - Math.ceil(imageSize.h / this.standardTileSize) │ │ │ │ │ - ); │ │ │ │ │ - this.tierSizeInTiles.push(tiles); │ │ │ │ │ - this.tierImageSize.push(imageSize); │ │ │ │ │ + if (this.ovmap) { │ │ │ │ │ + this.ovmap.destroy(); │ │ │ │ │ + this.ovmap = null; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - this.tierSizeInTiles.reverse(); │ │ │ │ │ - this.tierImageSize.reverse(); │ │ │ │ │ + this.element.removeChild(this.mapDiv); │ │ │ │ │ + this.mapDiv = null; │ │ │ │ │ │ │ │ │ │ - this.numberOfTiers = this.tierSizeInTiles.length; │ │ │ │ │ - var resolutions = [1]; │ │ │ │ │ - this.tileCountUpToTier = [0]; │ │ │ │ │ - for (var i = 1; i < this.numberOfTiers; i++) { │ │ │ │ │ - resolutions.unshift(Math.pow(2, i)); │ │ │ │ │ - this.tileCountUpToTier.push( │ │ │ │ │ - this.tierSizeInTiles[i - 1].w * this.tierSizeInTiles[i - 1].h + │ │ │ │ │ - this.tileCountUpToTier[i - 1] │ │ │ │ │ - ); │ │ │ │ │ + this.div.removeChild(this.element); │ │ │ │ │ + this.element = null; │ │ │ │ │ + │ │ │ │ │ + if (this.maximizeDiv) { │ │ │ │ │ + this.div.removeChild(this.maximizeDiv); │ │ │ │ │ + this.maximizeDiv = null; │ │ │ │ │ } │ │ │ │ │ - if (!this.serverResolutions) { │ │ │ │ │ - this.serverResolutions = resolutions; │ │ │ │ │ + │ │ │ │ │ + if (this.minimizeDiv) { │ │ │ │ │ + this.div.removeChild(this.minimizeDiv); │ │ │ │ │ + this.minimizeDiv = null; │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + moveend: this.update, │ │ │ │ │ + changebaselayer: this.baseLayerDraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod:destroy │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Render the control in the browser. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // for now, nothing special to do here. │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments); │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.layers.length === 0) { │ │ │ │ │ + if (this.map.baseLayer) { │ │ │ │ │ + var layer = this.map.baseLayer.clone(); │ │ │ │ │ + this.layers = [layer]; │ │ │ │ │ + } else { │ │ │ │ │ + this.map.events.register("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ + return this.div; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // Remove from memory the Zoomify pyramid - is that enough? │ │ │ │ │ - this.tileCountUpToTier.length = 0; │ │ │ │ │ - this.tierSizeInTiles.length = 0; │ │ │ │ │ - this.tierImageSize.length = 0; │ │ │ │ │ + // create overview map DOM elements │ │ │ │ │ + this.element = document.createElement('div'); │ │ │ │ │ + this.element.className = this.displayClass + 'Element'; │ │ │ │ │ + this.element.style.display = 'none'; │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ + this.mapDiv = document.createElement('div'); │ │ │ │ │ + this.mapDiv.style.width = this.size.w + 'px'; │ │ │ │ │ + this.mapDiv.style.height = this.size.h + 'px'; │ │ │ │ │ + this.mapDiv.style.position = 'relative'; │ │ │ │ │ + this.mapDiv.style.overflow = 'hidden'; │ │ │ │ │ + this.mapDiv.id = OpenLayers.Util.createUniqueID('overviewMap'); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + this.extentRectangle = document.createElement('div'); │ │ │ │ │ + this.extentRectangle.style.position = 'absolute'; │ │ │ │ │ + this.extentRectangle.style.zIndex = 1000; //HACK │ │ │ │ │ + this.extentRectangle.className = this.displayClass + 'ExtentRectangle'; │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Zoomify(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.size, │ │ │ │ │ - this.options); │ │ │ │ │ + this.element.appendChild(this.mapDiv); │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.element); │ │ │ │ │ + │ │ │ │ │ + // Optionally add min/max buttons if the control will go in the │ │ │ │ │ + // map viewport. │ │ │ │ │ + if (!this.outsideViewport) { │ │ │ │ │ + this.div.className += " " + this.displayClass + 'Container'; │ │ │ │ │ + // maximize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ + this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + this.displayClass + 'MaximizeButton', │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + 'absolute'); │ │ │ │ │ + this.maximizeDiv.style.display = 'none'; │ │ │ │ │ + this.maximizeDiv.className = this.displayClass + 'MaximizeButton olButton'; │ │ │ │ │ + if (this.maximizeTitle) { │ │ │ │ │ + this.maximizeDiv.title = this.maximizeTitle; │ │ │ │ │ + } │ │ │ │ │ + this.div.appendChild(this.maximizeDiv); │ │ │ │ │ + │ │ │ │ │ + // minimize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ + this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + 'OpenLayers_Control_minimizeDiv', │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + 'absolute'); │ │ │ │ │ + this.minimizeDiv.style.display = 'none'; │ │ │ │ │ + this.minimizeDiv.className = this.displayClass + 'MinimizeButton olButton'; │ │ │ │ │ + if (this.minimizeTitle) { │ │ │ │ │ + this.minimizeDiv.title = this.minimizeTitle; │ │ │ │ │ + } │ │ │ │ │ + this.div.appendChild(this.minimizeDiv); │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else { │ │ │ │ │ + // show the overview map │ │ │ │ │ + this.element.style.display = ''; │ │ │ │ │ + } │ │ │ │ │ + if (this.map.getExtent()) { │ │ │ │ │ + this.update(); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + moveend: this.update, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ + if (this.maximized) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + /** │ │ │ │ │ + * Method: baseLayerDraw │ │ │ │ │ + * Draw the base layer - called if unable to complete in the initial draw │ │ │ │ │ + */ │ │ │ │ │ + baseLayerDraw: function() { │ │ │ │ │ + this.draw(); │ │ │ │ │ + this.map.events.unregister("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ + * Method: rectDrag │ │ │ │ │ + * Handle extent rectangle drag │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters │ │ │ │ │ + * px - {} The pixel location of the drag. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - var res = this.getServerResolution(); │ │ │ │ │ - var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); │ │ │ │ │ - var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h)); │ │ │ │ │ - var z = this.getZoomForResolution(res); │ │ │ │ │ - │ │ │ │ │ - var tileIndex = x + y * this.tierSizeInTiles[z].w + this.tileCountUpToTier[z]; │ │ │ │ │ - var path = "TileGroup" + Math.floor((tileIndex) / 256) + │ │ │ │ │ - "/" + z + "-" + x + "-" + y + ".jpg"; │ │ │ │ │ - var url = this.url; │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(path, url); │ │ │ │ │ + rectDrag: function(px) { │ │ │ │ │ + var deltaX = this.handlers.drag.last.x - px.x; │ │ │ │ │ + var deltaY = this.handlers.drag.last.y - px.y; │ │ │ │ │ + if (deltaX != 0 || deltaY != 0) { │ │ │ │ │ + var rectTop = this.rectPxBounds.top; │ │ │ │ │ + var rectLeft = this.rectPxBounds.left; │ │ │ │ │ + var rectHeight = Math.abs(this.rectPxBounds.getHeight()); │ │ │ │ │ + var rectWidth = this.rectPxBounds.getWidth(); │ │ │ │ │ + // don't allow dragging off of parent element │ │ │ │ │ + var newTop = Math.max(0, (rectTop - deltaY)); │ │ │ │ │ + newTop = Math.min(newTop, │ │ │ │ │ + this.ovmap.size.h - this.hComp - rectHeight); │ │ │ │ │ + var newLeft = Math.max(0, (rectLeft - deltaX)); │ │ │ │ │ + newLeft = Math.min(newLeft, │ │ │ │ │ + this.ovmap.size.w - this.wComp - rectWidth); │ │ │ │ │ + this.setRectPxBounds(new OpenLayers.Bounds(newLeft, │ │ │ │ │ + newTop + rectHeight, │ │ │ │ │ + newLeft + rectWidth, │ │ │ │ │ + newTop)); │ │ │ │ │ } │ │ │ │ │ - return url + path; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getImageSize │ │ │ │ │ - * getImageSize returns size for a particular tile. If bounds are given as │ │ │ │ │ - * first argument, size is calculated (bottom-right tiles are non square). │ │ │ │ │ + * Method: mapDivClick │ │ │ │ │ + * Handle browser events │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} evt │ │ │ │ │ */ │ │ │ │ │ - getImageSize: function() { │ │ │ │ │ - if (arguments.length > 0) { │ │ │ │ │ - var bounds = this.adjustBounds(arguments[0]); │ │ │ │ │ - var res = this.getServerResolution(); │ │ │ │ │ - var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); │ │ │ │ │ - var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h)); │ │ │ │ │ - var z = this.getZoomForResolution(res); │ │ │ │ │ - var w = this.standardTileSize; │ │ │ │ │ - var h = this.standardTileSize; │ │ │ │ │ - if (x == this.tierSizeInTiles[z].w - 1) { │ │ │ │ │ - var w = this.tierImageSize[z].w % this.standardTileSize; │ │ │ │ │ - } │ │ │ │ │ - if (y == this.tierSizeInTiles[z].h - 1) { │ │ │ │ │ - var h = this.tierImageSize[z].h % this.standardTileSize; │ │ │ │ │ - } │ │ │ │ │ - return (new OpenLayers.Size(w, h)); │ │ │ │ │ - } else { │ │ │ │ │ - return this.tileSize; │ │ │ │ │ - } │ │ │ │ │ + mapDivClick: function(evt) { │ │ │ │ │ + var pxCenter = this.rectPxBounds.getCenterPixel(); │ │ │ │ │ + var deltaX = evt.xy.x - pxCenter.x; │ │ │ │ │ + var deltaY = evt.xy.y - pxCenter.y; │ │ │ │ │ + var top = this.rectPxBounds.top; │ │ │ │ │ + var left = this.rectPxBounds.left; │ │ │ │ │ + var height = Math.abs(this.rectPxBounds.getHeight()); │ │ │ │ │ + var width = this.rectPxBounds.getWidth(); │ │ │ │ │ + var newTop = Math.max(0, (top + deltaY)); │ │ │ │ │ + newTop = Math.min(newTop, this.ovmap.size.h - height); │ │ │ │ │ + var newLeft = Math.max(0, (left + deltaX)); │ │ │ │ │ + newLeft = Math.min(newLeft, this.ovmap.size.w - width); │ │ │ │ │ + this.setRectPxBounds(new OpenLayers.Bounds(newLeft, │ │ │ │ │ + newTop + height, │ │ │ │ │ + newLeft + width, │ │ │ │ │ + newTop)); │ │ │ │ │ + this.updateMapToRect(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setMap │ │ │ │ │ - * When the layer is added to a map, then we can fetch our origin │ │ │ │ │ - * (if we don't have one.) │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments); │ │ │ │ │ - this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left, │ │ │ │ │ - this.map.maxExtent.top); │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + if (evt.buttonElement === this.minimizeDiv) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else if (evt.buttonElement === this.maximizeDiv) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Zoomify" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/PointTrack.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/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.PointTrack │ │ │ │ │ - * Vector layer to display ordered point features as a line, creating one │ │ │ │ │ - * LineString feature for each pair of two points. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dataFrom │ │ │ │ │ - * {} or │ │ │ │ │ - * {} optional. If the lines │ │ │ │ │ - * should get the data/attributes from one of the two points it is │ │ │ │ │ - * composed of, which one should it be? │ │ │ │ │ + * Method: maximizeControl │ │ │ │ │ + * Unhide the control. Called when the control is in the map viewport. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {} │ │ │ │ │ */ │ │ │ │ │ - dataFrom: null, │ │ │ │ │ + maximizeControl: function(e) { │ │ │ │ │ + this.element.style.display = ''; │ │ │ │ │ + this.showToggle(false); │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: styleFrom │ │ │ │ │ - * {} or │ │ │ │ │ - * {} optional. If the lines │ │ │ │ │ - * should get the style from one of the two points it is composed of, │ │ │ │ │ - * which one should it be? │ │ │ │ │ + * Method: minimizeControl │ │ │ │ │ + * Hide all the contents of the control, shrink the size, │ │ │ │ │ + * add the maximize icon │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {} │ │ │ │ │ */ │ │ │ │ │ - styleFrom: null, │ │ │ │ │ + minimizeControl: function(e) { │ │ │ │ │ + this.element.style.display = 'none'; │ │ │ │ │ + this.showToggle(true); │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.PointTrack │ │ │ │ │ - * Constructor for a new OpenLayers.PointTrack instance. │ │ │ │ │ + * Method: showToggle │ │ │ │ │ + * Hide/Show the toggle depending on whether the control is minimized │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} name of the layer │ │ │ │ │ - * options - {Object} Optional object with properties to tag onto the │ │ │ │ │ - * instance. │ │ │ │ │ + * minimize - {Boolean} │ │ │ │ │ */ │ │ │ │ │ + showToggle: function(minimize) { │ │ │ │ │ + if (this.maximizeDiv) { │ │ │ │ │ + this.maximizeDiv.style.display = minimize ? '' : 'none'; │ │ │ │ │ + } │ │ │ │ │ + if (this.minimizeDiv) { │ │ │ │ │ + this.minimizeDiv.style.display = minimize ? 'none' : ''; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addNodes │ │ │ │ │ - * Adds point features that will be used to create lines from, using point │ │ │ │ │ - * pairs. The first point of a pair will be the source node, the second │ │ │ │ │ - * will be the target node. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pointFeatures - {Array()} │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Supported options: │ │ │ │ │ - * silent - {Boolean} true to suppress (before)feature(s)added events │ │ │ │ │ + * Method: update │ │ │ │ │ + * Update the overview map after layers move. │ │ │ │ │ */ │ │ │ │ │ - addNodes: function(pointFeatures, options) { │ │ │ │ │ - if (pointFeatures.length < 2) { │ │ │ │ │ - throw new Error("At least two point features have to be added to " + │ │ │ │ │ - "create a line from"); │ │ │ │ │ + update: function() { │ │ │ │ │ + if (this.ovmap == null) { │ │ │ │ │ + this.createMap(); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - var lines = new Array(pointFeatures.length - 1); │ │ │ │ │ - │ │ │ │ │ - var pointFeature, startPoint, endPoint; │ │ │ │ │ - for (var i = 0, len = pointFeatures.length; i < len; i++) { │ │ │ │ │ - pointFeature = pointFeatures[i]; │ │ │ │ │ - endPoint = pointFeature.geometry; │ │ │ │ │ - │ │ │ │ │ - if (!endPoint) { │ │ │ │ │ - var lonlat = pointFeature.lonlat; │ │ │ │ │ - endPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat); │ │ │ │ │ - } else if (endPoint.CLASS_NAME != "OpenLayers.Geometry.Point") { │ │ │ │ │ - throw new TypeError("Only features with point geometries are supported."); │ │ │ │ │ - } │ │ │ │ │ + if (this.autoPan || !this.isSuitableOverview()) { │ │ │ │ │ + this.updateOverview(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (i > 0) { │ │ │ │ │ - var attributes = (this.dataFrom != null) ? │ │ │ │ │ - (pointFeatures[i + this.dataFrom].data || │ │ │ │ │ - pointFeatures[i + this.dataFrom].attributes) : │ │ │ │ │ - null; │ │ │ │ │ - var style = (this.styleFrom != null) ? │ │ │ │ │ - (pointFeatures[i + this.styleFrom].style) : │ │ │ │ │ - null; │ │ │ │ │ - var line = new OpenLayers.Geometry.LineString([startPoint, │ │ │ │ │ - endPoint │ │ │ │ │ - ]); │ │ │ │ │ + // update extent rectangle │ │ │ │ │ + this.updateRectToMap(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - lines[i - 1] = new OpenLayers.Feature.Vector(line, attributes, │ │ │ │ │ - style); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: isSuitableOverview │ │ │ │ │ + * Determines if the overview map is suitable given the extent and │ │ │ │ │ + * resolution of the main map. │ │ │ │ │ + */ │ │ │ │ │ + isSuitableOverview: function() { │ │ │ │ │ + var mapExtent = this.map.getExtent(); │ │ │ │ │ + var maxExtent = this.map.getMaxExtent(); │ │ │ │ │ + var testExtent = new OpenLayers.Bounds( │ │ │ │ │ + Math.max(mapExtent.left, maxExtent.left), │ │ │ │ │ + Math.max(mapExtent.bottom, maxExtent.bottom), │ │ │ │ │ + Math.min(mapExtent.right, maxExtent.right), │ │ │ │ │ + Math.min(mapExtent.top, maxExtent.top)); │ │ │ │ │ │ │ │ │ │ - startPoint = endPoint; │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + testExtent = testExtent.transform( │ │ │ │ │ + this.map.getProjectionObject(), │ │ │ │ │ + this.ovmap.getProjectionObject()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - this.addFeatures(lines, options); │ │ │ │ │ + var resRatio = this.ovmap.getResolution() / this.map.getResolution(); │ │ │ │ │ + return ((resRatio > this.minRatio) && │ │ │ │ │ + (resRatio <= this.maxRatio) && │ │ │ │ │ + (this.ovmap.getExtent().containsBounds(testExtent))); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.PointTrack" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Layer.PointTrack.SOURCE_NODE │ │ │ │ │ - * {Number} value for and │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.PointTrack.SOURCE_NODE = -1; │ │ │ │ │ + /** │ │ │ │ │ + * Method updateOverview │ │ │ │ │ + * Called by if returns true │ │ │ │ │ + */ │ │ │ │ │ + updateOverview: function() { │ │ │ │ │ + var mapRes = this.map.getResolution(); │ │ │ │ │ + var targetRes = this.ovmap.getResolution(); │ │ │ │ │ + var resRatio = targetRes / mapRes; │ │ │ │ │ + if (resRatio > this.maxRatio) { │ │ │ │ │ + // zoom in overview map │ │ │ │ │ + targetRes = this.minRatio * mapRes; │ │ │ │ │ + } else if (resRatio <= this.minRatio) { │ │ │ │ │ + // zoom out overview map │ │ │ │ │ + targetRes = this.maxRatio * mapRes; │ │ │ │ │ + } │ │ │ │ │ + var center; │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + center = this.map.center.clone(); │ │ │ │ │ + center.transform(this.map.getProjectionObject(), │ │ │ │ │ + this.ovmap.getProjectionObject()); │ │ │ │ │ + } else { │ │ │ │ │ + center = this.map.center; │ │ │ │ │ + } │ │ │ │ │ + this.ovmap.setCenter(center, this.ovmap.getZoomForResolution( │ │ │ │ │ + targetRes * this.resolutionFactor)); │ │ │ │ │ + this.updateRectToMap(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Layer.PointTrack.TARGET_NODE │ │ │ │ │ - * {Number} value for and │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.PointTrack.TARGET_NODE = 0; │ │ │ │ │ + /** │ │ │ │ │ + * Method: createMap │ │ │ │ │ + * Construct the map that this control contains │ │ │ │ │ + */ │ │ │ │ │ + createMap: function() { │ │ │ │ │ + // create the overview map │ │ │ │ │ + var options = OpenLayers.Util.extend({ │ │ │ │ │ + controls: [], │ │ │ │ │ + maxResolution: 'auto', │ │ │ │ │ + fallThrough: false │ │ │ │ │ + }, this.mapOptions); │ │ │ │ │ + this.ovmap = new OpenLayers.Map(this.mapDiv, options); │ │ │ │ │ + this.ovmap.viewPortDiv.appendChild(this.extentRectangle); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Layer.PointTrack.dataFrom │ │ │ │ │ - * {Object} with the following keys - *deprecated* │ │ │ │ │ - * - SOURCE_NODE: take data/attributes from the source node of the line │ │ │ │ │ - * - TARGET_NODE: take data/attributes from the target node of the line │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.PointTrack.dataFrom = { │ │ │ │ │ - 'SOURCE_NODE': -1, │ │ │ │ │ - 'TARGET_NODE': 0 │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/KaMap.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + // prevent ovmap from being destroyed when the page unloads, because │ │ │ │ │ + // the OverviewMap control has to do this (and does it). │ │ │ │ │ + OpenLayers.Event.stopObserving(window, 'unload', this.ovmap.unloadDestroy); │ │ │ │ │ │ │ │ │ │ -/* 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.ovmap.addLayers(this.layers); │ │ │ │ │ + this.ovmap.zoomToMaxExtent(); │ │ │ │ │ + // check extent rectangle border width │ │ │ │ │ + this.wComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ + 'border-left-width')) + │ │ │ │ │ + parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ + 'border-right-width')); │ │ │ │ │ + this.wComp = (this.wComp) ? this.wComp : 2; │ │ │ │ │ + this.hComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ + 'border-top-width')) + │ │ │ │ │ + parseInt(OpenLayers.Element.getStyle(this.extentRectangle, │ │ │ │ │ + 'border-bottom-width')); │ │ │ │ │ + this.hComp = (this.hComp) ? this.hComp : 2; │ │ │ │ │ │ │ │ │ │ + this.handlers.drag = new OpenLayers.Handler.Drag( │ │ │ │ │ + this, { │ │ │ │ │ + move: this.rectDrag, │ │ │ │ │ + done: this.updateMapToRect │ │ │ │ │ + }, { │ │ │ │ │ + map: this.ovmap │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ + this, { │ │ │ │ │ + "click": this.mapDivClick │ │ │ │ │ + }, { │ │ │ │ │ + "single": true, │ │ │ │ │ + "double": false, │ │ │ │ │ + "stopSingle": true, │ │ │ │ │ + "stopDouble": true, │ │ │ │ │ + "pixelTolerance": 1, │ │ │ │ │ + map: this.ovmap │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + this.handlers.click.activate(); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - */ │ │ │ │ │ + this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, │ │ │ │ │ + null, true); │ │ │ │ │ + this.rectEvents.register("mouseover", this, function(e) { │ │ │ │ │ + if (!this.handlers.drag.active && !this.map.dragging) { │ │ │ │ │ + this.handlers.drag.activate(); │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.rectEvents.register("mouseout", this, function(e) { │ │ │ │ │ + if (!this.handlers.drag.dragging) { │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.KaMap │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + var sourceUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units; │ │ │ │ │ + var targetUnits = this.ovmap.getProjectionObject().getUnits() || │ │ │ │ │ + this.ovmap.units || this.ovmap.baseLayer.units; │ │ │ │ │ + this.resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[sourceUnits] / │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} KaMap Layer is always a base layer │ │ │ │ │ + /** │ │ │ │ │ + * Method: updateRectToMap │ │ │ │ │ + * Updates the extent rectangle position and size to match the map extent │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + updateRectToMap: function() { │ │ │ │ │ + // If the projections differ we need to reproject │ │ │ │ │ + var bounds; │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + bounds = this.map.getExtent().transform( │ │ │ │ │ + this.map.getProjectionObject(), │ │ │ │ │ + this.ovmap.getProjectionObject()); │ │ │ │ │ + } else { │ │ │ │ │ + bounds = this.map.getExtent(); │ │ │ │ │ + } │ │ │ │ │ + var pxBounds = this.getRectBoundsFromMapBounds(bounds); │ │ │ │ │ + if (pxBounds) { │ │ │ │ │ + this.setRectPxBounds(pxBounds); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_PARAMS │ │ │ │ │ - * {Object} parameters set by default. The default parameters set │ │ │ │ │ - * the format via the 'i' parameter to 'jpeg'. │ │ │ │ │ + * Method: updateMapToRect │ │ │ │ │ + * Updates the map extent to match the extent rectangle position and size │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_PARAMS: { │ │ │ │ │ - i: 'jpeg', │ │ │ │ │ - map: '' │ │ │ │ │ + updateMapToRect: function() { │ │ │ │ │ + var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + lonLatBounds = lonLatBounds.transform( │ │ │ │ │ + this.ovmap.getProjectionObject(), │ │ │ │ │ + this.map.getProjectionObject()); │ │ │ │ │ + } │ │ │ │ │ + this.map.panTo(lonLatBounds.getCenterLonLat()); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.KaMap │ │ │ │ │ - * │ │ │ │ │ + * Method: setRectPxBounds │ │ │ │ │ + * Set extent rectangle pixel bounds. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {String} │ │ │ │ │ - * params - {Object} Parameters to be sent to the HTTP server in the │ │ │ │ │ - * query string for the tile. The format can be set via the 'i' │ │ │ │ │ - * parameter (defaults to jpg) , and the map should be set via │ │ │ │ │ - * the 'map' parameter. It has been reported that ka-Map may behave │ │ │ │ │ - * inconsistently if your format parameter does not match the format │ │ │ │ │ - * parameter configured in your config.php. (See ticket #327 for more │ │ │ │ │ - * information.) │ │ │ │ │ - * options - {Object} Additional options for the layer. Any of the │ │ │ │ │ - * APIProperties listed on this layer, and any layer types it │ │ │ │ │ - * extends, can be overridden through the options parameter. │ │ │ │ │ + * pxBounds - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.params = OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, this.DEFAULT_PARAMS │ │ │ │ │ + setRectPxBounds: function(pxBounds) { │ │ │ │ │ + var top = Math.max(pxBounds.top, 0); │ │ │ │ │ + var left = Math.max(pxBounds.left, 0); │ │ │ │ │ + var bottom = Math.min(pxBounds.top + Math.abs(pxBounds.getHeight()), │ │ │ │ │ + this.ovmap.size.h - this.hComp); │ │ │ │ │ + var right = Math.min(pxBounds.left + pxBounds.getWidth(), │ │ │ │ │ + this.ovmap.size.w - this.wComp); │ │ │ │ │ + var width = Math.max(right - left, 0); │ │ │ │ │ + var height = Math.max(bottom - top, 0); │ │ │ │ │ + if (width < this.minRectSize || height < this.minRectSize) { │ │ │ │ │ + this.extentRectangle.className = this.displayClass + │ │ │ │ │ + this.minRectDisplayClass; │ │ │ │ │ + var rLeft = left + (width / 2) - (this.minRectSize / 2); │ │ │ │ │ + var rTop = top + (height / 2) - (this.minRectSize / 2); │ │ │ │ │ + this.extentRectangle.style.top = Math.round(rTop) + 'px'; │ │ │ │ │ + this.extentRectangle.style.left = Math.round(rLeft) + 'px'; │ │ │ │ │ + this.extentRectangle.style.height = this.minRectSize + 'px'; │ │ │ │ │ + this.extentRectangle.style.width = this.minRectSize + 'px'; │ │ │ │ │ + } else { │ │ │ │ │ + this.extentRectangle.className = this.displayClass + │ │ │ │ │ + 'ExtentRectangle'; │ │ │ │ │ + this.extentRectangle.style.top = Math.round(top) + 'px'; │ │ │ │ │ + this.extentRectangle.style.left = Math.round(left) + 'px'; │ │ │ │ │ + this.extentRectangle.style.height = Math.round(height) + 'px'; │ │ │ │ │ + this.extentRectangle.style.width = Math.round(width) + 'px'; │ │ │ │ │ + } │ │ │ │ │ + this.rectPxBounds = new OpenLayers.Bounds( │ │ │ │ │ + Math.round(left), Math.round(bottom), │ │ │ │ │ + Math.round(right), Math.round(top) │ │ │ │ │ ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * │ │ │ │ │ + * Method: getRectBoundsFromMapBounds │ │ │ │ │ + * Get the rect bounds from the map bounds. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * │ │ │ │ │ + * lonLatBounds - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters │ │ │ │ │ + * {}A bounds which is the passed-in map lon/lat extent │ │ │ │ │ + * translated into pixel bounds for the overview map │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - var mapRes = this.map.getResolution(); │ │ │ │ │ - var scale = Math.round((this.map.getScale() * 10000)) / 10000; │ │ │ │ │ - var pX = Math.round(bounds.left / mapRes); │ │ │ │ │ - var pY = -Math.round(bounds.top / mapRes); │ │ │ │ │ - return this.getFullRequestString({ │ │ │ │ │ - t: pY, │ │ │ │ │ - l: pX, │ │ │ │ │ - s: scale │ │ │ │ │ + getRectBoundsFromMapBounds: function(lonLatBounds) { │ │ │ │ │ + var leftBottomPx = this.getOverviewPxFromLonLat({ │ │ │ │ │ + lon: lonLatBounds.left, │ │ │ │ │ + lat: lonLatBounds.bottom │ │ │ │ │ + }); │ │ │ │ │ + var rightTopPx = this.getOverviewPxFromLonLat({ │ │ │ │ │ + lon: lonLatBounds.right, │ │ │ │ │ + lat: lonLatBounds.top │ │ │ │ │ }); │ │ │ │ │ + var bounds = null; │ │ │ │ │ + if (leftBottomPx && rightTopPx) { │ │ │ │ │ + bounds = new OpenLayers.Bounds(leftBottomPx.x, leftBottomPx.y, │ │ │ │ │ + rightTopPx.x, rightTopPx.y); │ │ │ │ │ + } │ │ │ │ │ + return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateGridLayout │ │ │ │ │ - * ka-Map uses the center point of the map as an origin for │ │ │ │ │ - * its tiles. Override calculateGridLayout to center tiles │ │ │ │ │ - * correctly for this case. │ │ │ │ │ + /** │ │ │ │ │ + * Method: getMapBoundsFromRectBounds │ │ │ │ │ + * Get the map bounds from the rect bounds. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * origin - {} │ │ │ │ │ - * resolution - {Number} │ │ │ │ │ + * pxBounds - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * {} Bounds which is the passed-in overview rect bounds │ │ │ │ │ + * translated into lon/lat bounds for the overview map │ │ │ │ │ */ │ │ │ │ │ - calculateGridLayout: function(bounds, origin, resolution) { │ │ │ │ │ - var tilelon = resolution * this.tileSize.w; │ │ │ │ │ - var tilelat = resolution * this.tileSize.h; │ │ │ │ │ - │ │ │ │ │ - var offsetlon = bounds.left; │ │ │ │ │ - var tilecol = Math.floor(offsetlon / tilelon) - this.buffer; │ │ │ │ │ - │ │ │ │ │ - var offsetlat = bounds.top; │ │ │ │ │ - var tilerow = Math.floor(offsetlat / tilelat) + this.buffer; │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - tilelon: tilelon, │ │ │ │ │ - tilelat: tilelat, │ │ │ │ │ - startcol: tilecol, │ │ │ │ │ - startrow: tilerow │ │ │ │ │ - }; │ │ │ │ │ + getMapBoundsFromRectBounds: function(pxBounds) { │ │ │ │ │ + var leftBottomLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ + x: pxBounds.left, │ │ │ │ │ + y: pxBounds.bottom │ │ │ │ │ + }); │ │ │ │ │ + var rightTopLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ + x: pxBounds.right, │ │ │ │ │ + y: pxBounds.top │ │ │ │ │ + }); │ │ │ │ │ + return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat, │ │ │ │ │ + rightTopLonLat.lon, rightTopLonLat.lat); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileBoundsForGridIndex │ │ │ │ │ + * Method: getLonLatFromOverviewPx │ │ │ │ │ + * Get a map location from a pixel location │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * row - {Number} The row of the grid │ │ │ │ │ - * col - {Number} The column of the grid │ │ │ │ │ + * overviewMapPx - {|Object} OpenLayers.Pixel or │ │ │ │ │ + * an object with a │ │ │ │ │ + * 'x' and 'y' properties. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The bounds for the tile at (row, col) │ │ │ │ │ - */ │ │ │ │ │ - getTileBoundsForGridIndex: function(row, col) { │ │ │ │ │ - var origin = this.getTileOrigin(); │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - var tilelon = tileLayout.tilelon; │ │ │ │ │ - var tilelat = tileLayout.tilelat; │ │ │ │ │ - var minX = (tileLayout.startcol + col) * tilelon; │ │ │ │ │ - var minY = (tileLayout.startrow - row) * tilelat; │ │ │ │ │ - return new OpenLayers.Bounds( │ │ │ │ │ - minX, minY, │ │ │ │ │ - minX + tilelon, minY + tilelat │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.KaMap │ │ │ │ │ + * {Object} Location which is the passed-in overview map │ │ │ │ │ + * OpenLayers.Pixel, translated into lon/lat by the overview │ │ │ │ │ + * map. An object with a 'lon' and 'lat' properties. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.KaMap(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - if (this.tileSize != null) { │ │ │ │ │ - obj.tileSize = this.tileSize.clone(); │ │ │ │ │ - } │ │ │ │ │ + getLonLatFromOverviewPx: function(overviewMapPx) { │ │ │ │ │ + var size = this.ovmap.size; │ │ │ │ │ + var res = this.ovmap.getResolution(); │ │ │ │ │ + var center = this.ovmap.getExtent().getCenterLonLat(); │ │ │ │ │ │ │ │ │ │ - // we do not want to copy reference to grid, so we make a new array │ │ │ │ │ - obj.grid = []; │ │ │ │ │ + var deltaX = overviewMapPx.x - (size.w / 2); │ │ │ │ │ + var deltaY = overviewMapPx.y - (size.h / 2); │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + return { │ │ │ │ │ + lon: center.lon + deltaX * res, │ │ │ │ │ + lat: center.lat - deltaY * res │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTileBounds │ │ │ │ │ - * Returns The tile bounds for a layer given a pixel location. │ │ │ │ │ + * Method: getOverviewPxFromLonLat │ │ │ │ │ + * Get a pixel location from a map location │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * viewPortPx - {} The location in the viewport. │ │ │ │ │ + * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Bounds of the tile at the given pixel location. │ │ │ │ │ + * {Object} Location which is the passed-in OpenLayers.LonLat, │ │ │ │ │ + * translated into overview map pixels │ │ │ │ │ */ │ │ │ │ │ - getTileBounds: function(viewPortPx) { │ │ │ │ │ - var resolution = this.getResolution(); │ │ │ │ │ - var tileMapWidth = resolution * this.tileSize.w; │ │ │ │ │ - var tileMapHeight = resolution * this.tileSize.h; │ │ │ │ │ - var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ - var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth); │ │ │ │ │ - var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight); │ │ │ │ │ - return new OpenLayers.Bounds(tileLeft, tileBottom, │ │ │ │ │ - tileLeft + tileMapWidth, │ │ │ │ │ - tileBottom + tileMapHeight); │ │ │ │ │ + getOverviewPxFromLonLat: function(lonlat) { │ │ │ │ │ + var res = this.ovmap.getResolution(); │ │ │ │ │ + var extent = this.ovmap.getExtent(); │ │ │ │ │ + if (extent) { │ │ │ │ │ + return { │ │ │ │ │ + x: Math.round(1 / res * (lonlat.lon - extent.left)), │ │ │ │ │ + y: Math.round(1 / res * (extent.top - lonlat.lat)) │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.KaMap" │ │ │ │ │ + CLASS_NAME: 'OpenLayers.Control.OverviewMap' │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/KaMapCache.js │ │ │ │ │ + OpenLayers/Control/Geolocate.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/Layer/KaMap.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.KaMapCache │ │ │ │ │ - * │ │ │ │ │ - * This class is designed to talk directly to a web-accessible ka-Map │ │ │ │ │ - * cache generated by the precache2.php script. │ │ │ │ │ - * │ │ │ │ │ - * To create a a new KaMapCache layer, you must indicate also the "i" parameter │ │ │ │ │ - * (that will be used to calculate the file extension), and another special │ │ │ │ │ - * parameter, object names "metaTileSize", with "h" (height) and "w" (width) │ │ │ │ │ - * properties. │ │ │ │ │ - * │ │ │ │ │ - * // Create a new kaMapCache layer. │ │ │ │ │ - * var kamap_base = new OpenLayers.Layer.KaMapCache( │ │ │ │ │ - * "Satellite", │ │ │ │ │ - * "http://www.example.org/web/acessible/cache", │ │ │ │ │ - * {g: "satellite", map: "world", i: 'png24', metaTileSize: {w: 5, h: 5} } │ │ │ │ │ - * ); │ │ │ │ │ - * │ │ │ │ │ - * // Create an kaMapCache overlay layer (using "isBaseLayer: false"). │ │ │ │ │ - * // Forces the output to be a "gif", using the "i" parameter. │ │ │ │ │ - * var kamap_overlay = new OpenLayers.Layer.KaMapCache( │ │ │ │ │ - * "Streets", │ │ │ │ │ - * "http://www.example.org/web/acessible/cache", │ │ │ │ │ - * {g: "streets", map: "world", i: "gif", metaTileSize: {w: 5, h: 5} }, │ │ │ │ │ - * {isBaseLayer: false} │ │ │ │ │ - * ); │ │ │ │ │ + * Class: OpenLayers.Control.Geolocate │ │ │ │ │ + * The Geolocate control wraps w3c geolocation API into control that can be │ │ │ │ │ + * bound to a map, and generate events on location update │ │ │ │ │ * │ │ │ │ │ - * The cache URLs must look like: │ │ │ │ │ - * var/cache/World/50000/Group_Name/def/t-440320/l20480 │ │ │ │ │ - * │ │ │ │ │ - * This means that the cache generated via tile.php will *not* work with │ │ │ │ │ - * this class, and should instead use the KaMap layer. │ │ │ │ │ + * To use this control requires to load the proj4js library if the projection │ │ │ │ │ + * of the map is not EPSG:4326 or EPSG:900913. │ │ │ │ │ * │ │ │ │ │ - * More information is available in Ticket #1518. │ │ │ │ │ - * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.KaMapCache = OpenLayers.Class(OpenLayers.Layer.KaMap, { │ │ │ │ │ +OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * locationupdated - Triggered when browser return a new position. Listeners will │ │ │ │ │ + * receive an object with a 'position' property which is the browser.geolocation.position │ │ │ │ │ + * native object, as well as a 'point' property which is the location transformed in the │ │ │ │ │ + * current map projection. │ │ │ │ │ + * locationfailed - Triggered when geolocation has failed │ │ │ │ │ + * locationuncapable - Triggered when control is activated on a browser │ │ │ │ │ + * which doesn't support geolocation │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: IMAGE_EXTENSIONS │ │ │ │ │ - * {Object} Simple hash map to convert format to extension. │ │ │ │ │ + * Property: geolocation │ │ │ │ │ + * {Object} The geolocation engine, as a property to be possibly mocked. │ │ │ │ │ + * This is set lazily to avoid a memory leak in IE9. │ │ │ │ │ */ │ │ │ │ │ - IMAGE_EXTENSIONS: { │ │ │ │ │ - 'jpeg': 'jpg', │ │ │ │ │ - 'gif': 'gif', │ │ │ │ │ - 'png': 'png', │ │ │ │ │ - 'png8': 'png', │ │ │ │ │ - 'png24': 'png', │ │ │ │ │ - 'dithered': 'png' │ │ │ │ │ - }, │ │ │ │ │ + geolocation: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_FORMAT │ │ │ │ │ - * {Object} Simple hash map to convert format to extension. │ │ │ │ │ + * Property: available │ │ │ │ │ + * {Boolean} The navigator.geolocation object is available. │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_FORMAT: 'jpeg', │ │ │ │ │ + available: ('geolocation' in navigator), │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.KaMapCache │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {String} │ │ │ │ │ - * params - {Object} Parameters to be sent to the HTTP server in the │ │ │ │ │ - * query string for the tile. The format can be set via the 'i' │ │ │ │ │ - * parameter (defaults to jpg) , and the map should be set via │ │ │ │ │ - * the 'map' parameter. It has been reported that ka-Map may behave │ │ │ │ │ - * inconsistently if your format parameter does not match the format │ │ │ │ │ - * parameter configured in your config.php. (See ticket #327 for more │ │ │ │ │ - * information.) │ │ │ │ │ - * options - {Object} Additional options for the layer. Any of the │ │ │ │ │ - * APIProperties listed on this layer, and any layer types it │ │ │ │ │ - * extends, can be overridden through the options parameter. │ │ │ │ │ + * APIProperty: bind │ │ │ │ │ + * {Boolean} If true, map center will be set on location update. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.KaMap.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.extension = this.IMAGE_EXTENSIONS[this.params.i.toLowerCase() || this.DEFAULT_FORMAT]; │ │ │ │ │ + bind: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: watch │ │ │ │ │ + * {Boolean} If true, position will be update regularly. │ │ │ │ │ + */ │ │ │ │ │ + watch: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geolocationOptions │ │ │ │ │ + * {Object} Options to pass to the navigator's geolocation API. See │ │ │ │ │ + * . No specific │ │ │ │ │ + * option is passed to the geolocation API by default. │ │ │ │ │ + */ │ │ │ │ │ + geolocationOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Geolocate │ │ │ │ │ + * Create a new control to deal with browser geolocation API │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activates the control. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters │ │ │ │ │ + * {Boolean} The control was effectively activated. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - var mapRes = this.map.getResolution(); │ │ │ │ │ - var scale = Math.round((this.map.getScale() * 10000)) / 10000; │ │ │ │ │ - var pX = Math.round(bounds.left / mapRes); │ │ │ │ │ - var pY = -Math.round(bounds.top / mapRes); │ │ │ │ │ - │ │ │ │ │ - var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w; │ │ │ │ │ - var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h; │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (this.available && !this.geolocation) { │ │ │ │ │ + // set lazily to avoid IE9 memory leak │ │ │ │ │ + this.geolocation = navigator.geolocation; │ │ │ │ │ + } │ │ │ │ │ + if (!this.geolocation) { │ │ │ │ │ + this.events.triggerEvent("locationuncapable"); │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + if (this.watch) { │ │ │ │ │ + this.watchId = this.geolocation.watchPosition( │ │ │ │ │ + OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ + OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ + this.geolocationOptions │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.getCurrentLocation(); │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var components = [ │ │ │ │ │ - "/", │ │ │ │ │ - this.params.map, │ │ │ │ │ - "/", │ │ │ │ │ - scale, │ │ │ │ │ - "/", │ │ │ │ │ - this.params.g.replace(/\s/g, '_'), │ │ │ │ │ - "/def/t", │ │ │ │ │ - metaY, │ │ │ │ │ - "/l", │ │ │ │ │ - metaX, │ │ │ │ │ - "/t", │ │ │ │ │ - pY, │ │ │ │ │ - "l", │ │ │ │ │ - pX, │ │ │ │ │ - ".", │ │ │ │ │ - this.extension │ │ │ │ │ - ]; │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivates the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The control was effectively deactivated. │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active && this.watchId !== null) { │ │ │ │ │ + this.geolocation.clearWatch(this.watchId); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ + this, arguments │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var url = this.url; │ │ │ │ │ + /** │ │ │ │ │ + * Method: geolocate │ │ │ │ │ + * Activates the control. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + geolocate: function(position) { │ │ │ │ │ + var center = new OpenLayers.LonLat( │ │ │ │ │ + position.coords.longitude, │ │ │ │ │ + position.coords.latitude │ │ │ │ │ + ).transform( │ │ │ │ │ + new OpenLayers.Projection("EPSG:4326"), │ │ │ │ │ + this.map.getProjectionObject() │ │ │ │ │ + ); │ │ │ │ │ + if (this.bind) { │ │ │ │ │ + this.map.setCenter(center); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("locationupdated", { │ │ │ │ │ + position: position, │ │ │ │ │ + point: new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ + ) │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(components.join(''), url); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getCurrentLocation │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Returns true if a event will be fired (successfull │ │ │ │ │ + * registration) │ │ │ │ │ + */ │ │ │ │ │ + getCurrentLocation: function() { │ │ │ │ │ + if (!this.active || this.watch) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return url + components.join(""); │ │ │ │ │ + this.geolocation.getCurrentPosition( │ │ │ │ │ + OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ + OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ + this.geolocationOptions │ │ │ │ │ + ); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.KaMapCache" │ │ │ │ │ + /** │ │ │ │ │ + * Method: failure │ │ │ │ │ + * method called on browser's geolocation failure │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + failure: function(error) { │ │ │ │ │ + this.events.triggerEvent("locationfailed", { │ │ │ │ │ + error: error │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Geolocate" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/TMS.js │ │ │ │ │ + OpenLayers/Control/NavigationHistory.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.TMS │ │ │ │ │ - * Create a layer for accessing tiles from services that conform with the │ │ │ │ │ - * Tile Map Service Specification │ │ │ │ │ - * (http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification). │ │ │ │ │ + * Class: OpenLayers.Control.NavigationHistory │ │ │ │ │ + * A navigation history control. This is a meta-control, that creates two │ │ │ │ │ + * dependent controls: and . Call the trigger method │ │ │ │ │ + * on the and controls to restore previous and next │ │ │ │ │ + * history states. The previous and next controls will become active │ │ │ │ │ + * when there are available states to restore and will become deactive │ │ │ │ │ + * when there are no states to restore. │ │ │ │ │ * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var layer = new OpenLayers.Layer.TMS( │ │ │ │ │ - * "My Layer", // name for display in LayerSwitcher │ │ │ │ │ - * "http://tilecache.osgeo.org/wms-c/Basic.py/", // service endpoint │ │ │ │ │ - * {layername: "basic", type: "png"} // required properties │ │ │ │ │ - * ); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: serviceVersion │ │ │ │ │ - * {String} Service version for tile requests. Default is "1.0.0". │ │ │ │ │ + * Property: type │ │ │ │ │ + * {String} Note that this control is not intended to be added directly │ │ │ │ │ + * to a control panel. Instead, add the sub-controls previous and │ │ │ │ │ + * next. These sub-controls are button type controls that activate │ │ │ │ │ + * and deactivate themselves. If this parent control is added to │ │ │ │ │ + * a panel, it will act as a toggle. │ │ │ │ │ */ │ │ │ │ │ - serviceVersion: "1.0.0", │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOGGLE, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layername │ │ │ │ │ - * {String} The identifier for the as advertised by the service. │ │ │ │ │ - * For example, if the service advertises a with │ │ │ │ │ - * 'href="http://tms.osgeo.org/1.0.0/vmap0"', the property │ │ │ │ │ - * would be set to "vmap0". │ │ │ │ │ + * APIProperty: previous │ │ │ │ │ + * {} A button type control whose trigger method restores │ │ │ │ │ + * the previous state managed by this control. │ │ │ │ │ */ │ │ │ │ │ - layername: null, │ │ │ │ │ + previous: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {String} The format extension corresponding to the requested tile image │ │ │ │ │ - * type. This is advertised in a element as the │ │ │ │ │ - * "extension" attribute. For example, if the service advertises a │ │ │ │ │ - * with , │ │ │ │ │ - * the property would be set to "jpg". │ │ │ │ │ + * APIProperty: previousOptions │ │ │ │ │ + * {Object} Set this property on the options argument of the constructor │ │ │ │ │ + * to set optional properties on the control. │ │ │ │ │ */ │ │ │ │ │ - type: null, │ │ │ │ │ + previousOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Make this layer a base layer. Default is true. Set false to │ │ │ │ │ - * use the layer as an overlay. │ │ │ │ │ + * APIProperty: next │ │ │ │ │ + * {} A button type control whose trigger method restores │ │ │ │ │ + * the next state managed by this control. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + next: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 bottom-left │ │ │ │ │ - * corner of the map's . Default is ``null``. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var layer = new OpenLayers.Layer.TMS( │ │ │ │ │ - * "My Layer", │ │ │ │ │ - * "http://tilecache.osgeo.org/wms-c/Basic.py/", │ │ │ │ │ - * { │ │ │ │ │ - * layername: "basic", │ │ │ │ │ - * type: "png", │ │ │ │ │ - * // set if different than the bottom left of map.maxExtent │ │ │ │ │ - * tileOrigin: new OpenLayers.LonLat(-180, -90) │ │ │ │ │ - * } │ │ │ │ │ - * ); │ │ │ │ │ - * (end) │ │ │ │ │ + * APIProperty: nextOptions │ │ │ │ │ + * {Object} Set this property on the options argument of the constructor │ │ │ │ │ + * to set optional properties on the control. │ │ │ │ │ */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ + nextOptions: 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: limit │ │ │ │ │ + * {Integer} Optional limit on the number of history items to retain. If │ │ │ │ │ + * null, there is no limit. Default is 50. │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + limit: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOffset │ │ │ │ │ - * {Number} If your cache has more zoom 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). Using is an alternative to │ │ │ │ │ - * setting if you only want to expose a subset │ │ │ │ │ - * of the server resolutions. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - zoomOffset: 0, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.TMS │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} Title to be displayed in a │ │ │ │ │ - * url - {String} Service endpoint (without the version number). E.g. │ │ │ │ │ - * "http://tms.osgeo.org/". │ │ │ │ │ - * options - {Object} Additional properties to be set on the layer. The │ │ │ │ │ - * and properties must be set here. │ │ │ │ │ + * Property: clearOnDeactivate │ │ │ │ │ + * {Boolean} Clear the history when the control is deactivated. Default │ │ │ │ │ + * is false. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, options) { │ │ │ │ │ - var newArguments = []; │ │ │ │ │ - newArguments.push(name, url, {}, options); │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); │ │ │ │ │ - }, │ │ │ │ │ + clearOnDeactivate: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a complete copy of this layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Should only be provided by subclasses that call this │ │ │ │ │ - * method. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ + * Property: registry │ │ │ │ │ + * {Object} An object with keys corresponding to event types. Values │ │ │ │ │ + * are functions that return an object representing the current state. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.TMS(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ - } │ │ │ │ │ + registry: null, │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ + /** │ │ │ │ │ + * Property: nextStack │ │ │ │ │ + * {Array} Array of items in the history. │ │ │ │ │ + */ │ │ │ │ │ + nextStack: null, │ │ │ │ │ │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ + /** │ │ │ │ │ + * Property: previousStack │ │ │ │ │ + * {Array} List of items in the history. First item represents the current │ │ │ │ │ + * state. │ │ │ │ │ + */ │ │ │ │ │ + previousStack: null, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: listeners │ │ │ │ │ + * {Object} An object containing properties corresponding to event types. │ │ │ │ │ + * This object is used to configure the control and is modified on │ │ │ │ │ + * construction. │ │ │ │ │ + */ │ │ │ │ │ + listeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters │ │ │ │ │ + * Property: restoring │ │ │ │ │ + * {Boolean} Currently restoring a history state. This is set to true │ │ │ │ │ + * before calling restore and set to false after restore returns. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - var res = this.getServerResolution(); │ │ │ │ │ - var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); │ │ │ │ │ - var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h)); │ │ │ │ │ - var z = this.getServerZoom(); │ │ │ │ │ - var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; │ │ │ │ │ - var url = this.url; │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(path, url); │ │ │ │ │ - } │ │ │ │ │ - return url + path; │ │ │ │ │ - }, │ │ │ │ │ + restoring: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * When the layer is added to a map, then we can fetch our origin │ │ │ │ │ - * (if we don't have one.) │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.NavigationHistory │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments); │ │ │ │ │ - if (!this.tileOrigin) { │ │ │ │ │ - this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left, │ │ │ │ │ - this.map.maxExtent.bottom); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.TMS" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/MapGuide.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/Request/XMLHttpRequest.js │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.MapGuide │ │ │ │ │ - * Instances of OpenLayers.Layer.MapGuide are used to display │ │ │ │ │ - * data from a MapGuide OS instance. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Treat this layer as a base layer. Default is true. │ │ │ │ │ - **/ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: useHttpTile │ │ │ │ │ - * {Boolean} use a tile cache exposed directly via a webserver rather than the │ │ │ │ │ - * via mapguide server. This does require extra configuration on the Mapguide Server, │ │ │ │ │ - * and will only work when singleTile is false. The url for the layer must be set to the │ │ │ │ │ - * webserver path rather than the Mapguide mapagent. │ │ │ │ │ - * See http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp │ │ │ │ │ - **/ │ │ │ │ │ - useHttpTile: false, │ │ │ │ │ + this.registry = OpenLayers.Util.extend({ │ │ │ │ │ + "moveend": this.getState │ │ │ │ │ + }, this.registry); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: singleTile │ │ │ │ │ - * {Boolean} use tile server or request single tile image. │ │ │ │ │ - **/ │ │ │ │ │ - singleTile: false, │ │ │ │ │ + var previousOptions = { │ │ │ │ │ + trigger: OpenLayers.Function.bind(this.previousTrigger, this), │ │ │ │ │ + displayClass: this.displayClass + " " + this.displayClass + "Previous" │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Util.extend(previousOptions, this.previousOptions); │ │ │ │ │ + this.previous = new OpenLayers.Control.Button(previousOptions); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: useOverlay │ │ │ │ │ - * {Boolean} flag to indicate if the layer should be retrieved using │ │ │ │ │ - * GETMAPIMAGE (default) or using GETDYNAMICOVERLAY requests. │ │ │ │ │ - **/ │ │ │ │ │ - useOverlay: false, │ │ │ │ │ + var nextOptions = { │ │ │ │ │ + trigger: OpenLayers.Function.bind(this.nextTrigger, this), │ │ │ │ │ + displayClass: this.displayClass + " " + this.displayClass + "Next" │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Util.extend(nextOptions, this.nextOptions); │ │ │ │ │ + this.next = new OpenLayers.Control.Button(nextOptions); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: useAsyncOverlay │ │ │ │ │ - * {Boolean} indicates if the MapGuide site supports the asynchronous │ │ │ │ │ - * GETDYNAMICOVERLAY requests which is available in MapGuide Enterprise 2010 │ │ │ │ │ - * and MapGuide Open Source v2.0.3 or higher. The newer versions of MG │ │ │ │ │ - * is called asynchronously, allows selections to be drawn separately from │ │ │ │ │ - * the map and offers styling options. │ │ │ │ │ - * │ │ │ │ │ - * With older versions of MapGuide, set useAsyncOverlay=false. Note that in │ │ │ │ │ - * this case a synchronous AJAX call is issued and the mapname and session │ │ │ │ │ - * parameters must be used to initialize the layer, not the mapdefinition │ │ │ │ │ - * parameter. Also note that this will issue a synchronous AJAX request │ │ │ │ │ - * before the image request can be issued so the users browser may lock │ │ │ │ │ - * up if the MG Web tier does not respond in a timely fashion. │ │ │ │ │ - **/ │ │ │ │ │ - useAsyncOverlay: true, │ │ │ │ │ + this.clear(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: TILE_PARAMS │ │ │ │ │ - * {Object} Hashtable of default parameter key/value pairs for tiled layer │ │ │ │ │ + * Method: onPreviousChange │ │ │ │ │ + * Called when the previous history stack changes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {Object} An object representing the state to be restored │ │ │ │ │ + * if previous is triggered again or null if no previous states remain. │ │ │ │ │ + * length - {Integer} The number of remaining previous states that can │ │ │ │ │ + * be restored. │ │ │ │ │ */ │ │ │ │ │ - TILE_PARAMS: { │ │ │ │ │ - operation: 'GETTILEIMAGE', │ │ │ │ │ - version: '1.2.0' │ │ │ │ │ + onPreviousChange: function(state, length) { │ │ │ │ │ + if (state && !this.previous.active) { │ │ │ │ │ + this.previous.activate(); │ │ │ │ │ + } else if (!state && this.previous.active) { │ │ │ │ │ + this.previous.deactivate(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: SINGLE_TILE_PARAMS │ │ │ │ │ - * {Object} Hashtable of default parameter key/value pairs for untiled layer │ │ │ │ │ + * Method: onNextChange │ │ │ │ │ + * Called when the next history stack changes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {Object} An object representing the state to be restored │ │ │ │ │ + * if next is triggered again or null if no next states remain. │ │ │ │ │ + * length - {Integer} The number of remaining next states that can │ │ │ │ │ + * be restored. │ │ │ │ │ */ │ │ │ │ │ - SINGLE_TILE_PARAMS: { │ │ │ │ │ - operation: 'GETMAPIMAGE', │ │ │ │ │ - format: 'PNG', │ │ │ │ │ - locale: 'en', │ │ │ │ │ - clip: '1', │ │ │ │ │ - version: '1.0.0' │ │ │ │ │ + onNextChange: function(state, length) { │ │ │ │ │ + if (state && !this.next.active) { │ │ │ │ │ + this.next.activate(); │ │ │ │ │ + } else if (!state && this.next.active) { │ │ │ │ │ + this.next.deactivate(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: OVERLAY_PARAMS │ │ │ │ │ - * {Object} Hashtable of default parameter key/value pairs for untiled layer │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy the control. │ │ │ │ │ */ │ │ │ │ │ - OVERLAY_PARAMS: { │ │ │ │ │ - operation: 'GETDYNAMICMAPOVERLAYIMAGE', │ │ │ │ │ - format: 'PNG', │ │ │ │ │ - locale: 'en', │ │ │ │ │ - clip: '1', │ │ │ │ │ - version: '2.0.0' │ │ │ │ │ + destroy: function() { │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ + this.previous.destroy(); │ │ │ │ │ + this.next.destroy(); │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + for (var prop in this) { │ │ │ │ │ + this[prop] = null; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: FOLDER_PARAMS │ │ │ │ │ - * {Object} Hashtable of parameter key/value pairs which describe │ │ │ │ │ - * the folder structure for tiles as configured in the mapguide │ │ │ │ │ - * serverconfig.ini section [TileServiceProperties] │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control and and child │ │ │ │ │ + * controls. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - FOLDER_PARAMS: { │ │ │ │ │ - tileColumnsPerFolder: 30, │ │ │ │ │ - tileRowsPerFolder: 30, │ │ │ │ │ - format: 'png', │ │ │ │ │ - querystring: null │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + this.next.setMap(map); │ │ │ │ │ + this.previous.setMap(map); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultSize │ │ │ │ │ - * {} Tile size as produced by MapGuide server │ │ │ │ │ - **/ │ │ │ │ │ - defaultSize: new OpenLayers.Size(300, 300), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileOriginCorner │ │ │ │ │ - * {String} MapGuide tile server uses top-left as tile origin │ │ │ │ │ - **/ │ │ │ │ │ - tileOriginCorner: "tl", │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Called when the control is added to the map. │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + this.next.draw(); │ │ │ │ │ + this.previous.draw(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.MapGuide │ │ │ │ │ - * Create a new Mapguide layer, either tiled or untiled. │ │ │ │ │ - * │ │ │ │ │ - * For tiled layers, the 'groupName' and 'mapDefinition' values │ │ │ │ │ - * must be specified as parameters in the constructor. │ │ │ │ │ - * │ │ │ │ │ - * For untiled base layers, specify either combination of 'mapName' and │ │ │ │ │ - * 'session', or 'mapDefinition' and 'locale'. │ │ │ │ │ - * │ │ │ │ │ - * For older versions of MapGuide and overlay layers, set useAsyncOverlay │ │ │ │ │ - * to false and in this case mapName and session are required parameters │ │ │ │ │ - * for the constructor. │ │ │ │ │ - * │ │ │ │ │ - * NOTE: MapGuide OS uses a DPI value and degrees to meters conversion │ │ │ │ │ - * factor that are different than the defaults used in OpenLayers, │ │ │ │ │ - * so these must be adjusted accordingly in your application. │ │ │ │ │ - * See the MapGuide example for how to set these values for MGOS. │ │ │ │ │ + * Method: previousTrigger │ │ │ │ │ + * Restore the previous state. If no items are in the previous history │ │ │ │ │ + * stack, this has no effect. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} Name of the layer displayed in the interface │ │ │ │ │ - * url - {String} Location of the MapGuide mapagent executable │ │ │ │ │ - * (e.g. http://localhost:8008/mapguide/mapagent/mapagent.fcgi) │ │ │ │ │ - * params - {Object} hashtable of additional parameters to use. Some │ │ │ │ │ - * parameters may require additional code on the server. The ones that │ │ │ │ │ - * you may want to use are: │ │ │ │ │ - * - mapDefinition - {String} The MapGuide resource definition │ │ │ │ │ - * (e.g. Library://Samples/Gmap/Maps/gmapTiled.MapDefinition) │ │ │ │ │ - * - locale - Locale setting │ │ │ │ │ - * (for untiled overlays layers only) │ │ │ │ │ - * - mapName - {String} Name of the map as stored in the MapGuide session. │ │ │ │ │ - * (for untiled layers with a session parameter only) │ │ │ │ │ - * - session - { String} MapGuide session ID │ │ │ │ │ - * (for untiled overlays layers only) │ │ │ │ │ - * - basemaplayergroupname - {String} GroupName for tiled MapGuide layers only │ │ │ │ │ - * - format - Image format to be returned (for untiled overlay layers only) │ │ │ │ │ - * - showLayers - {String} A comma separated list of GUID's for the │ │ │ │ │ - * layers to display eg: 'cvc-xcv34,453-345-345sdf'. │ │ │ │ │ - * - hideLayers - {String} A comma separated list of GUID's for the │ │ │ │ │ - * layers to hide eg: 'cvc-xcv34,453-345-345sdf'. │ │ │ │ │ - * - showGroups - {String} A comma separated list of GUID's for the │ │ │ │ │ - * groups to display eg: 'cvc-xcv34,453-345-345sdf'. │ │ │ │ │ - * - hideGroups - {String} A comma separated list of GUID's for the │ │ │ │ │ - * groups to hide eg: 'cvc-xcv34,453-345-345sdf' │ │ │ │ │ - * - selectionXml - {String} A selection xml string Some server plumbing │ │ │ │ │ - * is required to read such a value. │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer; │ │ │ │ │ - * will vary depending if tiled or untiled maps are being requested │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ + * items are in the previous history stack. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - // unless explicitly set in options, if the layer is transparent, │ │ │ │ │ - // it will be an overlay │ │ │ │ │ - if (options == null || options.isBaseLayer == null) { │ │ │ │ │ - this.isBaseLayer = ((this.transparent != "true") && │ │ │ │ │ - (this.transparent != true)); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (options && options.useOverlay != null) { │ │ │ │ │ - this.useOverlay = options.useOverlay; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //initialize for untiled layers │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - if (this.useOverlay) { │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - this.OVERLAY_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - if (!this.useAsyncOverlay) { │ │ │ │ │ - this.params.version = "1.0.0"; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - this.SINGLE_TILE_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + previousTrigger: function() { │ │ │ │ │ + var current = this.previousStack.shift(); │ │ │ │ │ + var state = this.previousStack.shift(); │ │ │ │ │ + if (state != undefined) { │ │ │ │ │ + this.nextStack.unshift(current); │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + this.restoring = true; │ │ │ │ │ + this.restore(state); │ │ │ │ │ + this.restoring = false; │ │ │ │ │ + this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ } else { │ │ │ │ │ - //initialize for tiled layers │ │ │ │ │ - if (this.useHttpTile) { │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - this.FOLDER_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - this.TILE_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.setTileSize(this.defaultSize); │ │ │ │ │ + this.previousStack.unshift(current); │ │ │ │ │ } │ │ │ │ │ + return state; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * APIMethod: nextTrigger │ │ │ │ │ + * Restore the next state. If no items are in the next history │ │ │ │ │ + * stack, this has no effect. The next history stack is populated │ │ │ │ │ + * as states are restored from the previous history stack. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ + * items are in the next history stack. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.MapGuide(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + nextTrigger: function() { │ │ │ │ │ + var state = this.nextStack.shift(); │ │ │ │ │ + if (state != undefined) { │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + this.restoring = true; │ │ │ │ │ + this.restore(state); │ │ │ │ │ + this.restoring = false; │ │ │ │ │ + this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ + return state; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clear │ │ │ │ │ + * Clear history. │ │ │ │ │ + */ │ │ │ │ │ + clear: function() { │ │ │ │ │ + this.previousStack = []; │ │ │ │ │ + this.previous.deactivate(); │ │ │ │ │ + this.nextStack = []; │ │ │ │ │ + this.next.deactivate(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * Return a query string for this layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox │ │ │ │ │ - * for the request │ │ │ │ │ + * Method: getState │ │ │ │ │ + * Get the current state and return it. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also │ │ │ │ │ - * the passed-in bounds and appropriate tile size specified │ │ │ │ │ - * as parameters. │ │ │ │ │ + * {Object} An object representing the current state. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - var url; │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var mapSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - //set up the call for GETMAPIMAGE or GETDYNAMICMAPOVERLAY with │ │ │ │ │ - //dynamic map parameters │ │ │ │ │ - var params = { │ │ │ │ │ - setdisplaydpi: OpenLayers.DOTS_PER_INCH, │ │ │ │ │ - setdisplayheight: mapSize.h * this.ratio, │ │ │ │ │ - setdisplaywidth: mapSize.w * this.ratio, │ │ │ │ │ - setviewcenterx: center.lon, │ │ │ │ │ - setviewcentery: center.lat, │ │ │ │ │ - setviewscale: this.map.getScale() │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - if (this.useOverlay && !this.useAsyncOverlay) { │ │ │ │ │ - //first we need to call GETVISIBLEMAPEXTENT to set the extent │ │ │ │ │ - var getVisParams = {}; │ │ │ │ │ - getVisParams = OpenLayers.Util.extend(getVisParams, params); │ │ │ │ │ - getVisParams.operation = "GETVISIBLEMAPEXTENT"; │ │ │ │ │ - getVisParams.version = "1.0.0"; │ │ │ │ │ - getVisParams.session = this.params.session; │ │ │ │ │ - getVisParams.mapName = this.params.mapName; │ │ │ │ │ - getVisParams.format = 'text/xml'; │ │ │ │ │ - url = this.getFullRequestString(getVisParams); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Request.GET({ │ │ │ │ │ - url: url, │ │ │ │ │ - async: false │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - //construct the full URL │ │ │ │ │ - url = this.getFullRequestString(params); │ │ │ │ │ - } else { │ │ │ │ │ - │ │ │ │ │ - //tiled version │ │ │ │ │ - var currentRes = this.map.getResolution(); │ │ │ │ │ - var colidx = Math.floor((bounds.left - this.maxExtent.left) / currentRes); │ │ │ │ │ - colidx = Math.round(colidx / this.tileSize.w); │ │ │ │ │ - var rowidx = Math.floor((this.maxExtent.top - bounds.top) / currentRes); │ │ │ │ │ - rowidx = Math.round(rowidx / this.tileSize.h); │ │ │ │ │ - │ │ │ │ │ - if (this.useHttpTile) { │ │ │ │ │ - url = this.getImageFilePath({ │ │ │ │ │ - tilecol: colidx, │ │ │ │ │ - tilerow: rowidx, │ │ │ │ │ - scaleindex: this.resolutions.length - this.map.zoom - 1 │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - url = this.getFullRequestString({ │ │ │ │ │ - tilecol: colidx, │ │ │ │ │ - tilerow: rowidx, │ │ │ │ │ - scaleindex: this.resolutions.length - this.map.zoom - 1 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return url; │ │ │ │ │ + getState: function() { │ │ │ │ │ + return { │ │ │ │ │ + center: this.map.getCenter(), │ │ │ │ │ + resolution: this.map.getResolution(), │ │ │ │ │ + projection: this.map.getProjectionObject(), │ │ │ │ │ + units: this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFullRequestString │ │ │ │ │ - * getFullRequestString on MapGuide layers is special, because we │ │ │ │ │ - * do a regular expression replace on ',' in parameters to '+'. │ │ │ │ │ - * This is why it is subclassed here. │ │ │ │ │ + * Method: restore │ │ │ │ │ + * Update the state with the given object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * altUrl - {String} Alternative base URL to use. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the layer's url appropriately encoded for MapGuide │ │ │ │ │ + * state - {Object} An object representing the state to restore. │ │ │ │ │ */ │ │ │ │ │ - getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ - // use layer's url unless altUrl passed in │ │ │ │ │ - var url = (altUrl == null) ? this.url : altUrl; │ │ │ │ │ - │ │ │ │ │ - // if url is not a string, it should be an array of strings, │ │ │ │ │ - // in which case we will randomly select one of them in order │ │ │ │ │ - // to evenly distribute requests to different urls. │ │ │ │ │ - if (typeof url == "object") { │ │ │ │ │ - url = url[Math.floor(Math.random() * url.length)]; │ │ │ │ │ - } │ │ │ │ │ - // requestString always starts with url │ │ │ │ │ - var requestString = 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); │ │ │ │ │ - // 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]; │ │ │ │ │ - } │ │ │ │ │ + restore: function(state) { │ │ │ │ │ + var center, zoom; │ │ │ │ │ + if (this.map.getProjectionObject() == state.projection) { │ │ │ │ │ + zoom = this.map.getZoomForResolution(state.resolution); │ │ │ │ │ + center = state.center; │ │ │ │ │ + } else { │ │ │ │ │ + center = state.center.clone(); │ │ │ │ │ + center.transform(state.projection, this.map.getProjectionObject()); │ │ │ │ │ + var sourceUnits = state.units; │ │ │ │ │ + var targetUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units; │ │ │ │ │ + var resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[sourceUnits] / OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ + zoom = this.map.getZoomForResolution(resolutionFactor * state.resolution); │ │ │ │ │ } │ │ │ │ │ - var paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ - │ │ │ │ │ - /* MapGuide needs '+' seperating things like bounds/height/width. │ │ │ │ │ - Since typically this is URL encoded, we use a slight hack: we │ │ │ │ │ - depend on the list-like functionality of getParameterString to │ │ │ │ │ - leave ',' only in the case of list items (since otherwise it is │ │ │ │ │ - encoded) then do a regular expression replace on the , characters │ │ │ │ │ - to '+' */ │ │ │ │ │ - paramsString = paramsString.replace(/,/g, "+"); │ │ │ │ │ + this.map.setCenter(center, zoom); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (paramsString != "") { │ │ │ │ │ - var lastServerChar = url.charAt(url.length - 1); │ │ │ │ │ - if ((lastServerChar == "&") || (lastServerChar == "?")) { │ │ │ │ │ - requestString += paramsString; │ │ │ │ │ - } else { │ │ │ │ │ - if (url.indexOf('?') == -1) { │ │ │ │ │ - //serverPath has no ? -- add one │ │ │ │ │ - requestString += '?' + paramsString; │ │ │ │ │ - } else { │ │ │ │ │ - //serverPath contains ?, so must already have paramsString at the end │ │ │ │ │ - requestString += '&' + paramsString; │ │ │ │ │ + /** │ │ │ │ │ + * Method: setListeners │ │ │ │ │ + * Sets functions to be registered in the listeners object. │ │ │ │ │ + */ │ │ │ │ │ + setListeners: function() { │ │ │ │ │ + this.listeners = {}; │ │ │ │ │ + for (var type in this.registry) { │ │ │ │ │ + this.listeners[type] = OpenLayers.Function.bind(function() { │ │ │ │ │ + if (!this.restoring) { │ │ │ │ │ + var state = this.registry[type].apply(this, arguments); │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + if (this.previousStack.length > 1) { │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (this.previousStack.length > (this.limit + 1)) { │ │ │ │ │ + this.previousStack.pop(); │ │ │ │ │ + } │ │ │ │ │ + if (this.nextStack.length > 0) { │ │ │ │ │ + this.nextStack = []; │ │ │ │ │ + this.onNextChange(null, 0); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ + return true; │ │ │ │ │ + }, this); │ │ │ │ │ } │ │ │ │ │ - return requestString; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getImageFilePath │ │ │ │ │ - * special handler to request mapguide tiles from an http exposed tilecache │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * altUrl - {String} Alternative base URL to use. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. This registers any listeners. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the url for the tile image │ │ │ │ │ + * {Boolean} Control successfully activated. │ │ │ │ │ */ │ │ │ │ │ - getImageFilePath: function(newParams, altUrl) { │ │ │ │ │ - // use layer's url unless altUrl passed in │ │ │ │ │ - var url = (altUrl == null) ? this.url : altUrl; │ │ │ │ │ - │ │ │ │ │ - // if url is not a string, it should be an array of strings, │ │ │ │ │ - // in which case we will randomly select one of them in order │ │ │ │ │ - // to evenly distribute requests to different urls. │ │ │ │ │ - if (typeof url == "object") { │ │ │ │ │ - url = url[Math.floor(Math.random() * url.length)]; │ │ │ │ │ - } │ │ │ │ │ - // requestString always starts with url │ │ │ │ │ - var requestString = url; │ │ │ │ │ - │ │ │ │ │ - var tileRowGroup = ""; │ │ │ │ │ - var tileColGroup = ""; │ │ │ │ │ - │ │ │ │ │ - if (newParams.tilerow < 0) { │ │ │ │ │ - tileRowGroup = '-'; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (newParams.tilerow == 0) { │ │ │ │ │ - tileRowGroup += '0'; │ │ │ │ │ - } else { │ │ │ │ │ - tileRowGroup += Math.floor(Math.abs(newParams.tilerow / this.params.tileRowsPerFolder)) * this.params.tileRowsPerFolder; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (newParams.tilecol < 0) { │ │ │ │ │ - tileColGroup = '-'; │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this)) { │ │ │ │ │ + if (this.listeners == null) { │ │ │ │ │ + this.setListeners(); │ │ │ │ │ + } │ │ │ │ │ + for (var type in this.listeners) { │ │ │ │ │ + this.map.events.register(type, this, this.listeners[type]); │ │ │ │ │ + } │ │ │ │ │ + activated = true; │ │ │ │ │ + if (this.previousStack.length == 0) { │ │ │ │ │ + this.initStack(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (newParams.tilecol == 0) { │ │ │ │ │ - tileColGroup += '0'; │ │ │ │ │ - } else { │ │ │ │ │ - tileColGroup += Math.floor(Math.abs(newParams.tilecol / this.params.tileColumnsPerFolder)) * this.params.tileColumnsPerFolder; │ │ │ │ │ + /** │ │ │ │ │ + * Method: initStack │ │ │ │ │ + * Called after the control is activated if the previous history stack is │ │ │ │ │ + * empty. │ │ │ │ │ + */ │ │ │ │ │ + initStack: function() { │ │ │ │ │ + if (this.map.getCenter()) { │ │ │ │ │ + this.listeners.moveend(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var tilePath = '/S' + Math.floor(newParams.scaleindex) + │ │ │ │ │ - '/' + this.params.basemaplayergroupname + │ │ │ │ │ - '/R' + tileRowGroup + │ │ │ │ │ - '/C' + tileColGroup + │ │ │ │ │ - '/' + (newParams.tilerow % this.params.tileRowsPerFolder) + │ │ │ │ │ - '_' + (newParams.tilecol % this.params.tileColumnsPerFolder) + │ │ │ │ │ - '.' + this.params.format; │ │ │ │ │ - │ │ │ │ │ - if (this.params.querystring) { │ │ │ │ │ - tilePath += "?" + this.params.querystring; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. This unregisters any listeners. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Control successfully deactivated. │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this)) { │ │ │ │ │ + for (var type in this.listeners) { │ │ │ │ │ + this.map.events.unregister( │ │ │ │ │ + type, this, this.listeners[type] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (this.clearOnDeactivate) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + } │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - requestString += tilePath; │ │ │ │ │ - return requestString; │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.MapGuide" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.NavigationHistory" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/ArcGIS93Rest.js │ │ │ │ │ + OpenLayers/Control/CacheRead.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/Control.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.ArcGIS93Rest │ │ │ │ │ - * Instances of OpenLayers.Layer.ArcGIS93Rest are used to display data from │ │ │ │ │ - * ESRI ArcGIS Server 9.3 (and up?) Mapping Services using the REST API. │ │ │ │ │ - * Create a new ArcGIS93Rest layer with the │ │ │ │ │ - * constructor. More detail on the REST API is available at │ │ │ │ │ - * http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/index.html ; │ │ │ │ │ - * specifically, the URL provided to this layer should be an export service │ │ │ │ │ - * URL: http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.CacheRead │ │ │ │ │ + * A control for using image tiles cached with │ │ │ │ │ + * from the browser's local storage. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.ArcGIS93Rest = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.CacheRead = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_PARAMS │ │ │ │ │ - * {Object} Hashtable of default parameter key/value pairs │ │ │ │ │ + * APIProperty: fetchEvent │ │ │ │ │ + * {String} The layer event to listen to for replacing remote resource tile │ │ │ │ │ + * URLs with cached data URIs. Supported values are "tileerror" (try │ │ │ │ │ + * remote first, fall back to cached) and "tileloadstart" (try cache │ │ │ │ │ + * first, fall back to remote). Default is "tileloadstart". │ │ │ │ │ + * │ │ │ │ │ + * Note that "tileerror" will not work for CORS enabled images (see │ │ │ │ │ + * https://developer.mozilla.org/en/CORS_Enabled_Image), i.e. layers │ │ │ │ │ + * configured with a in │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_PARAMS: { │ │ │ │ │ - format: "png" │ │ │ │ │ - }, │ │ │ │ │ + fetchEvent: "tileloadstart", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Default is true for ArcGIS93Rest layer │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()}. Optional. If provided, only these │ │ │ │ │ + * layers will receive tiles from the cache. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.ArcGIS93Rest │ │ │ │ │ - * Create a new ArcGIS93Rest layer object. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var arcims = new OpenLayers.Layer.ArcGIS93Rest("MyName", │ │ │ │ │ - * "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export", │ │ │ │ │ - * { │ │ │ │ │ - * layers: "0,1,2" │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * url - {String} Base url for the ArcGIS server REST service │ │ │ │ │ - * options - {Object} An object with key/value pairs representing the │ │ │ │ │ - * options and option values. │ │ │ │ │ - * │ │ │ │ │ - * Valid Options: │ │ │ │ │ - * format - {String} MIME type of desired image type. │ │ │ │ │ - * layers - {String} Comma-separated list of layers to display. │ │ │ │ │ - * srs - {String} Projection ID. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - var newArguments = []; │ │ │ │ │ - //uppercase params │ │ │ │ │ - params = OpenLayers.Util.upperCaseObject(params); │ │ │ │ │ - newArguments.push(name, url, params, options); │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - //layer is transparent │ │ │ │ │ - if (this.params.TRANSPARENT && │ │ │ │ │ - this.params.TRANSPARENT.toString().toLowerCase() == "true") { │ │ │ │ │ - │ │ │ │ │ - // unless explicitly set in options, make layer an overlay │ │ │ │ │ - if ((options == null) || (!options.isBaseLayer)) { │ │ │ │ │ - this.isBaseLayer = false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // jpegs can never be transparent, so intelligently switch the │ │ │ │ │ - // format, depending on the browser's capabilities │ │ │ │ │ - if (this.params.FORMAT == "jpg") { │ │ │ │ │ - this.params.FORMAT = OpenLayers.Util.alphaHack() ? "gif" : │ │ │ │ │ - "png"; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * Constructor: OpenLayers.Control.CacheRead │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Object with API properties for this control │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.ArcGIS93Rest(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + var i, layers = this.layers || map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (!this.layers) { │ │ │ │ │ + map.events.on({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * Return an image url this layer. │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ + * will be cached. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the map image's url. │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - │ │ │ │ │ - // ArcGIS Server only wants the numeric portion of the projection ID. │ │ │ │ │ - var projWords = this.projection.getCode().split(":"); │ │ │ │ │ - var srid = projWords[projWords.length - 1]; │ │ │ │ │ - │ │ │ │ │ - var imageSize = this.getImageSize(); │ │ │ │ │ - var newParams = { │ │ │ │ │ - 'BBOX': bounds.toBBOX(), │ │ │ │ │ - 'SIZE': imageSize.w + "," + imageSize.h, │ │ │ │ │ - // We always want image, the other options were json, image with a whole lotta html around it, etc. │ │ │ │ │ - 'F': "image", │ │ │ │ │ - 'BBOXSR': srid, │ │ │ │ │ - 'IMAGESR': srid │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // Now add the filter parameters. │ │ │ │ │ - if (this.layerDefs) { │ │ │ │ │ - var layerDefStrList = []; │ │ │ │ │ - var layerID; │ │ │ │ │ - for (layerID in this.layerDefs) { │ │ │ │ │ - if (this.layerDefs.hasOwnProperty(layerID)) { │ │ │ │ │ - if (this.layerDefs[layerID]) { │ │ │ │ │ - layerDefStrList.push(layerID); │ │ │ │ │ - layerDefStrList.push(":"); │ │ │ │ │ - layerDefStrList.push(this.layerDefs[layerID]); │ │ │ │ │ - layerDefStrList.push(";"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (layerDefStrList.length > 0) { │ │ │ │ │ - newParams['LAYERDEFS'] = layerDefStrList.join(""); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var requestString = this.getFullRequestString(newParams); │ │ │ │ │ - return requestString; │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + evt.layer.events.register(this.fetchEvent, this, this.fetch); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayerFilter │ │ │ │ │ - * addTile creates a tile, initializes it, and adds it to the layer div. │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ + * layer will no longer be cached. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * id - {String} The id of the layer to which the filter applies. │ │ │ │ │ - * queryDef - {String} A sql-ish query filter, for more detail see the ESRI │ │ │ │ │ - * documentation at http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - setLayerFilter: function(id, queryDef) { │ │ │ │ │ - if (!this.layerDefs) { │ │ │ │ │ - this.layerDefs = {}; │ │ │ │ │ - } │ │ │ │ │ - if (queryDef) { │ │ │ │ │ - this.layerDefs[id] = queryDef; │ │ │ │ │ - } else { │ │ │ │ │ - delete this.layerDefs[id]; │ │ │ │ │ - } │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + evt.layer.events.unregister(this.fetchEvent, this, this.fetch); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearLayerFilter │ │ │ │ │ - * Clears layer filters, either from a specific layer, │ │ │ │ │ - * or all of them. │ │ │ │ │ + * Method: fetch │ │ │ │ │ + * Listener to the event. Replaces a tile's url with a data │ │ │ │ │ + * URI from the cache. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * id - {String} The id of the layer from which to remove any │ │ │ │ │ - * filter. If unspecified/blank, all filters │ │ │ │ │ - * will be removed. │ │ │ │ │ + * evt - {Object} Event object with a tile property. │ │ │ │ │ */ │ │ │ │ │ - clearLayerFilter: function(id) { │ │ │ │ │ - if (id) { │ │ │ │ │ - delete this.layerDefs[id]; │ │ │ │ │ - } else { │ │ │ │ │ - delete this.layerDefs; │ │ │ │ │ + fetch: function(evt) { │ │ │ │ │ + if (this.active && window.localStorage && │ │ │ │ │ + evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ + var tile = evt.tile, │ │ │ │ │ + url = tile.url; │ │ │ │ │ + // deal with modified tile urls when both CacheWrite and CacheRead │ │ │ │ │ + // are active │ │ │ │ │ + if (!tile.layer.crossOriginKeyword && OpenLayers.ProxyHost && │ │ │ │ │ + url.indexOf(OpenLayers.ProxyHost) === 0) { │ │ │ │ │ + url = OpenLayers.Control.CacheWrite.urlMap[url]; │ │ │ │ │ + } │ │ │ │ │ + var dataURI = window.localStorage.getItem("olCache_" + url); │ │ │ │ │ + if (dataURI) { │ │ │ │ │ + tile.url = dataURI; │ │ │ │ │ + if (evt.type === "tileerror") { │ │ │ │ │ + tile.setImgSrc(dataURI); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * Catch changeParams and uppercase the new params to be merged in │ │ │ │ │ - * before calling changeParams on the super class. │ │ │ │ │ - * │ │ │ │ │ - * Once params have been changed, the tiles will be reloaded with │ │ │ │ │ - * the new parameters. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} Hashtable of new params to use │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - mergeNewParams: function(newParams) { │ │ │ │ │ - var upperParams = OpenLayers.Util.upperCaseObject(newParams); │ │ │ │ │ - var newArguments = [upperParams]; │ │ │ │ │ - return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, │ │ │ │ │ - newArguments); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layers || this.map) { │ │ │ │ │ + var i, layers = this.layers || this.map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.ArcGIS93Rest" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.CacheRead" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/TileCache.js │ │ │ │ │ + OpenLayers/Control/CacheWrite.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Console.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.TileCache │ │ │ │ │ - * A read only TileCache layer. Used to requests tiles cached by TileCache in │ │ │ │ │ - * a web accessible cache. This means that you have to pre-populate your │ │ │ │ │ - * cache before this layer can be used. It is meant only to read tiles │ │ │ │ │ - * created by TileCache, and not to make calls to TileCache for tile │ │ │ │ │ - * creation. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Control.CacheWrite │ │ │ │ │ + * A control for caching image tiles in the browser's local storage. The │ │ │ │ │ + * control is used to fetch and use the cached │ │ │ │ │ + * tile images. │ │ │ │ │ + * │ │ │ │ │ + * Note: Before using this control on any layer that is not your own, make sure │ │ │ │ │ + * that the terms of service of the tile provider allow local storage of tiles. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.TileCache = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Treat this layer as a base layer. Default is true. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * To register events in the constructor, configure . │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * cachefull - Triggered when the cache is full. Listeners receive an │ │ │ │ │ + * object with a tile property as first argument. The tile references │ │ │ │ │ + * the tile that couldn't be cached. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {String} Mime type of the images returned. Default is image/png. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} Object with event listeners, keyed by event name. An optional │ │ │ │ │ + * scope property defines the scope that listeners will be executed in. │ │ │ │ │ */ │ │ │ │ │ - format: 'image/png', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. (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: layers │ │ │ │ │ + * {Array()}. Optional. If provided, caching │ │ │ │ │ + * will be enabled for these layers only, otherwise for all cacheable │ │ │ │ │ + * layers. │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.TileCache │ │ │ │ │ - * Create a new read only TileCache layer. │ │ │ │ │ + * APIProperty: imageFormat │ │ │ │ │ + * {String} The image format used for caching. The default is "image/png". │ │ │ │ │ + * Supported formats depend on the user agent. If an unsupported │ │ │ │ │ + * is provided, "image/png" will be used. For aerial │ │ │ │ │ + * imagery, "image/jpeg" is recommended. │ │ │ │ │ + */ │ │ │ │ │ + imageFormat: "image/png", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: quotaRegEx │ │ │ │ │ + * {RegExp} │ │ │ │ │ + */ │ │ │ │ │ + quotaRegEx: (/quota/i), │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.CacheWrite │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} Name of the layer displayed in the interface │ │ │ │ │ - * url - {String} Location of the web accessible cache (not the location of │ │ │ │ │ - * your tilecache script!) │ │ │ │ │ - * layername - {String} Layer name as defined in the TileCache │ │ │ │ │ - * configuration │ │ │ │ │ - * options - {Object} Optional object with properties to be set on the │ │ │ │ │ - * layer. Note that you should speficy your resolutions to match │ │ │ │ │ - * your TileCache configuration. This can be done by setting │ │ │ │ │ - * the resolutions array directly (here or on the map), by setting │ │ │ │ │ - * maxResolution and numZoomLevels, or by using scale based properties. │ │ │ │ │ + * options - {Object} Object with API properties for this control. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, layername, options) { │ │ │ │ │ - this.layername = layername; │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, │ │ │ │ │ - [name, url, {}, options]); │ │ │ │ │ - this.extension = this.format.split('/')[1].toLowerCase(); │ │ │ │ │ - this.extension = (this.extension == 'jpg') ? 'jpeg' : this.extension; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * obj - {Object} │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.TileCache(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.layername, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + var i, layers = this.layers || map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + if (!this.layers) { │ │ │ │ │ + map.events.on({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ + /** │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ + * will be cached. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ + */ │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + evt.layer.events.on({ │ │ │ │ │ + tileloadstart: this.makeSameOrigin, │ │ │ │ │ + tileloaded: this.onTileLoaded, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ + * layer will no longer be cached. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ + */ │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + evt.layer.events.un({ │ │ │ │ │ + tileloadstart: this.makeSameOrigin, │ │ │ │ │ + tileloaded: this.onTileLoaded, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + /** │ │ │ │ │ + * Method: makeSameOrigin │ │ │ │ │ + * If the tile does not have CORS image loading enabled and is from a │ │ │ │ │ + * different origin, use OpenLayers.ProxyHost to make it a same origin url. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + */ │ │ │ │ │ + makeSameOrigin: function(evt) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + var tile = evt.tile; │ │ │ │ │ + if (tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ + !tile.crossOriginKeyword && │ │ │ │ │ + tile.url.substr(0, 5) !== "data:") { │ │ │ │ │ + var sameOriginUrl = OpenLayers.Request.makeSameOrigin( │ │ │ │ │ + tile.url, OpenLayers.ProxyHost │ │ │ │ │ + ); │ │ │ │ │ + OpenLayers.Control.CacheWrite.urlMap[sameOriginUrl] = tile.url; │ │ │ │ │ + tile.url = sameOriginUrl; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ + * Method: onTileLoaded │ │ │ │ │ + * Decides whether a tile can be cached and calls the cache method. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as parameters. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - var res = this.getServerResolution(); │ │ │ │ │ - var bbox = this.maxExtent; │ │ │ │ │ - var size = this.tileSize; │ │ │ │ │ - var tileX = Math.round((bounds.left - bbox.left) / (res * size.w)); │ │ │ │ │ - var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h)); │ │ │ │ │ - var tileZ = this.serverResolutions != null ? │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, res) : │ │ │ │ │ - this.map.getZoom(); │ │ │ │ │ + onTileLoaded: function(evt) { │ │ │ │ │ + if (this.active && !evt.aborted && │ │ │ │ │ + evt.tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ + evt.tile.url.substr(0, 5) !== 'data:') { │ │ │ │ │ + this.cache({ │ │ │ │ │ + tile: evt.tile │ │ │ │ │ + }); │ │ │ │ │ + delete OpenLayers.Control.CacheWrite.urlMap[evt.tile.url]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var components = [ │ │ │ │ │ - this.layername, │ │ │ │ │ - OpenLayers.Number.zeroPad(tileZ, 2), │ │ │ │ │ - OpenLayers.Number.zeroPad(parseInt(tileX / 1000000), 3), │ │ │ │ │ - OpenLayers.Number.zeroPad((parseInt(tileX / 1000) % 1000), 3), │ │ │ │ │ - OpenLayers.Number.zeroPad((parseInt(tileX) % 1000), 3), │ │ │ │ │ - OpenLayers.Number.zeroPad(parseInt(tileY / 1000000), 3), │ │ │ │ │ - OpenLayers.Number.zeroPad((parseInt(tileY / 1000) % 1000), 3), │ │ │ │ │ - OpenLayers.Number.zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension │ │ │ │ │ - ]; │ │ │ │ │ - var path = components.join('/'); │ │ │ │ │ - var url = this.url; │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(path, url); │ │ │ │ │ + /** │ │ │ │ │ + * Method: cache │ │ │ │ │ + * Adds a tile to the cache. When the cache is full, the "cachefull" event │ │ │ │ │ + * is triggered. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} Object with a tile property, tile being the │ │ │ │ │ + * with the data to add to the cache │ │ │ │ │ + */ │ │ │ │ │ + cache: function(obj) { │ │ │ │ │ + if (window.localStorage) { │ │ │ │ │ + var tile = obj.tile; │ │ │ │ │ + try { │ │ │ │ │ + var canvasContext = tile.getCanvasContext(); │ │ │ │ │ + if (canvasContext) { │ │ │ │ │ + var urlMap = OpenLayers.Control.CacheWrite.urlMap; │ │ │ │ │ + var url = urlMap[tile.url] || tile.url; │ │ │ │ │ + window.localStorage.setItem( │ │ │ │ │ + "olCache_" + url, │ │ │ │ │ + canvasContext.canvas.toDataURL(this.imageFormat) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } catch (e) { │ │ │ │ │ + // local storage full or CORS violation │ │ │ │ │ + var reason = e.name || e.message; │ │ │ │ │ + if (reason && this.quotaRegEx.test(reason)) { │ │ │ │ │ + this.events.triggerEvent("cachefull", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Console.error(e.toString()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - url = (url.charAt(url.length - 1) == '/') ? url : url + '/'; │ │ │ │ │ - return url + path; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.TileCache" │ │ │ │ │ + /** │ │ │ │ │ + * 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.layers || this.map) { │ │ │ │ │ + var i, layers = this.layers || this.map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.CacheWrite" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: OpenLayers.Control.CacheWrite.clearCache │ │ │ │ │ + * Clears all tiles cached with from the cache. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.CacheWrite.clearCache = function() { │ │ │ │ │ + if (!window.localStorage) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + var i, key; │ │ │ │ │ + for (i = window.localStorage.length - 1; i >= 0; --i) { │ │ │ │ │ + key = window.localStorage.key(i); │ │ │ │ │ + if (key.substr(0, 8) === "olCache_") { │ │ │ │ │ + window.localStorage.removeItem(key); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Property: OpenLayers.Control.CacheWrite.urlMap │ │ │ │ │ + * {Object} Mapping of same origin urls to cache url keys. Entries will be │ │ │ │ │ + * deleted as soon as a tile was cached. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.CacheWrite.urlMap = {}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/WMTS.js │ │ │ │ │ + OpenLayers/Control/Graticule.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/Control.js │ │ │ │ │ + * @requires OpenLayers/Lang.js │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/StyleMap.js │ │ │ │ │ + * @requires OpenLayers/Layer/Vector.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. │ │ │ │ │ + * Class: OpenLayers.Control.Graticule │ │ │ │ │ + * The Graticule displays a grid of latitude/longitude lines reprojected on │ │ │ │ │ + * the map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer will be considered a base layer. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} WMTS version. Default is "1.0.0". │ │ │ │ │ - */ │ │ │ │ │ - version: "1.0.0", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: requestEncoding │ │ │ │ │ - * {String} Request encoding. Can be "REST" or "KVP". Default is "KVP". │ │ │ │ │ - */ │ │ │ │ │ - requestEncoding: "KVP", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 . │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ +OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layer │ │ │ │ │ - * {String} The layer identifier advertised by the WMTS service. Must be │ │ │ │ │ - * provided. │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: matrixSet │ │ │ │ │ - * {String} One of the advertised matrix set identifiers. Must be provided. │ │ │ │ │ - */ │ │ │ │ │ - matrixSet: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {String} One of the advertised layer styles. Must be provided. │ │ │ │ │ - */ │ │ │ │ │ - style: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {String} The image MIME type. Default is "image/jpeg". │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - format: "image/jpeg", │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 . │ │ │ │ │ + * APIProperty: intervals │ │ │ │ │ + * {Array(Float)} A list of possible graticule widths in degrees. │ │ │ │ │ */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ + intervals: [45, 30, 20, 10, 5, 2, 1, │ │ │ │ │ + 0.5, 0.2, 0.1, 0.05, 0.01, │ │ │ │ │ + 0.005, 0.002, 0.001 │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: tileFullExtent │ │ │ │ │ - * {} The full extent of the tile set. If not supplied, │ │ │ │ │ - * the layer's property will be used. │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Allows the Graticule control to be switched on and off by │ │ │ │ │ + * LayerSwitcher control. Defaults is true. │ │ │ │ │ */ │ │ │ │ │ - tileFullExtent: null, │ │ │ │ │ + displayInLayerSwitcher: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: visible │ │ │ │ │ + * {Boolean} should the graticule be initially visible (default=true) │ │ │ │ │ */ │ │ │ │ │ - formatSuffix: null, │ │ │ │ │ + visible: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 . │ │ │ │ │ + * APIProperty: numPoints │ │ │ │ │ + * {Integer} The number of points to use in each graticule line. Higher │ │ │ │ │ + * numbers result in a smoother curve for projected maps │ │ │ │ │ */ │ │ │ │ │ - matrixIds: null, │ │ │ │ │ + numPoints: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: targetSize │ │ │ │ │ + * {Integer} The maximum size of the grid in pixels on the map │ │ │ │ │ */ │ │ │ │ │ - dimensions: null, │ │ │ │ │ + targetSize: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: layerName │ │ │ │ │ + * {String} The name to be displayed in the layer switcher, default is set │ │ │ │ │ + * by {}. │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + layerName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: labelled │ │ │ │ │ + * {Boolean} Should the graticule lines be labelled?. default=true │ │ │ │ │ */ │ │ │ │ │ - zoomOffset: 0, │ │ │ │ │ + labelled: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: labelFormat │ │ │ │ │ + * {String} the format of the labels, default = 'dm'. See │ │ │ │ │ + * for other options. │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + labelFormat: 'dm', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: formatSuffixMap │ │ │ │ │ - * {Object} a map between WMTS 'format' request parameter and tile image file suffix │ │ │ │ │ + * APIProperty: lineSymbolizer │ │ │ │ │ + * {symbolizer} the symbolizer used to render lines │ │ │ │ │ */ │ │ │ │ │ - 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" │ │ │ │ │ + lineSymbolizer: { │ │ │ │ │ + strokeColor: "#333", │ │ │ │ │ + strokeWidth: 1, │ │ │ │ │ + strokeOpacity: 0.5 │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: matrix │ │ │ │ │ - * {Object} Matrix definition for the current map resolution. Updated by │ │ │ │ │ - * the method. │ │ │ │ │ + * APIProperty: labelSymbolizer │ │ │ │ │ + * {symbolizer} the symbolizer used to render labels │ │ │ │ │ */ │ │ │ │ │ - matrix: null, │ │ │ │ │ + labelSymbolizer: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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