--- /srv/reproducible-results/rbuild-debian/r-b-build.gX5RP5Wc/b1/openlayers_2.13.1+ds2-11_i386.changes +++ /srv/reproducible-results/rbuild-debian/r-b-build.gX5RP5Wc/b2/openlayers_2.13.1+ds2-11_i386.changes ├── Files │ @@ -1,2 +1,2 @@ │ │ - a8b691201f10cf133bb27cf95f95c2dc 715616 javascript optional libjs-openlayers_2.13.1+ds2-11_all.deb │ + 4cd583dfa63c63f3db443d37dbe7c24b 721636 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 711740 2025-03-06 18:35:30.000000 data.tar.xz │ │ +-rw-r--r-- 0 0 0 717760 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,14 +52,37 @@ │ │ │ │ │ * 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. */ │ │ │ │ │ @@ -263,14 +286,268 @@ │ │ │ │ │ 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. */ │ │ │ │ │ @@ -1589,207 +1866,14 @@ │ │ │ │ │ │ │ │ │ │ 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. */ │ │ │ │ │ @@ -2243,268 +2327,14 @@ │ │ │ │ │ } │ │ │ │ │ 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. */ │ │ │ │ │ @@ -4426,8422 +4256,3965 @@ │ │ │ │ │ } else { │ │ │ │ │ str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N"); │ │ │ │ │ } │ │ │ │ │ return str; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Util/vendorPrefix.js │ │ │ │ │ + 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/SingleFile.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ /** │ │ │ │ │ - * Namespace: OpenLayers.Util.vendorPrefix │ │ │ │ │ - * A collection of utility functions to detect vendor prefixed features │ │ │ │ │ + * Namespace: OpenLayers.Element │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Util.vendorPrefix = (function() { │ │ │ │ │ - "use strict"; │ │ │ │ │ +OpenLayers.Element = { │ │ │ │ │ │ │ │ │ │ - var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], │ │ │ │ │ - divStyle = document.createElement("div").style, │ │ │ │ │ - cssCache = {}, │ │ │ │ │ - jsCache = {}; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * 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: │ │ │ │ │ - * prefixedDom - {String} The property to convert │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to search for. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The CSS property │ │ │ │ │ + * {Boolean} The element has the given class name. │ │ │ │ │ */ │ │ │ │ │ - function domToCss(prefixedDom) { │ │ │ │ │ - if (!prefixedDom) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - return prefixedDom. │ │ │ │ │ - replace(/([A-Z])/g, function(c) { │ │ │ │ │ - return "-" + c.toLowerCase(); │ │ │ │ │ - }). │ │ │ │ │ - replace(/^ms-/, "-ms-"); │ │ │ │ │ - } │ │ │ │ │ + hasClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + return (!!names && new RegExp("(^|\\s)" + name + "(\\s|$)").test(names)); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: css │ │ │ │ │ - * Detect which property is used for a CSS property │ │ │ │ │ + * Function: addClass │ │ │ │ │ + * Add a CSS class name to an element. Safe where element already has │ │ │ │ │ + * the class name. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to add. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + addClass: function(element, name) { │ │ │ │ │ + if (!OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + element.className += (element.className ? " " : "") + name; │ │ │ │ │ } │ │ │ │ │ - return cssCache[property]; │ │ │ │ │ - } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: js │ │ │ │ │ - * Detect which property is used for a JS property/method │ │ │ │ │ + * Function: removeClass │ │ │ │ │ + * Remove a CSS class name from an element. Safe where element does not │ │ │ │ │ + * have the class name. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} The object to test on │ │ │ │ │ - * property - {String} The standard (unprefixed) JS property name │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to remove. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The standard JS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + removeClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + if (names) { │ │ │ │ │ + element.className = OpenLayers.String.trim( │ │ │ │ │ + names.replace( │ │ │ │ │ + new RegExp("(^|\\s+)" + name + "(\\s+|$)"), " " │ │ │ │ │ + ) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return jsCache[property]; │ │ │ │ │ - } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: style │ │ │ │ │ - * Detect which property is used for a DOM style property │ │ │ │ │ + * Function: toggleClass │ │ │ │ │ + * Remove a CSS class name from an element if it exists. Add the class name │ │ │ │ │ + * if it doesn't exist. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) style property name │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to toggle. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The standard style property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ */ │ │ │ │ │ - function style(property) { │ │ │ │ │ - return js(divStyle, property); │ │ │ │ │ - } │ │ │ │ │ + toggleClass: function(element, name) { │ │ │ │ │ + if (OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + OpenLayers.Element.removeClass(element, name); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Element.addClass(element, name); │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return { │ │ │ │ │ - css: css, │ │ │ │ │ - js: js, │ │ │ │ │ - style: style, │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: getStyle │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * style - {?} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {?} │ │ │ │ │ + */ │ │ │ │ │ + getStyle: function(element, style) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ │ │ │ │ │ - // used for testing │ │ │ │ │ - cssCache: cssCache, │ │ │ │ │ - jsCache: jsCache │ │ │ │ │ - }; │ │ │ │ │ -}()); │ │ │ │ │ + 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/Events.js │ │ │ │ │ + Rico/Color.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 Rico/license.js │ │ │ │ │ + * @requires OpenLayers/Console.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ +/* │ │ │ │ │ + * This file has been edited substantially from the Rico-released version by │ │ │ │ │ + * the OpenLayers development team. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Event │ │ │ │ │ - * Utility functions for event handling. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Event = { │ │ │ │ │ +OpenLayers.Console.warn("OpenLayers.Rico is deprecated"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: observers │ │ │ │ │ - * {Object} A hashtable cache of the event observers. Keyed by │ │ │ │ │ - * element._eventCacheID │ │ │ │ │ - */ │ │ │ │ │ - observers: false, │ │ │ │ │ +OpenLayers.Rico = OpenLayers.Rico || {}; │ │ │ │ │ +OpenLayers.Rico.Color = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_SPACE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_SPACE: 32, │ │ │ │ │ + initialize: function(red, green, blue) { │ │ │ │ │ + this.rgb = { │ │ │ │ │ + r: red, │ │ │ │ │ + g: green, │ │ │ │ │ + b: blue │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_BACKSPACE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_BACKSPACE: 8, │ │ │ │ │ + setRed: function(r) { │ │ │ │ │ + this.rgb.r = r; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_TAB │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_TAB: 9, │ │ │ │ │ + setGreen: function(g) { │ │ │ │ │ + this.rgb.g = g; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_RETURN │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_RETURN: 13, │ │ │ │ │ + setBlue: function(b) { │ │ │ │ │ + this.rgb.b = b; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_ESC │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_ESC: 27, │ │ │ │ │ + setHue: function(h) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_LEFT │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_LEFT: 37, │ │ │ │ │ + // get an HSB model, and set the new hue... │ │ │ │ │ + var hsb = this.asHSB(); │ │ │ │ │ + hsb.h = h; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_UP │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_UP: 38, │ │ │ │ │ + // convert back to RGB... │ │ │ │ │ + this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_RIGHT │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_RIGHT: 39, │ │ │ │ │ + setSaturation: function(s) { │ │ │ │ │ + // get an HSB model, and set the new hue... │ │ │ │ │ + var hsb = this.asHSB(); │ │ │ │ │ + hsb.s = s; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_DOWN │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_DOWN: 40, │ │ │ │ │ + // convert back to RGB and set values... │ │ │ │ │ + this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_DELETE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_DELETE: 46, │ │ │ │ │ + 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: element │ │ │ │ │ - * Cross browser event element detection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The element that caused the event │ │ │ │ │ - */ │ │ │ │ │ - element: function(event) { │ │ │ │ │ - return event.target || event.srcElement; │ │ │ │ │ + darken: function(percent) { │ │ │ │ │ + var hsb = this.asHSB(); │ │ │ │ │ + this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent, 0)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: isSingleTouch │ │ │ │ │ - * Determine whether event was caused by a single touch │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isSingleTouch: function(event) { │ │ │ │ │ - return event.touches && event.touches.length == 1; │ │ │ │ │ + brighten: function(percent) { │ │ │ │ │ + var hsb = this.asHSB(); │ │ │ │ │ + this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent, 1)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: isMultiTouch │ │ │ │ │ - * Determine whether event was caused by a multi touch │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isMultiTouch: function(event) { │ │ │ │ │ - return event.touches && event.touches.length > 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: isLeftClick │ │ │ │ │ - * Determine whether event was caused by a left click. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isLeftClick: function(event) { │ │ │ │ │ - return (((event.which) && (event.which == 1)) || │ │ │ │ │ - ((event.button) && (event.button == 1))); │ │ │ │ │ + isBright: function() { │ │ │ │ │ + var hsb = this.asHSB(); │ │ │ │ │ + return this.asHSB().b > 0.5; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: isRightClick │ │ │ │ │ - * Determine whether event was caused by a right mouse click. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isRightClick: function(event) { │ │ │ │ │ - return (((event.which) && (event.which == 3)) || │ │ │ │ │ - ((event.button) && (event.button == 2))); │ │ │ │ │ + isDark: function() { │ │ │ │ │ + return !this.isBright(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: stop │ │ │ │ │ - * Stops an event from propagating. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * allowDefault - {Boolean} If true, we stop the event chain but │ │ │ │ │ - * still allow the default browser behaviour (text selection, │ │ │ │ │ - * radio-button clicking, etc). Default is false. │ │ │ │ │ - */ │ │ │ │ │ - stop: function(event, allowDefault) { │ │ │ │ │ + asRGB: function() { │ │ │ │ │ + return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (!allowDefault) { │ │ │ │ │ - OpenLayers.Event.preventDefault(event); │ │ │ │ │ + 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)); │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - if (event.stopPropagation) { │ │ │ │ │ - event.stopPropagation(); │ │ │ │ │ +/** │ │ │ │ │ + * Factory method for creating a color from the background of │ │ │ │ │ + * an HTML element. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Rico.Color.createColorFromBackground = function(elem) { │ │ │ │ │ + │ │ │ │ │ + var actualColor = │ │ │ │ │ + OpenLayers.Element.getStyle(OpenLayers.Util.getElement(elem), │ │ │ │ │ + "backgroundColor"); │ │ │ │ │ + │ │ │ │ │ + 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])); │ │ │ │ │ + │ │ │ │ │ + } else if (actualColor.indexOf("#") == 0) { │ │ │ │ │ + return OpenLayers.Rico.Color.createFromHex(actualColor); │ │ │ │ │ + } else { │ │ │ │ │ + return new OpenLayers.Rico.Color(255, 255, 255); │ │ │ │ │ + } │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { │ │ │ │ │ + │ │ │ │ │ + var red = 0; │ │ │ │ │ + var green = 0; │ │ │ │ │ + var blue = 0; │ │ │ │ │ + │ │ │ │ │ + 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))); │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + r: parseInt(red), │ │ │ │ │ + g: parseInt(green), │ │ │ │ │ + b: parseInt(blue) │ │ │ │ │ + }; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { │ │ │ │ │ + │ │ │ │ │ + var hue; │ │ │ │ │ + var saturation; │ │ │ │ │ + var brightness; │ │ │ │ │ + │ │ │ │ │ + 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); │ │ │ │ │ + │ │ │ │ │ + if (r == cmax) { │ │ │ │ │ + hue = bluec - greenc; │ │ │ │ │ + } else if (g == cmax) { │ │ │ │ │ + hue = 2.0 + redc - bluec; │ │ │ │ │ } else { │ │ │ │ │ - event.cancelBubble = true; │ │ │ │ │ + hue = 4.0 + greenc - redc; │ │ │ │ │ + } │ │ │ │ │ + hue = hue / 6.0; │ │ │ │ │ + if (hue < 0) { │ │ │ │ │ + hue = hue + 1.0; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + 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 = { │ │ │ │ │ + │ │ │ │ │ + round: function(e, options) { │ │ │ │ │ + e = OpenLayers.Util.getElement(e); │ │ │ │ │ + this._setOptions(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._roundCornersImpl(e, color, bgColor); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: preventDefault │ │ │ │ │ - * Cancels the event if it is cancelable, without stopping further │ │ │ │ │ - * propagation of the event. │ │ │ │ │ + /** This is a helper function to change the background │ │ │ │ │ + * color of
that has had Rico rounded corners added. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - preventDefault: function(event) { │ │ │ │ │ - if (event.preventDefault) { │ │ │ │ │ - event.preventDefault(); │ │ │ │ │ - } else { │ │ │ │ │ - event.returnValue = false; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: findElement │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Event} │ │ │ │ │ - * tagName - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The first node with the given tagName, starting from the │ │ │ │ │ - * node the event was triggered on and traversing the DOM upwards │ │ │ │ │ + │ │ │ │ │ + /** 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). │ │ │ │ │ */ │ │ │ │ │ - findElement: function(event, tagName) { │ │ │ │ │ - var element = OpenLayers.Event.element(event); │ │ │ │ │ - while (element.parentNode && (!element.tagName || │ │ │ │ │ - (element.tagName.toUpperCase() != tagName.toUpperCase()))) { │ │ │ │ │ - element = element.parentNode; │ │ │ │ │ + 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"); │ │ │ │ │ + │ │ │ │ │ + for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { │ │ │ │ │ + spanElements[currIdx].style.opacity = mozillaOpacity; │ │ │ │ │ + spanElements[currIdx].style.filter = ieOpacity; │ │ │ │ │ } │ │ │ │ │ - return element; │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: observe │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * elementParam - {DOMElement || String} │ │ │ │ │ - * name - {String} │ │ │ │ │ - * observer - {function} │ │ │ │ │ - * useCapture - {Boolean} │ │ │ │ │ + /** 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. │ │ │ │ │ + * │ │ │ │ │ + * @param {Object} options - list of options │ │ │ │ │ */ │ │ │ │ │ - observe: function(elementParam, name, observer, useCapture) { │ │ │ │ │ - var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ - useCapture = useCapture || false; │ │ │ │ │ + reRound: function(theDiv, options) { │ │ │ │ │ │ │ │ │ │ - if (name == 'keypress' && │ │ │ │ │ - (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ - element.attachEvent)) { │ │ │ │ │ - name = 'keydown'; │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //if observers cache has not yet been created, create it │ │ │ │ │ - if (!this.observers) { │ │ │ │ │ - this.observers = {}; │ │ │ │ │ + _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")); │ │ │ │ │ } │ │ │ │ │ + el.style.paddingTop = 0; │ │ │ │ │ + el.insertBefore(corner, el.firstChild); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //if not already assigned, make a new unique cache ID │ │ │ │ │ - if (!element._eventCacheID) { │ │ │ │ │ - var idPrefix = "eventCacheID_"; │ │ │ │ │ - if (element.id) { │ │ │ │ │ - idPrefix = element.id + "_" + idPrefix; │ │ │ │ │ - } │ │ │ │ │ - element._eventCacheID = OpenLayers.Util.createUniqueID(idPrefix); │ │ │ │ │ + _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")); │ │ │ │ │ } │ │ │ │ │ + el.style.paddingBottom = 0; │ │ │ │ │ + el.appendChild(corner); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var cacheID = element._eventCacheID; │ │ │ │ │ + _createCorner: function(bgColor) { │ │ │ │ │ + var corner = document.createElement("div"); │ │ │ │ │ + corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); │ │ │ │ │ + return corner; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //if there is not yet a hash entry for this element, add one │ │ │ │ │ - if (!this.observers[cacheID]) { │ │ │ │ │ - this.observers[cacheID] = []; │ │ │ │ │ - } │ │ │ │ │ + _createCornerSlice: function(color, bgColor, n, position) { │ │ │ │ │ + var slice = document.createElement("span"); │ │ │ │ │ │ │ │ │ │ - //add a new observer to this element's list │ │ │ │ │ - this.observers[cacheID].push({ │ │ │ │ │ - 'element': element, │ │ │ │ │ - 'name': name, │ │ │ │ │ - 'observer': observer, │ │ │ │ │ - 'useCapture': useCapture │ │ │ │ │ - }); │ │ │ │ │ + var inStyle = slice.style; │ │ │ │ │ + inStyle.backgroundColor = color; │ │ │ │ │ + inStyle.display = "block"; │ │ │ │ │ + inStyle.height = "1px"; │ │ │ │ │ + inStyle.overflow = "hidden"; │ │ │ │ │ + inStyle.fontSize = "1px"; │ │ │ │ │ │ │ │ │ │ - //add the actual browser event listener │ │ │ │ │ - if (element.addEventListener) { │ │ │ │ │ - element.addEventListener(name, observer, useCapture); │ │ │ │ │ - } else if (element.attachEvent) { │ │ │ │ │ - element.attachEvent('on' + name, observer); │ │ │ │ │ + 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"; │ │ │ │ │ } │ │ │ │ │ + this._setMargin(slice, n, position); │ │ │ │ │ + this._setBorder(slice, n, position); │ │ │ │ │ + return slice; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: stopObservingElement │ │ │ │ │ - * Given the id of an element to stop observing, cycle through the │ │ │ │ │ - * element's cached observers, calling stopObserving on each one, │ │ │ │ │ - * skipping those entries which can no longer be removed. │ │ │ │ │ - * │ │ │ │ │ - * parameters: │ │ │ │ │ - * elementParam - {DOMElement || String} │ │ │ │ │ - */ │ │ │ │ │ - stopObservingElement: function(elementParam) { │ │ │ │ │ - var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ - var cacheID = element._eventCacheID; │ │ │ │ │ + _setOptions: function(options) { │ │ │ │ │ + this.options = { │ │ │ │ │ + corners: "all", │ │ │ │ │ + color: "fromElement", │ │ │ │ │ + bgColor: "fromParent", │ │ │ │ │ + blend: true, │ │ │ │ │ + border: false, │ │ │ │ │ + compact: false │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Util.extend(this.options, options || {}); │ │ │ │ │ │ │ │ │ │ - this._removeElementObservers(OpenLayers.Event.observers[cacheID]); │ │ │ │ │ + this.options.numSlices = this.options.compact ? 2 : 4; │ │ │ │ │ + if (this._isTransparent()) { │ │ │ │ │ + this.options.blend = false; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: _removeElementObservers │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * elementObservers - {Array(Object)} Array of (element, name, │ │ │ │ │ - * observer, usecapture) objects, │ │ │ │ │ - * taken directly from hashtable │ │ │ │ │ - */ │ │ │ │ │ - _removeElementObservers: function(elementObservers) { │ │ │ │ │ - if (elementObservers) { │ │ │ │ │ - for (var i = elementObservers.length - 1; i >= 0; i--) { │ │ │ │ │ - var entry = elementObservers[i]; │ │ │ │ │ - OpenLayers.Event.stopObserving.apply(this, [ │ │ │ │ │ - entry.element, entry.name, entry.observer, entry.useCapture │ │ │ │ │ - ]); │ │ │ │ │ - } │ │ │ │ │ + _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: stopObserving │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * elementParam - {DOMElement || String} │ │ │ │ │ - * name - {String} │ │ │ │ │ - * observer - {function} │ │ │ │ │ - * useCapture - {Boolean} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the event observer was removed │ │ │ │ │ - */ │ │ │ │ │ - stopObserving: function(elementParam, name, observer, useCapture) { │ │ │ │ │ - useCapture = useCapture || false; │ │ │ │ │ + _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 ""; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ - var cacheID = element._eventCacheID; │ │ │ │ │ + if (this.options.corners.indexOf("bl") >= 0) { │ │ │ │ │ + return "left"; │ │ │ │ │ + } else if (this.options.corners.indexOf("br") >= 0) { │ │ │ │ │ + return "right"; │ │ │ │ │ + } │ │ │ │ │ + return ""; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (name == 'keypress') { │ │ │ │ │ - if (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ - element.detachEvent) { │ │ │ │ │ - name = 'keydown'; │ │ │ │ │ - } │ │ │ │ │ + _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 ""; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // find element's entry in this.observers cache and remove it │ │ │ │ │ - var foundEntry = false; │ │ │ │ │ - var elementObservers = OpenLayers.Event.observers[cacheID]; │ │ │ │ │ - if (elementObservers) { │ │ │ │ │ │ │ │ │ │ - // find the specific event type in the element's list │ │ │ │ │ - var i = 0; │ │ │ │ │ - while (!foundEntry && i < elementObservers.length) { │ │ │ │ │ - var cacheEntry = elementObservers[i]; │ │ │ │ │ + _setMargin: function(el, n, corners) { │ │ │ │ │ + var marginSize = this._marginSize(n); │ │ │ │ │ + var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); │ │ │ │ │ │ │ │ │ │ - if ((cacheEntry.name == name) && │ │ │ │ │ - (cacheEntry.observer == observer) && │ │ │ │ │ - (cacheEntry.useCapture == useCapture)) { │ │ │ │ │ + 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"; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - elementObservers.splice(i, 1); │ │ │ │ │ - if (elementObservers.length == 0) { │ │ │ │ │ - delete OpenLayers.Event.observers[cacheID]; │ │ │ │ │ - } │ │ │ │ │ - foundEntry = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - i++; │ │ │ │ │ - } │ │ │ │ │ + _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"; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //actually remove the event listener from browser │ │ │ │ │ - if (foundEntry) { │ │ │ │ │ - if (element.removeEventListener) { │ │ │ │ │ - element.removeEventListener(name, observer, useCapture); │ │ │ │ │ - } else if (element && element.detachEvent) { │ │ │ │ │ - element.detachEvent('on' + name, observer); │ │ │ │ │ - } │ │ │ │ │ + _marginSize: function(n) { │ │ │ │ │ + if (this._isTransparent()) { │ │ │ │ │ + return 0; │ │ │ │ │ + } │ │ │ │ │ + var marginSizes = [5, 3, 2, 1]; │ │ │ │ │ + var blendedMarginSizes = [3, 2, 1, 0]; │ │ │ │ │ + var compactMarginSizes = [2, 1]; │ │ │ │ │ + var smBlendedMarginSizes = [1, 0]; │ │ │ │ │ + │ │ │ │ │ + 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]; │ │ │ │ │ } │ │ │ │ │ - return foundEntry; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: unloadCache │ │ │ │ │ - * Cycle through all the element entries in the events cache and call │ │ │ │ │ - * stopObservingElement on each. │ │ │ │ │ - */ │ │ │ │ │ - unloadCache: function() { │ │ │ │ │ - // check for OpenLayers.Event before checking for observers, because │ │ │ │ │ - // OpenLayers.Event may be undefined in IE if no map instance was │ │ │ │ │ - // created │ │ │ │ │ - if (OpenLayers.Event && OpenLayers.Event.observers) { │ │ │ │ │ - for (var cacheID in OpenLayers.Event.observers) { │ │ │ │ │ - var elementObservers = OpenLayers.Event.observers[cacheID]; │ │ │ │ │ - OpenLayers.Event._removeElementObservers.apply(this, │ │ │ │ │ - [elementObservers]); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.observers = false; │ │ │ │ │ + _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]; │ │ │ │ │ + │ │ │ │ │ + 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]; │ │ │ │ │ } │ │ │ │ │ + return 0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Event" │ │ │ │ │ + _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; │ │ │ │ │ + } │ │ │ │ │ }; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ -/* prevent memory leaks in IE */ │ │ │ │ │ -OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, 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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: BROWSER_EVENTS │ │ │ │ │ - * {Array(String)} supported events │ │ │ │ │ - */ │ │ │ │ │ - BROWSER_EVENTS: [ │ │ │ │ │ - "mouseover", "mouseout", │ │ │ │ │ - "mousedown", "mouseup", "mousemove", │ │ │ │ │ - "click", "dblclick", "rightclick", "dblrightclick", │ │ │ │ │ - "resize", "focus", "blur", │ │ │ │ │ - "touchstart", "touchmove", "touchend", │ │ │ │ │ - "keydown" │ │ │ │ │ - ], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: listeners │ │ │ │ │ - * {Object} Hashtable of Array(Function): events listener functions │ │ │ │ │ - */ │ │ │ │ │ - listeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: object │ │ │ │ │ - * {Object} the code object issuing application events │ │ │ │ │ - */ │ │ │ │ │ - object: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} the DOM element receiving browser events │ │ │ │ │ - */ │ │ │ │ │ - element: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: eventHandler │ │ │ │ │ - * {Function} bound event handler attached to elements │ │ │ │ │ - */ │ │ │ │ │ - eventHandler: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fallThrough │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - fallThrough: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: includeXY │ │ │ │ │ - * {Boolean} Should the .xy property automatically be created for browser │ │ │ │ │ - * mouse events? In general, this should be false. If it is true, then │ │ │ │ │ - * mouse events will automatically generate a '.xy' property on the │ │ │ │ │ - * event object that is passed. (Prior to OpenLayers 2.7, this was true │ │ │ │ │ - * by default.) Otherwise, you can call the getMousePosition on the │ │ │ │ │ - * relevant events handler on the object available via the 'evt.object' │ │ │ │ │ - * property of the evt object. So, for most events, you can call: │ │ │ │ │ - * function named(evt) { │ │ │ │ │ - * this.xy = this.object.events.getMousePosition(evt) │ │ │ │ │ - * } │ │ │ │ │ - * │ │ │ │ │ - * This option typically defaults to false for performance reasons: │ │ │ │ │ - * when creating an events object whose primary purpose is to manage │ │ │ │ │ - * relatively positioned mouse events within a div, it may make │ │ │ │ │ - * sense to set it to true. │ │ │ │ │ - * │ │ │ │ │ - * This option is also used to control whether the events object caches │ │ │ │ │ - * offsets. If this is false, it will not: the reason for this is that │ │ │ │ │ - * it is only expected to be called many times if the includeXY property │ │ │ │ │ - * is set to true. If you set this to true, you are expected to clear │ │ │ │ │ - * the offset cache manually (using this.clearMouseCache()) if: │ │ │ │ │ - * the border of the element changes │ │ │ │ │ - * the location of the element in the page changes │ │ │ │ │ - */ │ │ │ │ │ - includeXY: false, │ │ │ │ │ +/** │ │ │ │ │ + * 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({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: extensions │ │ │ │ │ - * {Object} Event extensions registered with this instance. Keys are │ │ │ │ │ - * event types, values are {OpenLayers.Events.*} extension instances or │ │ │ │ │ - * {Boolean} for events that an instantiated extension provides in │ │ │ │ │ - * addition to the one it was created for. │ │ │ │ │ - * │ │ │ │ │ - * Extensions create an event in addition to browser events, which usually │ │ │ │ │ - * fires when a sequence of browser events is completed. Extensions are │ │ │ │ │ - * automatically instantiated when a listener is registered for an event │ │ │ │ │ - * provided by an extension. │ │ │ │ │ - * │ │ │ │ │ - * Extensions are created in the namespace using │ │ │ │ │ - * , and named after the event they provide. │ │ │ │ │ - * The constructor receives the target instance as │ │ │ │ │ - * argument. Extensions that need to capture browser events before they │ │ │ │ │ - * propagate can register their listeners events using , with │ │ │ │ │ - * {extension: true} as 4th argument. │ │ │ │ │ - * │ │ │ │ │ - * If an extension creates more than one event, an alias for each event │ │ │ │ │ - * type should be created and reference the same class. The constructor │ │ │ │ │ - * should set a reference in the target's extensions registry to itself. │ │ │ │ │ - * │ │ │ │ │ - * Below is a minimal extension that provides the "foostart" and "fooend" │ │ │ │ │ - * event types, which replace the native "click" event type if clicked on │ │ │ │ │ - * an element with the css class "foo": │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * OpenLayers.Events.foostart = OpenLayers.Class({ │ │ │ │ │ - * initialize: function(target) { │ │ │ │ │ - * this.target = target; │ │ │ │ │ - * this.target.register("click", this, this.doStuff, {extension: true}); │ │ │ │ │ - * // only required if extension provides more than one event type │ │ │ │ │ - * this.target.extensions["foostart"] = true; │ │ │ │ │ - * this.target.extensions["fooend"] = true; │ │ │ │ │ - * }, │ │ │ │ │ - * destroy: function() { │ │ │ │ │ - * var target = this.target; │ │ │ │ │ - * target.unregister("click", this, this.doStuff); │ │ │ │ │ - * delete this.target; │ │ │ │ │ - * // only required if extension provides more than one event type │ │ │ │ │ - * delete target.extensions["foostart"]; │ │ │ │ │ - * delete target.extensions["fooend"]; │ │ │ │ │ - * }, │ │ │ │ │ - * doStuff: function(evt) { │ │ │ │ │ - * var propagate = true; │ │ │ │ │ - * if (OpenLayers.Event.element(evt).className === "foo") { │ │ │ │ │ - * propagate = false; │ │ │ │ │ - * var target = this.target; │ │ │ │ │ - * target.triggerEvent("foostart"); │ │ │ │ │ - * window.setTimeout(function() { │ │ │ │ │ - * target.triggerEvent("fooend"); │ │ │ │ │ - * }, 1000); │ │ │ │ │ - * } │ │ │ │ │ - * return propagate; │ │ │ │ │ - * } │ │ │ │ │ - * }); │ │ │ │ │ - * // only required if extension provides more than one event type │ │ │ │ │ - * OpenLayers.Events.fooend = OpenLayers.Events.foostart; │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique identifier for this geometry. │ │ │ │ │ */ │ │ │ │ │ - extensions: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: extensionCount │ │ │ │ │ - * {Object} Keys are event types (like in ), values are the │ │ │ │ │ - * number of extension listeners for each event type. │ │ │ │ │ + * Property: parent │ │ │ │ │ + * {}This is set when a Geometry is added as component │ │ │ │ │ + * of another geometry │ │ │ │ │ */ │ │ │ │ │ - extensionCount: null, │ │ │ │ │ + parent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearMouseListener │ │ │ │ │ - * A version of that is bound to this instance so that │ │ │ │ │ - * it can be used with and │ │ │ │ │ - * . │ │ │ │ │ + * Property: bounds │ │ │ │ │ + * {} The bounds of this geometry │ │ │ │ │ */ │ │ │ │ │ - clearMouseListener: null, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Events │ │ │ │ │ - * Construct an OpenLayers.Events object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} The js object to which this Events object is being added │ │ │ │ │ - * element - {DOMElement} A dom element to respond to browser events │ │ │ │ │ - * eventTypes - {Array(String)} Deprecated. Array of custom application │ │ │ │ │ - * events. A listener may be registered for any named event, regardless │ │ │ │ │ - * of the values provided here. │ │ │ │ │ - * fallThrough - {Boolean} Allow events to fall through after these have │ │ │ │ │ - * been handled? │ │ │ │ │ - * options - {Object} Options for the events object. │ │ │ │ │ + * Constructor: OpenLayers.Geometry │ │ │ │ │ + * Creates a geometry object. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(object, element, eventTypes, fallThrough, options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.object = object; │ │ │ │ │ - this.fallThrough = fallThrough; │ │ │ │ │ - this.listeners = {}; │ │ │ │ │ - this.extensions = {}; │ │ │ │ │ - this.extensionCount = {}; │ │ │ │ │ - this._msTouches = []; │ │ │ │ │ - │ │ │ │ │ - // if a dom element is specified, add a listeners list │ │ │ │ │ - // for browser events on the element and register them │ │ │ │ │ - if (element != null) { │ │ │ │ │ - this.attachToElement(element); │ │ │ │ │ - } │ │ │ │ │ + initialize: function() { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - for (var e in this.extensions) { │ │ │ │ │ - if (typeof this.extensions[e] !== "boolean") { │ │ │ │ │ - this.extensions[e].destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.extensions = null; │ │ │ │ │ - if (this.element) { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.element); │ │ │ │ │ - if (this.element.hasScrollEvent) { │ │ │ │ │ - OpenLayers.Event.stopObserving( │ │ │ │ │ - window, "scroll", this.clearMouseListener │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.element = null; │ │ │ │ │ - │ │ │ │ │ - this.listeners = null; │ │ │ │ │ - this.object = null; │ │ │ │ │ - this.fallThrough = null; │ │ │ │ │ - this.eventHandler = null; │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addEventType │ │ │ │ │ - * Deprecated. Any event can be triggered without adding it first. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a clone of this geometry. Does not set any non-standard │ │ │ │ │ + * properties of the cloned geometry. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * eventName - {String} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this geometry. │ │ │ │ │ */ │ │ │ │ │ - addEventType: function(eventName) {}, │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Geometry(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: attachToElement │ │ │ │ │ - * │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Set the bounds for this Geometry. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {HTMLDOMElement} a DOM element to attach browser events to │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - attachToElement: function(element) { │ │ │ │ │ - if (this.element) { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.element); │ │ │ │ │ - } else { │ │ │ │ │ - // keep a bound copy of handleBrowserEvent() so that we can │ │ │ │ │ - // pass the same function to both Event.observe() and .stopObserving() │ │ │ │ │ - this.eventHandler = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ - this.handleBrowserEvent, this │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // to be used with observe and stopObserving │ │ │ │ │ - this.clearMouseListener = OpenLayers.Function.bind( │ │ │ │ │ - this.clearMouseCache, this │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.element = element; │ │ │ │ │ - var msTouch = !!window.navigator.msMaxTouchPoints; │ │ │ │ │ - var type; │ │ │ │ │ - for (var i = 0, len = this.BROWSER_EVENTS.length; i < len; i++) { │ │ │ │ │ - type = this.BROWSER_EVENTS[i]; │ │ │ │ │ - // register the event cross-browser │ │ │ │ │ - OpenLayers.Event.observe(element, type, this.eventHandler); │ │ │ │ │ - if (msTouch && type.indexOf('touch') === 0) { │ │ │ │ │ - this.addMsTouchListener(element, type, this.eventHandler); │ │ │ │ │ - } │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + if (bounds) { │ │ │ │ │ + this.bounds = bounds.clone(); │ │ │ │ │ } │ │ │ │ │ - // disable dragstart in IE so that mousedown/move/up works normally │ │ │ │ │ - OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: on │ │ │ │ │ - * Convenience method for registering listeners with a common scope. │ │ │ │ │ - * Internally, this method calls as shown in the examples │ │ │ │ │ - * below. │ │ │ │ │ - * │ │ │ │ │ - * Example use: │ │ │ │ │ - * (code) │ │ │ │ │ - * // register a single listener for the "loadstart" event │ │ │ │ │ - * events.on({"loadstart": loadStartListener}); │ │ │ │ │ - * │ │ │ │ │ - * // this is equivalent to the following │ │ │ │ │ - * events.register("loadstart", undefined, loadStartListener); │ │ │ │ │ - * │ │ │ │ │ - * // register multiple listeners to be called with the same `this` object │ │ │ │ │ - * events.on({ │ │ │ │ │ - * "loadstart": loadStartListener, │ │ │ │ │ - * "loadend": loadEndListener, │ │ │ │ │ - * scope: object │ │ │ │ │ - * }); │ │ │ │ │ - * │ │ │ │ │ - * // this is equivalent to the following │ │ │ │ │ - * events.register("loadstart", object, loadStartListener); │ │ │ │ │ - * events.register("loadend", object, loadEndListener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} │ │ │ │ │ + * Method: clearBounds │ │ │ │ │ + * Nullify this components bounds and that of its parent as well. │ │ │ │ │ */ │ │ │ │ │ - on: function(object) { │ │ │ │ │ - for (var type in object) { │ │ │ │ │ - if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ - this.register(type, object.scope, object[type]); │ │ │ │ │ - } │ │ │ │ │ + clearBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + if (this.parent) { │ │ │ │ │ + this.parent.clearBounds(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: register │ │ │ │ │ - * Register an event on the events object. │ │ │ │ │ - * │ │ │ │ │ - * When the event is triggered, the 'func' function will be called, in the │ │ │ │ │ - * context of 'obj'. Imagine we were to register an event, specifying an │ │ │ │ │ - * OpenLayers.Bounds Object as 'obj'. When the event is triggered, the │ │ │ │ │ - * context in the callback function will be our Bounds object. This means │ │ │ │ │ - * that within our callback function, we can access the properties and │ │ │ │ │ - * methods of the Bounds object through the "this" variable. So our │ │ │ │ │ - * callback could execute something like: │ │ │ │ │ - * : leftStr = "Left: " + this.left; │ │ │ │ │ - * │ │ │ │ │ - * or │ │ │ │ │ - * │ │ │ │ │ - * : centerStr = "Center: " + this.getCenterLonLat(); │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * type - {String} Name of the event to register │ │ │ │ │ - * obj - {Object} The object to bind the context to for the callback#. │ │ │ │ │ - * If no object is specified, default is the Events's 'object' property. │ │ │ │ │ - * func - {Function} The callback function. If no callback is │ │ │ │ │ - * specified, this function does nothing. │ │ │ │ │ - * priority - {Boolean|Object} If true, adds the new listener to the │ │ │ │ │ - * *front* of the events queue instead of to the end. │ │ │ │ │ - * │ │ │ │ │ - * Valid options for priority: │ │ │ │ │ - * extension - {Boolean} If true, then the event will be registered as │ │ │ │ │ - * extension event. Extension events are handled before all other │ │ │ │ │ - * events. │ │ │ │ │ + * newBounds - {} │ │ │ │ │ */ │ │ │ │ │ - register: function(type, obj, func, priority) { │ │ │ │ │ - if (type in OpenLayers.Events && !this.extensions[type]) { │ │ │ │ │ - this.extensions[type] = new OpenLayers.Events[type](this); │ │ │ │ │ - } │ │ │ │ │ - if (func != null) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = this.object; │ │ │ │ │ - } │ │ │ │ │ - var listeners = this.listeners[type]; │ │ │ │ │ - if (!listeners) { │ │ │ │ │ - listeners = []; │ │ │ │ │ - this.listeners[type] = listeners; │ │ │ │ │ - this.extensionCount[type] = 0; │ │ │ │ │ - } │ │ │ │ │ - var listener = { │ │ │ │ │ - obj: obj, │ │ │ │ │ - func: func │ │ │ │ │ - }; │ │ │ │ │ - if (priority) { │ │ │ │ │ - listeners.splice(this.extensionCount[type], 0, listener); │ │ │ │ │ - if (typeof priority === "object" && priority.extension) { │ │ │ │ │ - this.extensionCount[type]++; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - listeners.push(listener); │ │ │ │ │ - } │ │ │ │ │ + extendBounds: function(newBounds) { │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if (!bounds) { │ │ │ │ │ + this.setBounds(newBounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.bounds.extend(newBounds); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: registerPriority │ │ │ │ │ - * Same as register() but adds the new listener to the *front* of the │ │ │ │ │ - * events queue instead of to the end. │ │ │ │ │ - * │ │ │ │ │ - * TODO: get rid of this in 3.0 - Decide whether listeners should be │ │ │ │ │ - * called in the order they were registered or in reverse order. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * type - {String} Name of the event to register │ │ │ │ │ - * obj - {Object} The object to bind the context to for the callback#. │ │ │ │ │ - * If no object is specified, default is the Events's │ │ │ │ │ - * 'object' property. │ │ │ │ │ - * func - {Function} The callback function. If no callback is │ │ │ │ │ - * specified, this function does nothing. │ │ │ │ │ + * APIMethod: getBounds │ │ │ │ │ + * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ + * is calculated again, this makes queries faster. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - registerPriority: function(type, obj, func) { │ │ │ │ │ - this.register(type, obj, func, true); │ │ │ │ │ + getBounds: function() { │ │ │ │ │ + if (this.bounds == null) { │ │ │ │ │ + this.calculateBounds(); │ │ │ │ │ + } │ │ │ │ │ + return this.bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: un │ │ │ │ │ - * Convenience method for unregistering listeners with a common scope. │ │ │ │ │ - * Internally, this method calls as shown in the examples │ │ │ │ │ - * below. │ │ │ │ │ - * │ │ │ │ │ - * Example use: │ │ │ │ │ - * (code) │ │ │ │ │ - * // unregister a single listener for the "loadstart" event │ │ │ │ │ - * events.un({"loadstart": loadStartListener}); │ │ │ │ │ - * │ │ │ │ │ - * // this is equivalent to the following │ │ │ │ │ - * events.unregister("loadstart", undefined, loadStartListener); │ │ │ │ │ - * │ │ │ │ │ - * // unregister multiple listeners with the same `this` object │ │ │ │ │ - * events.un({ │ │ │ │ │ - * "loadstart": loadStartListener, │ │ │ │ │ - * "loadend": loadEndListener, │ │ │ │ │ - * scope: object │ │ │ │ │ - * }); │ │ │ │ │ - * │ │ │ │ │ - * // this is equivalent to the following │ │ │ │ │ - * events.unregister("loadstart", object, loadStartListener); │ │ │ │ │ - * events.unregister("loadend", object, loadEndListener); │ │ │ │ │ - * (end) │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds for the geometry. │ │ │ │ │ */ │ │ │ │ │ - un: function(object) { │ │ │ │ │ - for (var type in object) { │ │ │ │ │ - if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ - this.unregister(type, object.scope, object[type]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + // │ │ │ │ │ + // This should be overridden by subclasses. │ │ │ │ │ + // │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: unregister │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} │ │ │ │ │ - * obj - {Object} If none specified, defaults to this.object │ │ │ │ │ - * func - {Function} │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ + * │ │ │ │ │ + * Valid options depend on the specific geometry type. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - unregister: function(type, obj, func) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = this.object; │ │ │ │ │ - } │ │ │ │ │ - var listeners = this.listeners[type]; │ │ │ │ │ - if (listeners != null) { │ │ │ │ │ - for (var i = 0, len = listeners.length; i < len; i++) { │ │ │ │ │ - if (listeners[i].obj == obj && listeners[i].func == func) { │ │ │ │ │ - listeners.splice(i, 1); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + distanceTo: function(geometry, options) {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: remove │ │ │ │ │ - * Remove all listeners for a given event type. If type is not registered, │ │ │ │ │ - * does nothing. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - remove: function(type) { │ │ │ │ │ - if (this.listeners[type] != null) { │ │ │ │ │ - this.listeners[type] = []; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + getVertices: function(nodes) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: triggerEvent │ │ │ │ │ - * Trigger a specified registered event. │ │ │ │ │ + * Method: atPoint │ │ │ │ │ + * Note - This is only an approximation based on the bounds of the │ │ │ │ │ + * geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} │ │ │ │ │ - * evt - {Event || Object} will be passed to the listeners. │ │ │ │ │ - * │ │ │ │ │ + * 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} The last listener return. If a listener returns false, the │ │ │ │ │ - * chain of listeners will stop getting called. │ │ │ │ │ + * {Boolean} Whether or not the geometry is at the specified location │ │ │ │ │ */ │ │ │ │ │ - triggerEvent: function(type, evt) { │ │ │ │ │ - var listeners = this.listeners[type]; │ │ │ │ │ - │ │ │ │ │ - // fast path │ │ │ │ │ - if (!listeners || listeners.length == 0) { │ │ │ │ │ - return undefined; │ │ │ │ │ - } │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ │ │ │ │ │ - // prep evt object with object & div references │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - evt = {}; │ │ │ │ │ - } │ │ │ │ │ - evt.object = this.object; │ │ │ │ │ - evt.element = this.element; │ │ │ │ │ - if (!evt.type) { │ │ │ │ │ - evt.type = type; │ │ │ │ │ - } │ │ │ │ │ + var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ + var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ │ │ │ │ │ - // execute all callbacks registered for specified type │ │ │ │ │ - // get a clone of the listeners array to │ │ │ │ │ - // allow for splicing during callbacks │ │ │ │ │ - listeners = listeners.slice(); │ │ │ │ │ - var continueChain; │ │ │ │ │ - for (var i = 0, len = listeners.length; i < len; i++) { │ │ │ │ │ - var callback = listeners[i]; │ │ │ │ │ - // bind the context to callback.obj │ │ │ │ │ - continueChain = callback.func.apply(callback.obj, [evt]); │ │ │ │ │ + var toleranceBounds = │ │ │ │ │ + new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ + this.bounds.bottom - dY, │ │ │ │ │ + this.bounds.right + dX, │ │ │ │ │ + this.bounds.top + dY); │ │ │ │ │ │ │ │ │ │ - if ((continueChain != undefined) && (continueChain == false)) { │ │ │ │ │ - // if callback returns false, execute no more callbacks. │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // don't fall through to other DOM elements │ │ │ │ │ - if (!this.fallThrough) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ } │ │ │ │ │ - return continueChain; │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleBrowserEvent │ │ │ │ │ - * Basically just a wrapper to the triggerEvent() function, but takes │ │ │ │ │ - * care to set a property 'xy' on the event with the current mouse │ │ │ │ │ - * position. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: getLength │ │ │ │ │ + * Calculate the length of this geometry. This method is defined in │ │ │ │ │ + * subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The length of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - handleBrowserEvent: function(evt) { │ │ │ │ │ - var type = evt.type, │ │ │ │ │ - listeners = this.listeners[type]; │ │ │ │ │ - if (!listeners || listeners.length == 0) { │ │ │ │ │ - // noone's listening, bail out │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - // add clientX & clientY to all events - corresponds to average x, y │ │ │ │ │ - var touches = evt.touches; │ │ │ │ │ - if (touches && touches[0]) { │ │ │ │ │ - var x = 0; │ │ │ │ │ - var y = 0; │ │ │ │ │ - var num = touches.length; │ │ │ │ │ - var touch; │ │ │ │ │ - for (var i = 0; i < num; ++i) { │ │ │ │ │ - touch = this.getTouchClientXY(touches[i]); │ │ │ │ │ - x += touch.clientX; │ │ │ │ │ - y += touch.clientY; │ │ │ │ │ - } │ │ │ │ │ - evt.clientX = x / num; │ │ │ │ │ - evt.clientY = y / num; │ │ │ │ │ - } │ │ │ │ │ - if (this.includeXY) { │ │ │ │ │ - evt.xy = this.getMousePosition(evt); │ │ │ │ │ - } │ │ │ │ │ - this.triggerEvent(type, evt); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + //to be overridden by geometries that actually have a length │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTouchClientXY │ │ │ │ │ - * WebKit has a few bugs for clientX/clientY. This method detects them │ │ │ │ │ - * and calculate the correct values. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Touch} a Touch object from a TouchEvent │ │ │ │ │ + * Method: getArea │ │ │ │ │ + * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} An object with only clientX and clientY properties with the │ │ │ │ │ - * calculated values. │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - getTouchClientXY: function(evt) { │ │ │ │ │ - // olMochWin is to override window, used for testing │ │ │ │ │ - var win = window.olMockWin || window, │ │ │ │ │ - winPageX = win.pageXOffset, │ │ │ │ │ - winPageY = win.pageYOffset, │ │ │ │ │ - x = evt.clientX, │ │ │ │ │ - y = evt.clientY; │ │ │ │ │ - │ │ │ │ │ - if (evt.pageY === 0 && Math.floor(y) > Math.floor(evt.pageY) || │ │ │ │ │ - evt.pageX === 0 && Math.floor(x) > Math.floor(evt.pageX)) { │ │ │ │ │ - // iOS4 include scroll offset in clientX/Y │ │ │ │ │ - x = x - winPageX; │ │ │ │ │ - y = y - winPageY; │ │ │ │ │ - } else if (y < (evt.pageY - winPageY) || x < (evt.pageX - winPageX)) { │ │ │ │ │ - // Some Android browsers have totally bogus values for clientX/Y │ │ │ │ │ - // when scrolling/zooming a page │ │ │ │ │ - x = evt.pageX - winPageX; │ │ │ │ │ - y = evt.pageY - winPageY; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - evt.olClientX = x; │ │ │ │ │ - evt.olClientY = y; │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - clientX: x, │ │ │ │ │ - clientY: y │ │ │ │ │ - }; │ │ │ │ │ + getArea: function() { │ │ │ │ │ + //to be overridden by geometries that actually have an area │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clearMouseCache │ │ │ │ │ - * Clear cached data about the mouse position. This should be called any │ │ │ │ │ - * time the element that events are registered on changes position │ │ │ │ │ - * within the page. │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - clearMouseCache: function() { │ │ │ │ │ - this.element.scrolls = null; │ │ │ │ │ - this.element.lefttop = null; │ │ │ │ │ - this.element.offsets = null; │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMousePosition │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {} The current xy coordinate of the mouse, adjusted │ │ │ │ │ - * for offsets │ │ │ │ │ + * {String} String representation of this geometry. │ │ │ │ │ */ │ │ │ │ │ - getMousePosition: function(evt) { │ │ │ │ │ - if (!this.includeXY) { │ │ │ │ │ - this.clearMouseCache(); │ │ │ │ │ - } else if (!this.element.hasScrollEvent) { │ │ │ │ │ - OpenLayers.Event.observe(window, "scroll", this.clearMouseListener); │ │ │ │ │ - this.element.hasScrollEvent = true; │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (!this.element.scrolls) { │ │ │ │ │ - var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ - this.element.scrolls = [ │ │ │ │ │ - window.pageXOffset || viewportElement.scrollLeft, │ │ │ │ │ - window.pageYOffset || viewportElement.scrollTop │ │ │ │ │ - ]; │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - if (!this.element.lefttop) { │ │ │ │ │ - this.element.lefttop = [ │ │ │ │ │ - (document.documentElement.clientLeft || 0), │ │ │ │ │ - (document.documentElement.clientTop || 0) │ │ │ │ │ - ]; │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (!this.element.offsets) { │ │ │ │ │ - this.element.offsets = OpenLayers.Util.pagePosition(this.element); │ │ │ │ │ + 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - return new OpenLayers.Pixel( │ │ │ │ │ - (evt.clientX + this.element.scrolls[0]) - this.element.offsets[0] - │ │ │ │ │ - this.element.lefttop[0], │ │ │ │ │ - (evt.clientY + this.element.scrolls[1]) - this.element.offsets[1] - │ │ │ │ │ - this.element.lefttop[1] │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addMsTouchListener │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ - * type - {String} The event type │ │ │ │ │ - * handler - {Function} the handler │ │ │ │ │ - */ │ │ │ │ │ - addMsTouchListener: function(element, type, handler) { │ │ │ │ │ - var eventHandler = this.eventHandler; │ │ │ │ │ - var touches = this._msTouches; │ │ │ │ │ - │ │ │ │ │ - function msHandler(evt) { │ │ │ │ │ - handler(OpenLayers.Util.applyDefaults({ │ │ │ │ │ - stopPropagation: function() { │ │ │ │ │ - for (var i = touches.length - 1; i >= 0; --i) { │ │ │ │ │ - touches[i].stopPropagation(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - preventDefault: function() { │ │ │ │ │ - for (var i = touches.length - 1; i >= 0; --i) { │ │ │ │ │ - touches[i].preventDefault(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - type: type │ │ │ │ │ - }, evt)); │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - switch (type) { │ │ │ │ │ - case 'touchstart': │ │ │ │ │ - return this.addMsTouchListenerStart(element, type, msHandler); │ │ │ │ │ - case 'touchend': │ │ │ │ │ - return this.addMsTouchListenerEnd(element, type, msHandler); │ │ │ │ │ - case 'touchmove': │ │ │ │ │ - return this.addMsTouchListenerMove(element, type, msHandler); │ │ │ │ │ - default: │ │ │ │ │ - throw 'Unknown touch event type'; │ │ │ │ │ + } │ │ │ │ │ + } 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addMsTouchListenerStart │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ - * type - {String} The event type │ │ │ │ │ - * handler - {Function} the handler │ │ │ │ │ - */ │ │ │ │ │ - addMsTouchListenerStart: function(element, type, handler) { │ │ │ │ │ - var touches = this._msTouches; │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - var cb = function(e) { │ │ │ │ │ +/** │ │ │ │ │ + * 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/Feature.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var alreadyInArray = false; │ │ │ │ │ - for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ - if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ - alreadyInArray = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!alreadyInArray) { │ │ │ │ │ - touches.push(e); │ │ │ │ │ - } │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - e.touches = touches.slice(); │ │ │ │ │ - handler(e); │ │ │ │ │ - }; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.observe(element, 'MSPointerDown', cb); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // Need to also listen for end events to keep the _msTouches list │ │ │ │ │ - // accurate │ │ │ │ │ - var internalCb = function(e) { │ │ │ │ │ - for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ - if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ - touches.splice(i, 1); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Event.observe(element, 'MSPointerUp', internalCb); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Feature │ │ │ │ │ + * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ + * class specifically combines a marker and a lonlat. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addMsTouchListenerMove │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ - * type - {String} The event type │ │ │ │ │ - * handler - {Function} the handler │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - addMsTouchListenerMove: function(element, type, handler) { │ │ │ │ │ - var touches = this._msTouches; │ │ │ │ │ - var cb = function(e) { │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ - //Don't fire touch moves when mouse isn't down │ │ │ │ │ - if (e.pointerType == e.MSPOINTER_TYPE_MOUSE && e.buttons == 0) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - if (touches.length == 1 && touches[0].pageX == e.pageX && │ │ │ │ │ - touches[0].pageY == e.pageY) { │ │ │ │ │ - // don't trigger event when pointer has not moved │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ - if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ - touches[i] = e; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - e.touches = touches.slice(); │ │ │ │ │ - handler(e); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Property: data │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.observe(element, 'MSPointerMove', cb); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: marker │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + marker: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addMsTouchListenerEnd │ │ │ │ │ + * APIProperty: popupClass │ │ │ │ │ + * {} The class which will be used to instantiate │ │ │ │ │ + * a new Popup. Default is . │ │ │ │ │ + */ │ │ │ │ │ + popupClass: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: popup │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + popup: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Feature │ │ │ │ │ + * Constructor for features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ - * type - {String} The event type │ │ │ │ │ - * handler - {Function} the handler │ │ │ │ │ + * layer - {} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * data - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - addMsTouchListenerEnd: function(element, type, handler) { │ │ │ │ │ - var touches = this._msTouches; │ │ │ │ │ + initialize: function(layer, lonlat, data) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.lonlat = lonlat; │ │ │ │ │ + this.data = (data != null) ? data : {}; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var cb = function(e) { │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ │ │ │ │ │ - for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ - if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ - touches.splice(i, 1); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + //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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - e.touches = touches.slice(); │ │ │ │ │ - handler(e); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Event.observe(element, 'MSPointerUp', cb); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Events" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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. */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: onScreen │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ + * (based on its 'lonlat' property) │ │ │ │ │ + */ │ │ │ │ │ + onScreen: function() { │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ - */ │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ + var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ + } │ │ │ │ │ + return onScreen; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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 │ │ │ │ │ + * 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 │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ - var isNative = !!(requestAnimationFrame); │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + │ │ │ │ │ + if (this.lonlat != null) { │ │ │ │ │ + this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ + } │ │ │ │ │ + return this.marker; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: destroyMarker │ │ │ │ │ + * Destroys marker. │ │ │ │ │ + * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ + * to also specify an alternative function for destroying it │ │ │ │ │ */ │ │ │ │ │ - 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 = {}; │ │ │ │ │ + destroyMarker: function() { │ │ │ │ │ + this.marker.destroy(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: createPopup │ │ │ │ │ + * Creates a popup object created from the 'lonlat', 'popupSize', │ │ │ │ │ + * and 'popupContentHTML' properties set in this.data. It uses │ │ │ │ │ + * this.marker.icon as default anchor. │ │ │ │ │ + * │ │ │ │ │ + * If no 'lonlat' is set, returns null. │ │ │ │ │ + * If no this.marker has been created, no anchor is sent. │ │ │ │ │ * │ │ │ │ │ + * Note - the returned popup object is 'owned' by the feature, so you │ │ │ │ │ + * cannot use the popup's destroy method to discard the popup. │ │ │ │ │ + * Instead, you must use the feature's destroyPopup │ │ │ │ │ + * │ │ │ │ │ + * Note - this.popup is set to return value │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * closeBox - {Boolean} create popup with closebox or not │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Number} Identifier for the animation loop. Used to stop animations with │ │ │ │ │ - * . │ │ │ │ │ + * {} 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 . │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - 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]; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - requestFrame(loops[id], element); │ │ │ │ │ - return id; │ │ │ │ │ - } │ │ │ │ │ + if (this.data.overflow != null) { │ │ │ │ │ + this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.popup.feature = this; │ │ │ │ │ + } │ │ │ │ │ + return this.popup; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: stop │ │ │ │ │ - * Terminates an animation loop started with . │ │ │ │ │ + * Method: destroyPopup │ │ │ │ │ + * Destroys the popup created via createPopup. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {Number} Identifier returned from . │ │ │ │ │ + * As with the marker, if user overrides the createPopup() function, s/he │ │ │ │ │ + * should also be able to override the destruction │ │ │ │ │ */ │ │ │ │ │ - function stop(id) { │ │ │ │ │ - delete loops[id]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - isNative: isNative, │ │ │ │ │ - requestFrame: requestFrame, │ │ │ │ │ - start: start, │ │ │ │ │ - stop: stop │ │ │ │ │ - }; │ │ │ │ │ + destroyPopup: function() { │ │ │ │ │ + if (this.popup) { │ │ │ │ │ + this.popup.feature = null; │ │ │ │ │ + this.popup.destroy(); │ │ │ │ │ + this.popup = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -})(window); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Tween.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/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ + * @requires OpenLayers/Feature.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Namespace: OpenLayers.Tween │ │ │ │ │ + * 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.Tween = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: easing │ │ │ │ │ - * {(Function)} Easing equation used for the animation │ │ │ │ │ - * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ - */ │ │ │ │ │ - easing: null, │ │ │ │ │ +OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: begin │ │ │ │ │ - * {Object} Values to start the animation with │ │ │ │ │ + /** │ │ │ │ │ + * Property: fid │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - begin: null, │ │ │ │ │ + fid: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: finish │ │ │ │ │ - * {Object} Values to finish the animation with │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geometry │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - finish: null, │ │ │ │ │ + geometry: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: duration │ │ │ │ │ - * {int} duration of the tween (number of steps) │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: attributes │ │ │ │ │ + * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ + * describe the feature. │ │ │ │ │ */ │ │ │ │ │ - duration: null, │ │ │ │ │ + attributes: 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: time │ │ │ │ │ - * {int} Step counter │ │ │ │ │ + /** │ │ │ │ │ + * Property: state │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - time: null, │ │ │ │ │ + state: 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. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: style │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - minFrameRate: null, │ │ │ │ │ + style: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startTime │ │ │ │ │ - * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ - * frames │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} If this property is set it will be taken into account by │ │ │ │ │ + * {} when upadting or deleting the feature. │ │ │ │ │ */ │ │ │ │ │ - startTime: null, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: animationId │ │ │ │ │ - * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ + * Property: renderIntent │ │ │ │ │ + * {String} rendering intent currently being used │ │ │ │ │ */ │ │ │ │ │ - animationId: null, │ │ │ │ │ + renderIntent: "default", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: playing │ │ │ │ │ - * {Boolean} Tells if the easing is currently playing │ │ │ │ │ - */ │ │ │ │ │ - playing: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tween │ │ │ │ │ - * Creates a Tween. │ │ │ │ │ + * 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: │ │ │ │ │ - * easing - {(Function)} easing function method to use │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * geometry: >Object │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * When an application has made changes to feature attributes, it could │ │ │ │ │ + * have set the attributes to something like this: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * { │ │ │ │ │ + * attributes: { │ │ │ │ │ + * myAttribute: "original" │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Note that only checks for truthy values in │ │ │ │ │ + * *modified.geometry* and the attribute names in *modified.attributes*, │ │ │ │ │ + * but it is recommended to set the original values (and not just true) as │ │ │ │ │ + * attribute value, so applications could use this information to undo │ │ │ │ │ + * changes. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(easing) { │ │ │ │ │ - this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ - }, │ │ │ │ │ + modified: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: start │ │ │ │ │ - * Plays the Tween, and calls the callback method on each step │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Feature.Vector │ │ │ │ │ + * Create a vector feature. │ │ │ │ │ * │ │ │ │ │ * 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) │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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.animationId = OpenLayers.Animation.start( │ │ │ │ │ - OpenLayers.Function.bind(this.play, this) │ │ │ │ │ - ); │ │ │ │ │ + this.style = style ? style : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: stop │ │ │ │ │ - * Stops the Tween, and calls the done callback │ │ │ │ │ - * Doesn't do anything if animation is already finished │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - stop: function() { │ │ │ │ │ - if (!this.playing) { │ │ │ │ │ - return; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layer) { │ │ │ │ │ + this.layer.removeFeatures(this); │ │ │ │ │ + this.layer = null; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.callbacks && this.callbacks.done) { │ │ │ │ │ - this.callbacks.done.call(this, this.finish); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - this.playing = false; │ │ │ │ │ + this.geometry = null; │ │ │ │ │ + this.modified = null; │ │ │ │ │ + OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: play │ │ │ │ │ - * Calls the appropriate easing method │ │ │ │ │ + * Method: clone │ │ │ │ │ + * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ + * properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this vector feature. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Feature.Vector( │ │ │ │ │ + this.geometry ? this.geometry.clone() : null, │ │ │ │ │ + this.attributes, │ │ │ │ │ + this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: onScreen │ │ │ │ │ + * Determine whether the feature is within the map viewport. This method │ │ │ │ │ + * tests for an intersection between the geometry and the viewport │ │ │ │ │ + * bounds. If a more effecient but less precise geometry bounds │ │ │ │ │ + * intersection is desired, call the method with the boundsOnly │ │ │ │ │ + * parameter true. │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * boundsOnly - {Boolean} Only test whether a feature's bounds intersects │ │ │ │ │ + * the viewport bounds. Default is false. If false, the feature's │ │ │ │ │ + * geometry must intersect the viewport for onScreen to return true. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ + * based on its bounds if boundsOnly is true). │ │ │ │ │ */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {Boolean} The feature is currently displayed. │ │ │ │ │ */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + 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()); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create markers │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Expo = { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ + * Method: destroyMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * delete markers │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ + * to also specify an alternative function for destroying it │ │ │ │ │ */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ + destroyMarker: function() { │ │ │ │ │ + // pass │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ + * Method: createPopup │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create popups │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ + createPopup: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + if (this.geometry) { │ │ │ │ │ + atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ + toleranceLat); │ │ │ │ │ + } │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - 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} │ │ │ │ │ + * Method: destroyPopup │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * delete popups │ │ │ │ │ */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * (t /= d) * t + b; │ │ │ │ │ + destroyPopup: function() { │ │ │ │ │ + // pass │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * Method: move │ │ │ │ │ + * Moves the feature and redraws it at its new location │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * location - { or } the │ │ │ │ │ + * location to which to move the feature. │ │ │ │ │ */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ + * Method: toState │ │ │ │ │ + * Sets the new state │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {String} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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.Easing.Quad" │ │ │ │ │ + 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/Projection.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 │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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.Projection = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: proj │ │ │ │ │ - * {Object} Proj4js.Proj instance. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} A reference to options passed to the constructor. │ │ │ │ │ */ │ │ │ │ │ - proj: null, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: projCode │ │ │ │ │ - * {String} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - projCode: null, │ │ │ │ │ + externalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: titleRegEx │ │ │ │ │ - * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ + internalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Projection │ │ │ │ │ - * This class offers several methods for interacting with a wrapped │ │ │ │ │ - * pro4js projection object. │ │ │ │ │ + * APIProperty: data │ │ │ │ │ + * {Object} When is true, this is the parsed string sent to │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + data: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: keepData │ │ │ │ │ + * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + keepData: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * {} A projection object. │ │ │ │ │ + * An instance of OpenLayers.Format │ │ │ │ │ */ │ │ │ │ │ - initialize: function(projCode, options) { │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.projCode = projCode; │ │ │ │ │ - if (typeof Proj4js == "object") { │ │ │ │ │ - this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ - } │ │ │ │ │ + this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCode │ │ │ │ │ - * Get the string SRS code. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: read │ │ │ │ │ + * Read data from a string, and return an object whose type depends on the │ │ │ │ │ + * subclass. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {string} Data to read/parse. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The SRS code. │ │ │ │ │ + * Depends on the subclass │ │ │ │ │ */ │ │ │ │ │ - getCode: function() { │ │ │ │ │ - return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ + read: function(data) { │ │ │ │ │ + throw new Error('Read not implemented.'); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getUnits │ │ │ │ │ - * Get the units string for the projection -- returns null if │ │ │ │ │ - * proj4js is not available. │ │ │ │ │ + * Method: write │ │ │ │ │ + * Accept an object, and return a string. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} Object to be serialized │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The units abbreviation. │ │ │ │ │ + * {String} A string representation of the object. │ │ │ │ │ */ │ │ │ │ │ - getUnits: function() { │ │ │ │ │ - return this.proj ? this.proj.units : null; │ │ │ │ │ + write: function(object) { │ │ │ │ │ + throw new Error('Write not implemented.'); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Point.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Point │ │ │ │ │ + * Point geometry class. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: x │ │ │ │ │ + * {float} │ │ │ │ │ + */ │ │ │ │ │ + x: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: y │ │ │ │ │ + * {float} │ │ │ │ │ + */ │ │ │ │ │ + y: null, │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: toString │ │ │ │ │ - * Convert projection to string (getCode wrapper). │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ + * Construct a point geometry. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The projection code. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {float} │ │ │ │ │ + * y - {float} │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - return this.getCode(); │ │ │ │ │ + initialize: function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + this.x = parseFloat(x); │ │ │ │ │ + this.y = parseFloat(y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: equals │ │ │ │ │ - * Test equality of two projection instances. Determines equality based │ │ │ │ │ - * soley on the projection code. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The two projections are equivalent. │ │ │ │ │ + * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ } │ │ │ │ │ - return equals; │ │ │ │ │ + │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ + │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /* Method: destroy │ │ │ │ │ - * Destroy projection object. │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * Create a new Bounds based on the lon/lat │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - delete this.proj; │ │ │ │ │ - delete this.projCode; │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ + this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Projection" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Property: transforms │ │ │ │ │ - * {Object} Transforms is an object, with from properties, each of which may │ │ │ │ │ - * have a to property. This allows you to define projections without │ │ │ │ │ - * requiring support for proj4js to be included. │ │ │ │ │ - * │ │ │ │ │ - * This object has keys which correspond to a 'source' projection object. The │ │ │ │ │ - * keys should be strings, corresponding to the projection.getCode() value. │ │ │ │ │ - * Each source projection object should have a set of destination projection │ │ │ │ │ - * keys included in the object. │ │ │ │ │ - * │ │ │ │ │ - * Each value in the destination object should be a transformation function, │ │ │ │ │ - * where the function is expected to be passed an object with a .x and a .y │ │ │ │ │ - * property. The function should return the object, with the .x and .y │ │ │ │ │ - * transformed according to the transformation function. │ │ │ │ │ - * │ │ │ │ │ - * Note - Properties on this object should not be set directly. To add a │ │ │ │ │ - * transform method to this object, use the method. For an │ │ │ │ │ - * example of usage, see the OpenLayers.Layer.SphericalMercator file. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.transforms = {}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIProperty: defaults │ │ │ │ │ - * {Object} Defaults for the SRS codes known to OpenLayers (currently │ │ │ │ │ - * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, │ │ │ │ │ - * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units, │ │ │ │ │ - * maxExtent (the validity extent for the SRS) and yx (true if this SRS is │ │ │ │ │ - * known to have a reverse axis order). │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.defaults = { │ │ │ │ │ - "EPSG:4326": { │ │ │ │ │ - units: "degrees", │ │ │ │ │ - maxExtent: [-180, -90, 180, 90], │ │ │ │ │ - yx: true │ │ │ │ │ - }, │ │ │ │ │ - "CRS:84": { │ │ │ │ │ - units: "degrees", │ │ │ │ │ - maxExtent: [-180, -90, 180, 90] │ │ │ │ │ - }, │ │ │ │ │ - "EPSG:900913": { │ │ │ │ │ - units: "m", │ │ │ │ │ - maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34] │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIMethod: addTransform │ │ │ │ │ - * Set a custom transform method between two projections. Use this method in │ │ │ │ │ - * cases where the proj4js lib is not available or where custom projections │ │ │ │ │ - * need to be handled. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * from - {String} The code for the source projection │ │ │ │ │ - * to - {String} the code for the destination projection │ │ │ │ │ - * method - {Function} A function that takes a point as an argument and │ │ │ │ │ - * transforms that point from the source to the destination projection │ │ │ │ │ - * in place. The original point should be modified. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.addTransform = function(from, to, method) { │ │ │ │ │ - if (method === OpenLayers.Projection.nullTransform) { │ │ │ │ │ - var defaults = OpenLayers.Projection.defaults[from]; │ │ │ │ │ - if (defaults && !OpenLayers.Projection.defaults[to]) { │ │ │ │ │ - OpenLayers.Projection.defaults[to] = defaults; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!OpenLayers.Projection.transforms[from]) { │ │ │ │ │ - OpenLayers.Projection.transforms[from] = {}; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Projection.transforms[from][to] = method; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Transform a point coordinate from one projection to another. Note that │ │ │ │ │ - * the input point is transformed in place. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - { | Object} An object with x and y │ │ │ │ │ - * properties representing coordinates in those dimensions. │ │ │ │ │ - * source - {OpenLayers.Projection} Source map coordinate system │ │ │ │ │ - * dest - {OpenLayers.Projection} Destination map coordinate system │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * point - {object} A transformed coordinate. The original point is modified. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.transform = function(point, source, dest) { │ │ │ │ │ - if (source && dest) { │ │ │ │ │ - if (!(source instanceof OpenLayers.Projection)) { │ │ │ │ │ - source = new OpenLayers.Projection(source); │ │ │ │ │ - } │ │ │ │ │ - if (!(dest instanceof OpenLayers.Projection)) { │ │ │ │ │ - dest = new OpenLayers.Projection(dest); │ │ │ │ │ - } │ │ │ │ │ - if (source.proj && dest.proj) { │ │ │ │ │ - point = Proj4js.transform(source.proj, dest.proj, point); │ │ │ │ │ - } else { │ │ │ │ │ - var sourceCode = source.getCode(); │ │ │ │ │ - var destCode = dest.getCode(); │ │ │ │ │ - var transforms = OpenLayers.Projection.transforms; │ │ │ │ │ - if (transforms[sourceCode] && transforms[sourceCode][destCode]) { │ │ │ │ │ - transforms[sourceCode][destCode](point); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return point; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: nullTransform │ │ │ │ │ - * A null transformation - useful for defining projection aliases when │ │ │ │ │ - * proj4js is not available: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913", │ │ │ │ │ - * OpenLayers.Projection.nullTransform); │ │ │ │ │ - * OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857", │ │ │ │ │ - * OpenLayers.Projection.nullTransform); │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection.nullTransform = function(point) { │ │ │ │ │ - return point; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Note: Transforms for web mercator <-> geographic │ │ │ │ │ - * OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100. │ │ │ │ │ - * OpenLayers originally started referring to EPSG:900913 as web mercator. │ │ │ │ │ - * The EPSG has declared EPSG:3857 to be web mercator. │ │ │ │ │ - * ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as │ │ │ │ │ - * equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084. │ │ │ │ │ - * For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and │ │ │ │ │ - * urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis │ │ │ │ │ - * order for EPSG:4326. │ │ │ │ │ - */ │ │ │ │ │ -(function() { │ │ │ │ │ - │ │ │ │ │ - var pole = 20037508.34; │ │ │ │ │ - │ │ │ │ │ - function inverseMercator(xy) { │ │ │ │ │ - xy.x = 180 * xy.x / pole; │ │ │ │ │ - xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2); │ │ │ │ │ - return xy; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - function forwardMercator(xy) { │ │ │ │ │ - xy.x = xy.x * pole / 180; │ │ │ │ │ - var y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole; │ │ │ │ │ - xy.y = Math.max(-20037508.34, Math.min(y, 20037508.34)); │ │ │ │ │ - return xy; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - function map(base, codes) { │ │ │ │ │ - var add = OpenLayers.Projection.addTransform; │ │ │ │ │ - var same = OpenLayers.Projection.nullTransform; │ │ │ │ │ - var i, len, code, other, j; │ │ │ │ │ - for (i = 0, len = codes.length; i < len; ++i) { │ │ │ │ │ - code = codes[i]; │ │ │ │ │ - add(base, code, forwardMercator); │ │ │ │ │ - add(code, base, inverseMercator); │ │ │ │ │ - for (j = i + 1; j < len; ++j) { │ │ │ │ │ - other = codes[j]; │ │ │ │ │ - add(code, other, same); │ │ │ │ │ - add(other, code, same); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // list of equivalent codes for web mercator │ │ │ │ │ - var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"], │ │ │ │ │ - geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"], │ │ │ │ │ - i; │ │ │ │ │ - for (i = mercator.length - 1; i >= 0; --i) { │ │ │ │ │ - map(mercator[i], geographic); │ │ │ │ │ - } │ │ │ │ │ - for (i = geographic.length - 1; i >= 0; --i) { │ │ │ │ │ - map(geographic[i], mercator); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ -})(); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Map.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Tween.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Map │ │ │ │ │ - * Instances of OpenLayers.Map are interactive maps embedded in a web page. │ │ │ │ │ - * Create a new map with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * On their own maps do not provide much functionality. To extend a map │ │ │ │ │ - * it's necessary to add controls () and │ │ │ │ │ - * layers () to the map. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Map = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: Z_INDEX_BASE │ │ │ │ │ - * {Object} Base z-indexes for different classes of thing │ │ │ │ │ - */ │ │ │ │ │ - Z_INDEX_BASE: { │ │ │ │ │ - BaseLayer: 100, │ │ │ │ │ - Overlay: 325, │ │ │ │ │ - Feature: 725, │ │ │ │ │ - Popup: 750, │ │ │ │ │ - Control: 1000 │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * map.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to map.events.object. │ │ │ │ │ - * element - {DOMElement} A reference to map.events.element. │ │ │ │ │ - * │ │ │ │ │ - * Browser events have the following additional properties: │ │ │ │ │ - * xy - {} The pixel location of the event (relative │ │ │ │ │ - * to the the map viewport). │ │ │ │ │ - * │ │ │ │ │ - * Supported map event types: │ │ │ │ │ - * preaddlayer - triggered before a layer has been added. The event │ │ │ │ │ - * object will include a *layer* property that references the layer │ │ │ │ │ - * to be added. When a listener returns "false" the adding will be │ │ │ │ │ - * aborted. │ │ │ │ │ - * addlayer - triggered after a layer has been added. The event object │ │ │ │ │ - * will include a *layer* property that references the added layer. │ │ │ │ │ - * preremovelayer - triggered before a layer has been removed. The event │ │ │ │ │ - * object will include a *layer* property that references the layer │ │ │ │ │ - * to be removed. When a listener returns "false" the removal will be │ │ │ │ │ - * aborted. │ │ │ │ │ - * removelayer - triggered after a layer has been removed. The event │ │ │ │ │ - * object will include a *layer* property that references the removed │ │ │ │ │ - * layer. │ │ │ │ │ - * changelayer - triggered after a layer name change, order change, │ │ │ │ │ - * opacity change, params change, visibility change (actual visibility, │ │ │ │ │ - * not the layer's visibility property) or attribution change (due to │ │ │ │ │ - * extent change). Listeners will receive an event object with *layer* │ │ │ │ │ - * and *property* properties. The *layer* property will be a reference │ │ │ │ │ - * to the changed layer. The *property* property will be a key to the │ │ │ │ │ - * changed property (name, order, opacity, params, visibility or │ │ │ │ │ - * attribution). │ │ │ │ │ - * movestart - triggered after the start of a drag, pan, or zoom. The event │ │ │ │ │ - * object may include a *zoomChanged* property that tells whether the │ │ │ │ │ - * zoom has changed. │ │ │ │ │ - * move - triggered after each drag, pan, or zoom │ │ │ │ │ - * moveend - triggered after a drag, pan, or zoom completes │ │ │ │ │ - * zoomend - triggered after a zoom completes │ │ │ │ │ - * mouseover - triggered after mouseover the map │ │ │ │ │ - * mouseout - triggered after mouseout the map │ │ │ │ │ - * mousemove - triggered after mousemove the map │ │ │ │ │ - * changebaselayer - triggered after the base layer changes │ │ │ │ │ - * updatesize - triggered after the method was executed │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} Unique identifier for the map │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: fractionalZoom │ │ │ │ │ - * {Boolean} For a base layer that supports it, allow the map resolution │ │ │ │ │ - * to be set to a value between one of the values in the resolutions │ │ │ │ │ - * array. Default is false. │ │ │ │ │ - * │ │ │ │ │ - * When fractionalZoom is set to true, it is possible to zoom to │ │ │ │ │ - * an arbitrary extent. This requires a base layer from a source │ │ │ │ │ - * that supports requests for arbitrary extents (i.e. not cached │ │ │ │ │ - * tiles on a regular lattice). This means that fractionalZoom │ │ │ │ │ - * will not work with commercial layers (Google, Yahoo, VE), layers │ │ │ │ │ - * using TileCache, or any other pre-cached data sources. │ │ │ │ │ - * │ │ │ │ │ - * If you are using fractionalZoom, then you should also use │ │ │ │ │ - * instead of layer.resolutions[zoom] as the │ │ │ │ │ - * former works for non-integer zoom levels. │ │ │ │ │ - */ │ │ │ │ │ - fractionalZoom: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the map │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: allOverlays │ │ │ │ │ - * {Boolean} Allow the map to function with "overlays" only. Defaults to │ │ │ │ │ - * false. If true, the lowest layer in the draw order will act as │ │ │ │ │ - * the base layer. In addition, if set to true, all layers will │ │ │ │ │ - * have isBaseLayer set to false when they are added to the map. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you set map.allOverlays to true, then you *cannot* use │ │ │ │ │ - * map.setBaseLayer or layer.setIsBaseLayer. With allOverlays true, │ │ │ │ │ - * the lowest layer in the draw layer is the base layer. So, to change │ │ │ │ │ - * the base layer, use or to set the layer │ │ │ │ │ - * index to 0. │ │ │ │ │ - */ │ │ │ │ │ - allOverlays: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement|String} The element that contains the map (or an id for │ │ │ │ │ - * that element). If the constructor is called │ │ │ │ │ - * with two arguments, this should be provided as the first argument. │ │ │ │ │ - * Alternatively, the map constructor can be called with the options │ │ │ │ │ - * object as the only argument. In this case (one argument), a │ │ │ │ │ - * div property may or may not be provided. If the div property │ │ │ │ │ - * is not provided, the map can be rendered to a container later │ │ │ │ │ - * using the method. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you are calling after map construction, do not use │ │ │ │ │ - * auto. Instead, divide your by your │ │ │ │ │ - * maximum expected dimension. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} The map is currently being dragged. │ │ │ │ │ - */ │ │ │ │ │ - dragging: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} Size of the main div (this.div) │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: viewPortDiv │ │ │ │ │ - * {HTMLDivElement} The element that represents the map viewport │ │ │ │ │ - */ │ │ │ │ │ - viewPortDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerOrigin │ │ │ │ │ - * {} The lonlat at which the later container was │ │ │ │ │ - * re-initialized (on-zoom) │ │ │ │ │ - */ │ │ │ │ │ - layerContainerOrigin: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerDiv │ │ │ │ │ - * {HTMLDivElement} The element that contains the layers. │ │ │ │ │ - */ │ │ │ │ │ - layerContainerDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} Ordered list of layers in the map │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: controls │ │ │ │ │ - * {Array()} List of controls associated with the map. │ │ │ │ │ - * │ │ │ │ │ - * If not provided in the map options at construction, the map will │ │ │ │ │ - * by default be given the following controls if present in the build: │ │ │ │ │ - * - or │ │ │ │ │ - * - or │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ - controls: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: popups │ │ │ │ │ - * {Array()} List of popups associated with the map │ │ │ │ │ - */ │ │ │ │ │ - popups: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: baseLayer │ │ │ │ │ - * {} The currently selected base layer. This determines │ │ │ │ │ - * min/max zoom level, projection, etc. │ │ │ │ │ - */ │ │ │ │ │ - baseLayer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: center │ │ │ │ │ - * {} The current center of the map │ │ │ │ │ - */ │ │ │ │ │ - center: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The resolution of the map. │ │ │ │ │ - */ │ │ │ │ │ - resolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoom │ │ │ │ │ - * {Integer} The current zoom level of the map │ │ │ │ │ - */ │ │ │ │ │ - zoom: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panRatio │ │ │ │ │ - * {Float} The ratio of the current extent within │ │ │ │ │ - * which panning will tween. │ │ │ │ │ - */ │ │ │ │ │ - panRatio: 1.5, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: options │ │ │ │ │ - * {Object} The options object passed to the class constructor. Read-only. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - // Options │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileSize │ │ │ │ │ - * {} Set in the map options to override the default tile │ │ │ │ │ - * size for this map. │ │ │ │ │ - */ │ │ │ │ │ - tileSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: projection │ │ │ │ │ - * {String} Set in the map options to specify the default projection │ │ │ │ │ - * for layers added to this map. When using a projection other than EPSG:4326 │ │ │ │ │ - * (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), │ │ │ │ │ - * also set maxExtent, maxResolution or resolutions. Default is "EPSG:4326". │ │ │ │ │ - * Note that the projection of the map is usually determined │ │ │ │ │ - * by that of the current baseLayer (see and ). │ │ │ │ │ - */ │ │ │ │ │ - projection: "EPSG:4326", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: units │ │ │ │ │ - * {String} The map units. Possible values are 'degrees' (or 'dd'), 'm', │ │ │ │ │ - * 'ft', 'km', 'mi', 'inches'. Normally taken from the projection. │ │ │ │ │ - * Only required if both map and layers do not define a projection, │ │ │ │ │ - * or if they define a projection which does not define units │ │ │ │ │ - */ │ │ │ │ │ - units: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: resolutions │ │ │ │ │ - * {Array(Float)} A list of map resolutions (map units per pixel) in │ │ │ │ │ - * descending order. If this is not set in the layer constructor, it │ │ │ │ │ - * will be set based on other resolution related properties │ │ │ │ │ - * (maxExtent, maxResolution, maxScale, etc.). │ │ │ │ │ - */ │ │ │ │ │ - resolutions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxResolution │ │ │ │ │ - * {Float} Required if you are not displaying the whole world on a tile │ │ │ │ │ - * with the size specified in . │ │ │ │ │ - */ │ │ │ │ │ - maxResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minScale: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The maximum extent for the map. │ │ │ │ │ - * Default depends on projection; if this is one of those defined in OpenLayers.Projection.defaults │ │ │ │ │ - * (EPSG:4326 or web mercator), maxExtent will be set to the value defined there; │ │ │ │ │ - * else, defaults to null. │ │ │ │ │ - * To restrict user panning and zooming of the map, use instead. │ │ │ │ │ - * The value for will change calculations for tile URLs. │ │ │ │ │ - */ │ │ │ │ │ - maxExtent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The minimum extent for the map. Defaults to null. │ │ │ │ │ - */ │ │ │ │ │ - minExtent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: restrictedExtent │ │ │ │ │ - * {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * Limit map navigation to this extent where possible. │ │ │ │ │ - * If a non-null restrictedExtent is set, panning will be restricted │ │ │ │ │ - * to the given bounds. In addition, zooming to a resolution that │ │ │ │ │ - * displays more than the restricted extent will center the map │ │ │ │ │ - * on the restricted extent. If you wish to limit the zoom level │ │ │ │ │ - * or resolution, use maxResolution. │ │ │ │ │ - */ │ │ │ │ │ - restrictedExtent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} Number of zoom levels for the map. Defaults to 16. Set a │ │ │ │ │ - * different value in the map options if needed. │ │ │ │ │ - */ │ │ │ │ │ - numZoomLevels: 16, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: theme │ │ │ │ │ - * {String} Relative path to a CSS file from which to load theme styles. │ │ │ │ │ - * Specify null in the map options (e.g. {theme: null}) if you │ │ │ │ │ - * want to get cascading style declarations - by putting links to │ │ │ │ │ - * stylesheets or style declarations directly in your page. │ │ │ │ │ - */ │ │ │ │ │ - theme: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} Requires proj4js support for projections other │ │ │ │ │ - * than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by │ │ │ │ │ - * several controls to display data to user. If this property is set, │ │ │ │ │ - * it will be set on any control which has a null displayProjection │ │ │ │ │ - * property at the time the control is added to the map. │ │ │ │ │ - */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileManager │ │ │ │ │ - * {|Object} By default, and if the build contains │ │ │ │ │ - * TileManager.js, the map will use the TileManager to queue image requests │ │ │ │ │ - * and to cache tile image elements. To create a map without a TileManager │ │ │ │ │ - * configure the map with tileManager: null. To create a TileManager with │ │ │ │ │ - * non-default options, supply the options instead or alternatively supply │ │ │ │ │ - * an instance of {}. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: fallThrough │ │ │ │ │ - * {Boolean} Should OpenLayers allow events on the map to fall through to │ │ │ │ │ - * other elements on the page, or should it swallow them? (#457) │ │ │ │ │ - * Default is to swallow. │ │ │ │ │ - */ │ │ │ │ │ - fallThrough: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoUpdateSize │ │ │ │ │ - * {Boolean} Should OpenLayers automatically update the size of the map │ │ │ │ │ - * when the resize event is fired. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - autoUpdateSize: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panTween │ │ │ │ │ - * {} Animated panning tween object, see panTo() │ │ │ │ │ - */ │ │ │ │ │ - panTween: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: panMethod │ │ │ │ │ - * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ - * OpenLayers.Easing.Expo.easeOut. Setting this to 'null' turns off │ │ │ │ │ - * animated panning. │ │ │ │ │ - */ │ │ │ │ │ - panMethod: OpenLayers.Easing.Expo.easeOut, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: panDuration │ │ │ │ │ - * {Integer} The number of steps to be passed to the │ │ │ │ │ - * OpenLayers.Tween.start() method when the map is │ │ │ │ │ - * panned. │ │ │ │ │ - * Default is 50. │ │ │ │ │ - */ │ │ │ │ │ - panDuration: 50, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomTween │ │ │ │ │ - * {} Animated zooming tween object, see zoomTo() │ │ │ │ │ - */ │ │ │ │ │ - zoomTween: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomMethod │ │ │ │ │ - * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ - * OpenLayers.Easing.Quad.easeOut. Setting this to 'null' turns off │ │ │ │ │ - * animated zooming. │ │ │ │ │ - */ │ │ │ │ │ - zoomMethod: OpenLayers.Easing.Quad.easeOut, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomDuration │ │ │ │ │ - * {Integer} The number of steps to be passed to the │ │ │ │ │ - * OpenLayers.Tween.start() method when the map is zoomed. │ │ │ │ │ - * Default is 20. │ │ │ │ │ - */ │ │ │ │ │ - zoomDuration: 20, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: paddingForPopups │ │ │ │ │ - * {} Outside margin of the popup. Used to prevent │ │ │ │ │ - * the popup from getting too close to the map border. │ │ │ │ │ - */ │ │ │ │ │ - paddingForPopups: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerContainerOriginPx │ │ │ │ │ - * {Object} Cached object representing the layer container origin (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - layerContainerOriginPx: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: minPx │ │ │ │ │ - * {Object} An object with a 'x' and 'y' values that is the lower │ │ │ │ │ - * left of maxExtent in viewport pixel space. │ │ │ │ │ - * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ - * is valid. It is also used in the getLonLatFromViewPortPx function │ │ │ │ │ - * of Layer. │ │ │ │ │ - */ │ │ │ │ │ - minPx: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: maxPx │ │ │ │ │ - * {Object} An object with a 'x' and 'y' values that is the top │ │ │ │ │ - * right of maxExtent in viewport pixel space. │ │ │ │ │ - * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ - * is valid. │ │ │ │ │ - */ │ │ │ │ │ - maxPx: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Map │ │ │ │ │ - * Constructor for a new OpenLayers.Map instance. There are two possible │ │ │ │ │ - * ways to call the map constructor. See the examples below. │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * div - {DOMElement|String} The element or id of an element in your page │ │ │ │ │ - * that will contain the map. May be omitted if the
option is │ │ │ │ │ - * provided or if you intend to call the method later. │ │ │ │ │ - * options - {Object} Optional object with properties to tag onto the map. │ │ │ │ │ - * │ │ │ │ │ - * Valid options (in addition to the listed API properties): │ │ │ │ │ - * center - {|Array} The default initial center of the map. │ │ │ │ │ - * If provided as array, the first value is the x coordinate, │ │ │ │ │ - * and the 2nd value is the y coordinate. │ │ │ │ │ - * Only specify if is provided. │ │ │ │ │ - * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ - * and the querystring contains coordinates, center will be set │ │ │ │ │ - * by that, and this option will be ignored. │ │ │ │ │ - * zoom - {Number} The initial zoom level for the map. Only specify if │ │ │ │ │ - * is provided. │ │ │ │ │ - * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ - * and the querystring contains a zoom level, zoom will be set │ │ │ │ │ - * by that, and this option will be ignored. │ │ │ │ │ - * extent - {|Array} The initial extent of the map. │ │ │ │ │ - * If provided as an array, the array should consist of │ │ │ │ │ - * four values (left, bottom, right, top). │ │ │ │ │ - * Only specify if
and are not provided. │ │ │ │ │ - * │ │ │ │ │ - * Examples: │ │ │ │ │ - * (code) │ │ │ │ │ - * // create a map with default options in an element with the id "map1" │ │ │ │ │ - * var map = new OpenLayers.Map("map1"); │ │ │ │ │ - * │ │ │ │ │ - * // create a map with non-default options in an element with id "map2" │ │ │ │ │ - * var options = { │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000), │ │ │ │ │ - * center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095) │ │ │ │ │ - * }; │ │ │ │ │ - * var map = new OpenLayers.Map("map2", options); │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ * │ │ │ │ │ - * // map with non-default options - same as above but with a single argument, │ │ │ │ │ - * // a restricted extent, and using arrays for bounds and center │ │ │ │ │ - * var map = new OpenLayers.Map({ │ │ │ │ │ - * div: "map_id", │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146], │ │ │ │ │ - * restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962], │ │ │ │ │ - * center: [-12356463.476333, 5621521.4854095] │ │ │ │ │ - * }); │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ * │ │ │ │ │ - * // create a map without a reference to a container - call render later │ │ │ │ │ - * var map = new OpenLayers.Map({ │ │ │ │ │ - * projection: "EPSG:3857", │ │ │ │ │ - * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000) │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(div, options) { │ │ │ │ │ - │ │ │ │ │ - // If only one argument is provided, check if it is an object. │ │ │ │ │ - if (arguments.length === 1 && typeof div === "object") { │ │ │ │ │ - options = div; │ │ │ │ │ - div = options && options.div; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // Simple-type defaults are set in class definition. │ │ │ │ │ - // Now set complex-type defaults │ │ │ │ │ - this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH, │ │ │ │ │ - OpenLayers.Map.TILE_HEIGHT); │ │ │ │ │ - │ │ │ │ │ - this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15); │ │ │ │ │ - │ │ │ │ │ - this.theme = OpenLayers._getScriptLocation() + │ │ │ │ │ - 'theme/default/style.css'; │ │ │ │ │ - │ │ │ │ │ - // backup original options │ │ │ │ │ - this.options = OpenLayers.Util.extend({}, options); │ │ │ │ │ - │ │ │ │ │ - // now override default options │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - │ │ │ │ │ - var projCode = this.projection instanceof OpenLayers.Projection ? │ │ │ │ │ - this.projection.projCode : this.projection; │ │ │ │ │ - OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]); │ │ │ │ │ - │ │ │ │ │ - // allow extents and center to be arrays │ │ │ │ │ - if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.maxExtent = new OpenLayers.Bounds(this.maxExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.minExtent && !(this.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.minExtent = new OpenLayers.Bounds(this.minExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.restrictedExtent && !(this.restrictedExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - this.restrictedExtent = new OpenLayers.Bounds(this.restrictedExtent); │ │ │ │ │ - } │ │ │ │ │ - if (this.center && !(this.center instanceof OpenLayers.LonLat)) { │ │ │ │ │ - this.center = new OpenLayers.LonLat(this.center); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // initialize layers array │ │ │ │ │ - this.layers = []; │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID("OpenLayers.Map_"); │ │ │ │ │ - │ │ │ │ │ - this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ - if (!this.div) { │ │ │ │ │ - this.div = document.createElement("div"); │ │ │ │ │ - this.div.style.height = "1px"; │ │ │ │ │ - this.div.style.width = "1px"; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ - │ │ │ │ │ - // the viewPortDiv is the outermost div we modify │ │ │ │ │ - var id = this.id + "_OpenLayers_ViewPort"; │ │ │ │ │ - this.viewPortDiv = OpenLayers.Util.createDiv(id, null, null, null, │ │ │ │ │ - "relative", null, │ │ │ │ │ - "hidden"); │ │ │ │ │ - this.viewPortDiv.style.width = "100%"; │ │ │ │ │ - this.viewPortDiv.style.height = "100%"; │ │ │ │ │ - this.viewPortDiv.className = "olMapViewport"; │ │ │ │ │ - this.div.appendChild(this.viewPortDiv); │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events( │ │ │ │ │ - this, this.viewPortDiv, null, this.fallThrough, { │ │ │ │ │ - includeXY: true │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.TileManager && this.tileManager !== null) { │ │ │ │ │ - if (!(this.tileManager instanceof OpenLayers.TileManager)) { │ │ │ │ │ - this.tileManager = new OpenLayers.TileManager(this.tileManager); │ │ │ │ │ - } │ │ │ │ │ - this.tileManager.addMap(this); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // the layerContainerDiv is the one that holds all the layers │ │ │ │ │ - id = this.id + "_OpenLayers_Container"; │ │ │ │ │ - this.layerContainerDiv = OpenLayers.Util.createDiv(id); │ │ │ │ │ - this.layerContainerDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] - 1; │ │ │ │ │ - this.layerContainerOriginPx = { │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }; │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - │ │ │ │ │ - this.viewPortDiv.appendChild(this.layerContainerDiv); │ │ │ │ │ - │ │ │ │ │ - this.updateSize(); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.autoUpdateSize === true) { │ │ │ │ │ - // updateSize on catching the window's resize │ │ │ │ │ - // Note that this is ok, as updateSize() does nothing if the │ │ │ │ │ - // map's size has not actually changed. │ │ │ │ │ - this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize, │ │ │ │ │ - this); │ │ │ │ │ - OpenLayers.Event.observe(window, 'resize', │ │ │ │ │ - this.updateSizeDestroy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // only append link stylesheet if the theme property is set │ │ │ │ │ - if (this.theme) { │ │ │ │ │ - // check existing links for equivalent url │ │ │ │ │ - var addNode = true; │ │ │ │ │ - var nodes = document.getElementsByTagName('link'); │ │ │ │ │ - for (var i = 0, len = nodes.length; i < len; ++i) { │ │ │ │ │ - if (OpenLayers.Util.isEquivalentUrl(nodes.item(i).href, │ │ │ │ │ - this.theme)) { │ │ │ │ │ - addNode = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // only add a new node if one with an equivalent url hasn't already │ │ │ │ │ - // been added │ │ │ │ │ - if (addNode) { │ │ │ │ │ - var cssNode = document.createElement('link'); │ │ │ │ │ - cssNode.setAttribute('rel', 'stylesheet'); │ │ │ │ │ - cssNode.setAttribute('type', 'text/css'); │ │ │ │ │ - cssNode.setAttribute('href', this.theme); │ │ │ │ │ - document.getElementsByTagName('head')[0].appendChild(cssNode); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.controls == null) { // default controls │ │ │ │ │ - this.controls = []; │ │ │ │ │ - if (OpenLayers.Control != null) { // running full or lite? │ │ │ │ │ - // Navigation or TouchNavigation depending on what is in build │ │ │ │ │ - if (OpenLayers.Control.Navigation) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Navigation()); │ │ │ │ │ - } else if (OpenLayers.Control.TouchNavigation) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.TouchNavigation()); │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.Zoom) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Zoom()); │ │ │ │ │ - } else if (OpenLayers.Control.PanZoom) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.PanZoom()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.Control.ArgParser) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.ArgParser()); │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.Attribution) { │ │ │ │ │ - this.controls.push(new OpenLayers.Control.Attribution()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - this.addControlToMap(this.controls[i]); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.popups = []; │ │ │ │ │ - │ │ │ │ │ - this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - // always call map.destroy() │ │ │ │ │ - OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); │ │ │ │ │ - │ │ │ │ │ - // add any initial layers │ │ │ │ │ - if (options && options.layers) { │ │ │ │ │ - /** │ │ │ │ │ - * If you have set options.center, the map center property will be │ │ │ │ │ - * set at this point. However, since setCenter has not been called, │ │ │ │ │ - * addLayers gets confused. So we delete the map center in this │ │ │ │ │ - * case. Because the check below uses options.center, it will │ │ │ │ │ - * be properly set below. │ │ │ │ │ - */ │ │ │ │ │ - delete this.center; │ │ │ │ │ - delete this.zoom; │ │ │ │ │ - this.addLayers(options.layers); │ │ │ │ │ - // set center (and optionally zoom) │ │ │ │ │ - if (options.center && !this.getCenter()) { │ │ │ │ │ - // zoom can be undefined here │ │ │ │ │ - this.setCenter(options.center, options.zoom); │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var distance, x0, y0, x1, y1, result; │ │ │ │ │ + if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + x0 = this.x; │ │ │ │ │ + y0 = this.y; │ │ │ │ │ + x1 = geometry.x; │ │ │ │ │ + y1 = geometry.y; │ │ │ │ │ + distance = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); │ │ │ │ │ + result = !details ? │ │ │ │ │ + distance : { │ │ │ │ │ + x0: x0, │ │ │ │ │ + y0: y0, │ │ │ │ │ + x1: x1, │ │ │ │ │ + y1: y1, │ │ │ │ │ + distance: distance │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + result = geometry.distanceTo(this, options); │ │ │ │ │ + if (details) { │ │ │ │ │ + // switch coord order since this geom is target │ │ │ │ │ + result = { │ │ │ │ │ + x0: result.x1, │ │ │ │ │ + y0: result.y1, │ │ │ │ │ + x1: result.x0, │ │ │ │ │ + y1: result.y0, │ │ │ │ │ + distance: result.distance │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (this.panMethod) { │ │ │ │ │ - this.panTween = new OpenLayers.Tween(this.panMethod); │ │ │ │ │ - } │ │ │ │ │ - if (this.zoomMethod && this.applyTransform.transform) { │ │ │ │ │ - this.zoomTween = new OpenLayers.Tween(this.zoomMethod); │ │ │ │ │ - } │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getViewport │ │ │ │ │ - * Get the DOMElement representing the view port. │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geom - {} The geometry to test. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - getViewport: function() { │ │ │ │ │ - return this.viewPortDiv; │ │ │ │ │ + equals: function(geom) { │ │ │ │ │ + var equals = false; │ │ │ │ │ + if (geom != null) { │ │ │ │ │ + equals = ((this.x == geom.x && this.y == geom.y) || │ │ │ │ │ + (isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y))); │ │ │ │ │ + } │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: render │ │ │ │ │ - * Render the map to a specified container. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * div - {String|DOMElement} The container that the map should be rendered │ │ │ │ │ - * to. If different than the current container, the map viewport │ │ │ │ │ - * will be moved from the current to the new container. │ │ │ │ │ + * Method: toShortString │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Shortened String representation of Point object. │ │ │ │ │ + * (ex. "5, 42") │ │ │ │ │ */ │ │ │ │ │ - render: function(div) { │ │ │ │ │ - this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ - OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ - this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ - this.div.appendChild(this.viewPortDiv); │ │ │ │ │ - this.updateSize(); │ │ │ │ │ + toShortString: function() { │ │ │ │ │ + return (this.x + ", " + this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unloadDestroy │ │ │ │ │ - * Function that is called to destroy the map on page unload. stored here │ │ │ │ │ - * so that if map is manually destroyed, we can unregister this. │ │ │ │ │ - */ │ │ │ │ │ - unloadDestroy: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateSizeDestroy │ │ │ │ │ - * When the map is destroyed, we need to stop listening to updateSize │ │ │ │ │ - * events: this method stores the function we need to unregister in │ │ │ │ │ - * non-IE browsers. │ │ │ │ │ - */ │ │ │ │ │ - updateSizeDestroy: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this map. │ │ │ │ │ - * Note that if you are using an application which removes a container │ │ │ │ │ - * of the map from the DOM, you need to ensure that you destroy the │ │ │ │ │ - * map *before* this happens; otherwise, the page unload handler │ │ │ │ │ - * will fail because the DOM elements that map.destroy() wants │ │ │ │ │ - * to clean up will be gone. (See │ │ │ │ │ - * http://trac.osgeo.org/openlayers/ticket/2277 for more information). │ │ │ │ │ - * This will apply to GeoExt and also to other applications which │ │ │ │ │ - * modify the DOM of the container of the OpenLayers Map. │ │ │ │ │ + * APIMethod: move │ │ │ │ │ + * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ + * This modifies the position of the geometry and clears the cached │ │ │ │ │ + * bounds. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ + * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // if unloadDestroy is null, we've already been destroyed │ │ │ │ │ - if (!this.unloadDestroy) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // make sure panning doesn't continue after destruction │ │ │ │ │ - if (this.panTween) { │ │ │ │ │ - this.panTween.stop(); │ │ │ │ │ - this.panTween = null; │ │ │ │ │ - } │ │ │ │ │ - // make sure zooming doesn't continue after destruction │ │ │ │ │ - if (this.zoomTween) { │ │ │ │ │ - this.zoomTween.stop(); │ │ │ │ │ - this.zoomTween = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // map has been destroyed. dont do it again! │ │ │ │ │ - OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); │ │ │ │ │ - this.unloadDestroy = null; │ │ │ │ │ - │ │ │ │ │ - if (this.updateSizeDestroy) { │ │ │ │ │ - OpenLayers.Event.stopObserving(window, 'resize', │ │ │ │ │ - this.updateSizeDestroy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.paddingForPopups = null; │ │ │ │ │ - │ │ │ │ │ - if (this.controls != null) { │ │ │ │ │ - for (var i = this.controls.length - 1; i >= 0; --i) { │ │ │ │ │ - this.controls[i].destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.controls = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.layers != null) { │ │ │ │ │ - for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ - //pass 'false' to destroy so that map wont try to set a new │ │ │ │ │ - // baselayer after each baselayer is removed │ │ │ │ │ - this.layers[i].destroy(false); │ │ │ │ │ - } │ │ │ │ │ - this.layers = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.viewPortDiv && this.viewPortDiv.parentNode) { │ │ │ │ │ - this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ - } │ │ │ │ │ - this.viewPortDiv = null; │ │ │ │ │ - │ │ │ │ │ - if (this.tileManager) { │ │ │ │ │ - this.tileManager.removeMap(this); │ │ │ │ │ - this.tileManager = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - this.options = null; │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + this.x = this.x + x; │ │ │ │ │ + this.y = this.y + y; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setOptions │ │ │ │ │ - * Change the map options │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a point around another. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Hashtable of options to tag to the map │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - setOptions: function(options) { │ │ │ │ │ - var updatePxExtent = this.minPx && │ │ │ │ │ - options.restrictedExtent != this.restrictedExtent; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - // force recalculation of minPx and maxPx │ │ │ │ │ - updatePxExtent && this.moveTo(this.getCachedCenter(), this.zoom, { │ │ │ │ │ - forceZoomChange: true │ │ │ │ │ - }); │ │ │ │ │ + rotate: function(angle, origin) { │ │ │ │ │ + angle *= Math.PI / 180; │ │ │ │ │ + var radius = this.distanceTo(origin); │ │ │ │ │ + var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x); │ │ │ │ │ + this.x = origin.x + (radius * Math.cos(theta)); │ │ │ │ │ + this.y = origin.y + (radius * Math.sin(theta)); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTileSize │ │ │ │ │ - * Get the tile size for the map │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - getTileSize: function() { │ │ │ │ │ - return this.tileSize; │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getBy │ │ │ │ │ - * Get a list of objects given a property and a match item. │ │ │ │ │ + * APIMethod: resize │ │ │ │ │ + * Resize a point relative to some origin. For points, this has the effect │ │ │ │ │ + * of scaling a vector (from the origin to the point). This method is │ │ │ │ │ + * more useful on geometry collection subclasses. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * array - {String} A property on the map whose value is an array. │ │ │ │ │ - * property - {String} A property on each item of the given array. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(map[array][i][property]) evaluates to true, the item will │ │ │ │ │ - * be included in the array returned. If no items are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ + * scale - {Float} Ratio of the new distance from the origin to the old │ │ │ │ │ + * distance from the origin. A scale of 2 doubles the │ │ │ │ │ + * distance between the point and origin. │ │ │ │ │ + * origin - {} Point of origin for resizing │ │ │ │ │ + * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} An array of items where the given property matches the given │ │ │ │ │ - * criteria. │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - getBy: function(array, property, match) { │ │ │ │ │ - var test = (typeof match.test == "function"); │ │ │ │ │ - var found = OpenLayers.Array.filter(this[array], function(item) { │ │ │ │ │ - return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ - }); │ │ │ │ │ - return found; │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + ratio = (ratio == undefined) ? 1 : ratio; │ │ │ │ │ + this.x = origin.x + (scale * ratio * (this.x - origin.x)); │ │ │ │ │ + this.y = origin.y + (scale * (this.y - origin.y)); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersBy │ │ │ │ │ - * Get a list of layers with properties matching the given criteria. │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * property - {String} A layer property to be matched. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ - * included in the array returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given criteria. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - getLayersBy: function(property, match) { │ │ │ │ │ - return this.getBy("layers", property, match); │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + intersect = this.equals(geometry); │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ + } │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersByName │ │ │ │ │ - * Get a list of layers with names matching the given name. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Translate the x,y properties of the point from source to dest. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * match - {String | Object} A layer name. The name can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * name.test(layer.name) evaluates to true, the layer will be included │ │ │ │ │ - * in the list of layers returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given name. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getLayersByName: function(match) { │ │ │ │ │ - return this.getLayersBy("name", match); │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if ((source && dest)) { │ │ │ │ │ + OpenLayers.Projection.transform( │ │ │ │ │ + this, source, dest); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayersByClass │ │ │ │ │ - * Get a list of layers of a given class (CLASS_NAME). │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * match - {String | Object} A layer class name. The match can also be a │ │ │ │ │ - * regular expression literal or object. In addition, it can be any │ │ │ │ │ - * object with a method named test. For reqular expressions or other, │ │ │ │ │ - * if type.test(layer.CLASS_NAME) evaluates to true, the layer will │ │ │ │ │ - * be included in the list of layers returned. If no layers are │ │ │ │ │ - * found, an empty array is returned. │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array()} A list of layers matching the given class. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getLayersByClass: function(match) { │ │ │ │ │ - return this.getLayersBy("CLASS_NAME", match); │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + return [this]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Collection.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Collection │ │ │ │ │ + * A Collection is exactly what it sounds like: A collection of different │ │ │ │ │ + * Geometries. These are stored in the local parameter (which │ │ │ │ │ + * can be passed as a parameter to the constructor). │ │ │ │ │ + * │ │ │ │ │ + * As new geometries are added to the collection, they are NOT cloned. │ │ │ │ │ + * When removing geometries, they need to be specified by reference (ie you │ │ │ │ │ + * have to pass in the *exact* geometry to be removed). │ │ │ │ │ + * │ │ │ │ │ + * The and functions here merely iterate through │ │ │ │ │ + * the components, summing their respective areas and lengths. │ │ │ │ │ + * │ │ │ │ │ + * Create a new instance with the constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControlsBy │ │ │ │ │ - * Get a list of controls with properties matching the given criteria. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} A control property to be matched. │ │ │ │ │ - * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ - * expression literal or object. In addition, it can be any object │ │ │ │ │ - * with a method named test. For reqular expressions or other, if │ │ │ │ │ - * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ - * included in the array returned. If no layers are found, an empty │ │ │ │ │ - * array is returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} A list of controls matching the given │ │ │ │ │ - * criteria. An empty array is returned if no matches are found. │ │ │ │ │ + * APIProperty: components │ │ │ │ │ + * {Array()} The component parts of this geometry │ │ │ │ │ */ │ │ │ │ │ - getControlsBy: function(property, match) { │ │ │ │ │ - return this.getBy("controls", property, match); │ │ │ │ │ - }, │ │ │ │ │ + components: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControlsByClass │ │ │ │ │ - * Get a list of controls of a given class (CLASS_NAME). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * match - {String | Object} A control class name. The match can also be a │ │ │ │ │ - * regular expression literal or object. In addition, it can be any │ │ │ │ │ - * object with a method named test. For reqular expressions or other, │ │ │ │ │ - * if type.test(control.CLASS_NAME) evaluates to true, the control will │ │ │ │ │ - * be included in the list of controls returned. If no controls are │ │ │ │ │ - * found, an empty array is returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} A list of controls matching the given class. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null value means the │ │ │ │ │ + * component types are not restricted. │ │ │ │ │ */ │ │ │ │ │ - getControlsByClass: function(match) { │ │ │ │ │ - return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Layer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Layers to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ + componentTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLayer │ │ │ │ │ - * Get a layer based on its id │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ + * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} A layer id │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} Optional array of geometries │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The Layer with the corresponding id from the map's │ │ │ │ │ - * layer collection, or null if not found. │ │ │ │ │ */ │ │ │ │ │ - getLayer: function(id) { │ │ │ │ │ - var foundLayer = null; │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer.id == id) { │ │ │ │ │ - foundLayer = layer; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + initialize: function(components) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.components = []; │ │ │ │ │ + if (components != null) { │ │ │ │ │ + this.addComponents(components); │ │ │ │ │ } │ │ │ │ │ - return foundLayer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayerZIndex │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * zIdx - {int} │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - setLayerZIndex: function(layer, zIdx) { │ │ │ │ │ - layer.setZIndex( │ │ │ │ │ - this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] + │ │ │ │ │ - zIdx * 5); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.components.length = 0; │ │ │ │ │ + this.components = null; │ │ │ │ │ + OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetLayersZIndex │ │ │ │ │ - * Reset each layer's z-index based on layer's array index │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clone this geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this collection │ │ │ │ │ */ │ │ │ │ │ - resetLayersZIndex: function() { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - this.setLayerZIndex(layer, i); │ │ │ │ │ + clone: function() { │ │ │ │ │ + var geometry = eval("new " + this.CLASS_NAME + "()"); │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + geometry.addComponent(this.components[i].clone()); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ + │ │ │ │ │ + return geometry; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addLayer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * │ │ │ │ │ + * Method: getComponentsString │ │ │ │ │ + * Get a string representing the components for this collection │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} True if the layer has been added to the map. │ │ │ │ │ + * {String} A string representation of the components of this geometry │ │ │ │ │ */ │ │ │ │ │ - addLayer: function(layer) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - if (this.layers[i] == layer) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.events.triggerEvent("preaddlayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }) === false) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (this.allOverlays) { │ │ │ │ │ - layer.isBaseLayer = false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - layer.div.className = "olLayerDiv"; │ │ │ │ │ - layer.div.style.overflow = ""; │ │ │ │ │ - this.setLayerZIndex(layer, this.layers.length); │ │ │ │ │ - │ │ │ │ │ - if (layer.isFixed) { │ │ │ │ │ - this.viewPortDiv.appendChild(layer.div); │ │ │ │ │ - } else { │ │ │ │ │ - this.layerContainerDiv.appendChild(layer.div); │ │ │ │ │ + getComponentsString: function() { │ │ │ │ │ + var strings = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + strings.push(this.components[i].toShortString()); │ │ │ │ │ } │ │ │ │ │ - this.layers.push(layer); │ │ │ │ │ - layer.setMap(this); │ │ │ │ │ + return strings.join(","); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (layer.isBaseLayer || (this.allOverlays && !this.baseLayer)) { │ │ │ │ │ - if (this.baseLayer == null) { │ │ │ │ │ - // set the first baselaye we add as the baselayer │ │ │ │ │ - this.setBaseLayer(layer); │ │ │ │ │ - } else { │ │ │ │ │ - layer.setVisibility(false); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds by iterating through the components and │ │ │ │ │ + * calling calling extendBounds() on each item. │ │ │ │ │ + */ │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + var bounds = new OpenLayers.Bounds(); │ │ │ │ │ + var components = this.components; │ │ │ │ │ + if (components) { │ │ │ │ │ + for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ + bounds.extend(components[i].getBounds()); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - layer.redraw(); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("addlayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.events.triggerEvent("added", { │ │ │ │ │ - map: this, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.afterAdd(); │ │ │ │ │ - │ │ │ │ │ - return true; │ │ │ │ │ + // to preserve old behavior, we only set bounds if non-null │ │ │ │ │ + // in the future, we could add bounds.isEmpty() │ │ │ │ │ + if (bounds.left != null && bounds.bottom != null && │ │ │ │ │ + bounds.right != null && bounds.top != null) { │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addLayers │ │ │ │ │ + * APIMethod: addComponents │ │ │ │ │ + * Add components to this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layers - {Array()} │ │ │ │ │ + * components - {Array()} An array of geometries to add │ │ │ │ │ */ │ │ │ │ │ - addLayers: function(layers) { │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - this.addLayer(layers[i]); │ │ │ │ │ + addComponents: function(components) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ + this.addComponent(components[i]); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeLayer │ │ │ │ │ - * Removes a layer from the map by removing its visual element (the │ │ │ │ │ - * layer.div property), then removing it from the map's internal list │ │ │ │ │ - * of layers, setting the layer's map property to null. │ │ │ │ │ - * │ │ │ │ │ - * a "removelayer" event is triggered. │ │ │ │ │ - * │ │ │ │ │ - * very worthy of mention is that simply removing a layer from a map │ │ │ │ │ - * will not cause the removal of any popups which may have been created │ │ │ │ │ - * by the layer. this is due to the fact that it was decided at some │ │ │ │ │ - * point that popups would not belong to layers. thus there is no way │ │ │ │ │ - * for us to know here to which layer the popup belongs. │ │ │ │ │ - * │ │ │ │ │ - * A simple solution to this is simply to call destroy() on the layer. │ │ │ │ │ - * the default OpenLayers.Layer class's destroy() function │ │ │ │ │ - * automatically takes care to remove itself from whatever map it has │ │ │ │ │ - * been attached to. │ │ │ │ │ - * │ │ │ │ │ - * The correct solution is for the layer itself to register an │ │ │ │ │ - * event-handler on "removelayer" and when it is called, if it │ │ │ │ │ - * recognizes itself as the layer being removed, then it cycles through │ │ │ │ │ - * its own personal list of popups, removing them from the map. │ │ │ │ │ + /** │ │ │ │ │ + * Method: addComponent │ │ │ │ │ + * Add a new component (geometry) to the collection. If this.componentTypes │ │ │ │ │ + * is set, then the component class name must be in the componentTypes array. │ │ │ │ │ + * │ │ │ │ │ + * The bounds cache is reset. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * setNewBaseLayer - {Boolean} Default is true │ │ │ │ │ + * component - {} A geometry to add │ │ │ │ │ + * index - {int} Optional index into the array to insert the component │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component geometry was successfully added │ │ │ │ │ */ │ │ │ │ │ - removeLayer: function(layer, setNewBaseLayer) { │ │ │ │ │ - if (this.events.triggerEvent("preremovelayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }) === false) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (setNewBaseLayer == null) { │ │ │ │ │ - setNewBaseLayer = true; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (layer.isFixed) { │ │ │ │ │ - this.viewPortDiv.removeChild(layer.div); │ │ │ │ │ - } else { │ │ │ │ │ - this.layerContainerDiv.removeChild(layer.div); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.removeItem(this.layers, layer); │ │ │ │ │ - layer.removeMap(this); │ │ │ │ │ - layer.map = null; │ │ │ │ │ + addComponent: function(component, index) { │ │ │ │ │ + var added = false; │ │ │ │ │ + if (component) { │ │ │ │ │ + if (this.componentTypes == null || │ │ │ │ │ + (OpenLayers.Util.indexOf(this.componentTypes, │ │ │ │ │ + component.CLASS_NAME) > -1)) { │ │ │ │ │ │ │ │ │ │ - // if we removed the base layer, need to set a new one │ │ │ │ │ - if (this.baseLayer == layer) { │ │ │ │ │ - this.baseLayer = null; │ │ │ │ │ - if (setNewBaseLayer) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var iLayer = this.layers[i]; │ │ │ │ │ - if (iLayer.isBaseLayer || this.allOverlays) { │ │ │ │ │ - this.setBaseLayer(iLayer); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + if (index != null && (index < this.components.length)) { │ │ │ │ │ + var components1 = this.components.slice(0, index); │ │ │ │ │ + var components2 = this.components.slice(index, │ │ │ │ │ + this.components.length); │ │ │ │ │ + components1.push(component); │ │ │ │ │ + this.components = components1.concat(components2); │ │ │ │ │ + } else { │ │ │ │ │ + this.components.push(component); │ │ │ │ │ } │ │ │ │ │ + component.parent = this; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + added = true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.resetLayersZIndex(); │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("removelayer", { │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - layer.events.triggerEvent("removed", { │ │ │ │ │ - map: this, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ + return added; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getNumLayers │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Int} The number of layers attached to the map. │ │ │ │ │ - */ │ │ │ │ │ - getNumLayers: function() { │ │ │ │ │ - return this.layers.length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerIndex │ │ │ │ │ + * APIMethod: removeComponents │ │ │ │ │ + * Remove components from this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ + * components - {Array()} The components to be removed │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The current (zero-based) index of the given layer in the map's │ │ │ │ │ - * layer stack. Returns -1 if the layer isn't on the map. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A component was removed. │ │ │ │ │ */ │ │ │ │ │ - getLayerIndex: function(layer) { │ │ │ │ │ - return OpenLayers.Util.indexOf(this.layers, layer); │ │ │ │ │ - }, │ │ │ │ │ + removeComponents: function(components) { │ │ │ │ │ + var removed = false; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setLayerIndex │ │ │ │ │ - * Move the given layer to the specified (zero-based) index in the layer │ │ │ │ │ - * list, changing its z-index in the map display. Use │ │ │ │ │ - * map.getLayerIndex() to find out the current index of a layer. Note │ │ │ │ │ - * that this cannot (or at least should not) be effectively used to │ │ │ │ │ - * raise base layers above overlays. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * idx - {int} │ │ │ │ │ - */ │ │ │ │ │ - setLayerIndex: function(layer, idx) { │ │ │ │ │ - var base = this.getLayerIndex(layer); │ │ │ │ │ - if (idx < 0) { │ │ │ │ │ - idx = 0; │ │ │ │ │ - } else if (idx > this.layers.length) { │ │ │ │ │ - idx = this.layers.length; │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ } │ │ │ │ │ - if (base != idx) { │ │ │ │ │ - this.layers.splice(base, 1); │ │ │ │ │ - this.layers.splice(idx, 0, layer); │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - this.setLayerZIndex(this.layers[i], i); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: layer, │ │ │ │ │ - property: "order" │ │ │ │ │ - }); │ │ │ │ │ - if (this.allOverlays) { │ │ │ │ │ - if (idx === 0) { │ │ │ │ │ - this.setBaseLayer(layer); │ │ │ │ │ - } else if (this.baseLayer !== this.layers[0]) { │ │ │ │ │ - this.setBaseLayer(this.layers[0]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ + removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ } │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: raiseLayer │ │ │ │ │ - * Change the index of the given layer by delta. If delta is positive, │ │ │ │ │ - * the layer is moved up the map's layer stack; if delta is negative, │ │ │ │ │ - * the layer is moved down. Again, note that this cannot (or at least │ │ │ │ │ - * should not) be effectively used to raise base layers above overlays. │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeComponent │ │ │ │ │ + * Remove a component from this geometry. │ │ │ │ │ * │ │ │ │ │ - * Paremeters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * delta - {int} │ │ │ │ │ - */ │ │ │ │ │ - raiseLayer: function(layer, delta) { │ │ │ │ │ - var idx = this.getLayerIndex(layer) + delta; │ │ │ │ │ - this.setLayerIndex(layer, idx); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setBaseLayer │ │ │ │ │ - * Allows user to specify one of the currently-loaded layers as the Map's │ │ │ │ │ - * new base layer. │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newBaseLayer - {} │ │ │ │ │ + * component - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - setBaseLayer: function(newBaseLayer) { │ │ │ │ │ - │ │ │ │ │ - if (newBaseLayer != this.baseLayer) { │ │ │ │ │ - │ │ │ │ │ - // ensure newBaseLayer is already loaded │ │ │ │ │ - if (OpenLayers.Util.indexOf(this.layers, newBaseLayer) != -1) { │ │ │ │ │ - │ │ │ │ │ - // preserve center and scale when changing base layers │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - var newResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - this.getScale(), newBaseLayer.units │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // make the old base layer invisible │ │ │ │ │ - if (this.baseLayer != null && !this.allOverlays) { │ │ │ │ │ - this.baseLayer.setVisibility(false); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // set new baselayer │ │ │ │ │ - this.baseLayer = newBaseLayer; │ │ │ │ │ - │ │ │ │ │ - if (!this.allOverlays || this.baseLayer.visibility) { │ │ │ │ │ - this.baseLayer.setVisibility(true); │ │ │ │ │ - // Layer may previously have been visible but not in range. │ │ │ │ │ - // In this case we need to redraw it to make it visible. │ │ │ │ │ - if (this.baseLayer.inRange === false) { │ │ │ │ │ - this.baseLayer.redraw(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + removeComponent: function(component) { │ │ │ │ │ │ │ │ │ │ - // recenter the map │ │ │ │ │ - if (center != null) { │ │ │ │ │ - // new zoom level derived from old scale │ │ │ │ │ - var newZoom = this.getZoomForResolution( │ │ │ │ │ - newResolution || this.resolution, true │ │ │ │ │ - ); │ │ │ │ │ - // zoom and force zoom change │ │ │ │ │ - this.setCenter(center, newZoom, false, true); │ │ │ │ │ - } │ │ │ │ │ + OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ │ │ │ │ │ - this.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this.baseLayer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ + // to this.getBounds(); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Control Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Controls to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addControl │ │ │ │ │ - * Add the passed over control to the map. Optionally │ │ │ │ │ - * position the control at the given pixel. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * px - {} │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ + * Calculate the length of this geometry │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The length of the geometry │ │ │ │ │ */ │ │ │ │ │ - addControl: function(control, px) { │ │ │ │ │ - this.controls.push(control); │ │ │ │ │ - this.addControlToMap(control, px); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i].getLength(); │ │ │ │ │ + } │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addControls │ │ │ │ │ - * Add all of the passed over controls to the map. │ │ │ │ │ - * You can pass over an optional second array │ │ │ │ │ - * with pixel-objects to position the controls. │ │ │ │ │ - * The indices of the two arrays should match and │ │ │ │ │ - * you can add null as pixel for those controls │ │ │ │ │ - * you want to be autopositioned. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * controls - {Array()} │ │ │ │ │ - * pixels - {Array()} │ │ │ │ │ + * APIMethod: getArea │ │ │ │ │ + * Calculate the area of this geometry. Note how this function is overridden │ │ │ │ │ + * in . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - addControls: function(controls, pixels) { │ │ │ │ │ - var pxs = (arguments.length === 1) ? [] : pixels; │ │ │ │ │ - for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ - var ctrl = controls[i]; │ │ │ │ │ - var px = (pxs[i]) ? pxs[i] : null; │ │ │ │ │ - this.addControl(ctrl, px); │ │ │ │ │ + getArea: function() { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + area += this.components[i].getArea(); │ │ │ │ │ } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addControlToMap │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getGeodesicArea │ │ │ │ │ + * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ - * control - {} │ │ │ │ │ - * px - {} │ │ │ │ │ + * Reference: │ │ │ │ │ + * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for │ │ │ │ │ + * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion │ │ │ │ │ + * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {float} The approximate geodesic area of the geometry in square meters. │ │ │ │ │ */ │ │ │ │ │ - addControlToMap: function(control, px) { │ │ │ │ │ - // If a control doesn't have a div at this point, it belongs in the │ │ │ │ │ - // viewport. │ │ │ │ │ - control.outsideViewport = (control.div != null); │ │ │ │ │ - │ │ │ │ │ - // If the map has a displayProjection, and the control doesn't, set │ │ │ │ │ - // the display projection. │ │ │ │ │ - if (this.displayProjection && !control.displayProjection) { │ │ │ │ │ - control.displayProjection = this.displayProjection; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - control.setMap(this); │ │ │ │ │ - var div = control.draw(px); │ │ │ │ │ - if (div) { │ │ │ │ │ - if (!control.outsideViewport) { │ │ │ │ │ - div.style.zIndex = this.Z_INDEX_BASE['Control'] + │ │ │ │ │ - this.controls.length; │ │ │ │ │ - this.viewPortDiv.appendChild(div); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (control.autoActivate) { │ │ │ │ │ - control.activate(); │ │ │ │ │ + getGeodesicArea: function(projection) { │ │ │ │ │ + var area = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + area += this.components[i].getGeodesicArea(projection); │ │ │ │ │ } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getControl │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * │ │ │ │ │ + * Compute the centroid for this geometry collection. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * id - {String} ID of the control to return. │ │ │ │ │ - * │ │ │ │ │ + * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ + * returning an area weighted average of all geometries in this collection. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The control from the map's list of controls │ │ │ │ │ - * which has a matching 'id'. If none found, │ │ │ │ │ - * returns null. │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - getControl: function(id) { │ │ │ │ │ - var returnControl = null; │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - var control = this.controls[i]; │ │ │ │ │ - if (control.id == id) { │ │ │ │ │ - returnControl = control; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + getCentroid: function(weighted) { │ │ │ │ │ + if (!weighted) { │ │ │ │ │ + return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ + } │ │ │ │ │ + var len = this.components.length; │ │ │ │ │ + if (!len) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return returnControl; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeControl │ │ │ │ │ - * Remove a control from the map. Removes the control both from the map │ │ │ │ │ - * object's internal array of controls, as well as from the map's │ │ │ │ │ - * viewPort (assuming the control was not added outsideViewport) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control to remove. │ │ │ │ │ - */ │ │ │ │ │ - removeControl: function(control) { │ │ │ │ │ - //make sure control is non-null and actually part of our map │ │ │ │ │ - if ((control) && (control == this.getControl(control.id))) { │ │ │ │ │ - if (control.div && (control.div.parentNode == this.viewPortDiv)) { │ │ │ │ │ - this.viewPortDiv.removeChild(control.div); │ │ │ │ │ + var areas = []; │ │ │ │ │ + var centroids = []; │ │ │ │ │ + var areaSum = 0; │ │ │ │ │ + var minArea = Number.MAX_VALUE; │ │ │ │ │ + var component; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + component = this.components[i]; │ │ │ │ │ + var area = component.getArea(); │ │ │ │ │ + var centroid = component.getCentroid(true); │ │ │ │ │ + if (isNaN(area) || isNaN(centroid.x) || isNaN(centroid.y)) { │ │ │ │ │ + continue; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Util.removeItem(this.controls, control); │ │ │ │ │ + areas.push(area); │ │ │ │ │ + areaSum += area; │ │ │ │ │ + minArea = (area < minArea && area > 0) ? area : minArea; │ │ │ │ │ + centroids.push(centroid); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Popup Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with adding and */ │ │ │ │ │ - /* removing Popups to and from the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addPopup │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * popup - {} │ │ │ │ │ - * exclusive - {Boolean} If true, closes all other popups first │ │ │ │ │ - */ │ │ │ │ │ - addPopup: function(popup, exclusive) { │ │ │ │ │ - │ │ │ │ │ - if (exclusive) { │ │ │ │ │ - //remove all other popups from screen │ │ │ │ │ - for (var i = this.popups.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removePopup(this.popups[i]); │ │ │ │ │ + len = areas.length; │ │ │ │ │ + if (areaSum === 0) { │ │ │ │ │ + // all the components in this collection have 0 area │ │ │ │ │ + // probably a collection of points -- weight all the points the same │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + areas[i] = 1; │ │ │ │ │ + } │ │ │ │ │ + areaSum = areas.length; │ │ │ │ │ + } else { │ │ │ │ │ + // normalize all the areas where the smallest area will get │ │ │ │ │ + // a value of 1 │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + areas[i] /= minArea; │ │ │ │ │ } │ │ │ │ │ + areaSum /= minArea; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - popup.map = this; │ │ │ │ │ - this.popups.push(popup); │ │ │ │ │ - var popupDiv = popup.draw(); │ │ │ │ │ - if (popupDiv) { │ │ │ │ │ - popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + │ │ │ │ │ - this.popups.length; │ │ │ │ │ - this.layerContainerDiv.appendChild(popupDiv); │ │ │ │ │ + var xSum = 0, │ │ │ │ │ + ySum = 0, │ │ │ │ │ + centroid, area; │ │ │ │ │ + for (var i = 0; i < len; ++i) { │ │ │ │ │ + centroid = centroids[i]; │ │ │ │ │ + area = areas[i]; │ │ │ │ │ + xSum += centroid.x * area; │ │ │ │ │ + ySum += centroid.y * area; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removePopup │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * popup - {} │ │ │ │ │ - */ │ │ │ │ │ - removePopup: function(popup) { │ │ │ │ │ - OpenLayers.Util.removeItem(this.popups, popup); │ │ │ │ │ - if (popup.div) { │ │ │ │ │ - try { │ │ │ │ │ - this.layerContainerDiv.removeChild(popup.div); │ │ │ │ │ - } catch (e) {} // Popups sometimes apparently get disconnected │ │ │ │ │ - // from the layerContainerDiv, and cause complaints. │ │ │ │ │ - } │ │ │ │ │ - popup.map = null; │ │ │ │ │ + return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Container Div Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions deal with the access to */ │ │ │ │ │ - /* and maintenance of the size of the container div */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getSize │ │ │ │ │ + * APIMethod: getGeodesicLength │ │ │ │ │ + * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ + * │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An object that represents the │ │ │ │ │ - * size, in pixels, of the div into which OpenLayers │ │ │ │ │ - * has been loaded. │ │ │ │ │ - * Note - A clone() of this locally cached variable is │ │ │ │ │ - * returned, so as not to allow users to modify it. │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - getSize: function() { │ │ │ │ │ - var size = null; │ │ │ │ │ - if (this.size != null) { │ │ │ │ │ - size = this.size.clone(); │ │ │ │ │ + getGeodesicLength: function(projection) { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i].getGeodesicLength(projection); │ │ │ │ │ } │ │ │ │ │ - return size; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: updateSize │ │ │ │ │ - * This function should be called by any external code which dynamically │ │ │ │ │ - * changes the size of the map div (because mozilla wont let us catch │ │ │ │ │ - * the "onresize" for an element) │ │ │ │ │ + * APIMethod: move │ │ │ │ │ + * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ + * This modifies the position of the geometry and clears the cached │ │ │ │ │ + * bounds. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ + * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ */ │ │ │ │ │ - updateSize: function() { │ │ │ │ │ - // the div might have moved on the page, also │ │ │ │ │ - var newSize = this.getCurrentSize(); │ │ │ │ │ - if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) { │ │ │ │ │ - this.events.clearMouseCache(); │ │ │ │ │ - var oldSize = this.getSize(); │ │ │ │ │ - if (oldSize == null) { │ │ │ │ │ - this.size = oldSize = newSize; │ │ │ │ │ - } │ │ │ │ │ - if (!newSize.equals(oldSize)) { │ │ │ │ │ - │ │ │ │ │ - // store the new size │ │ │ │ │ - this.size = newSize; │ │ │ │ │ - │ │ │ │ │ - //notify layers of mapresize │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - this.layers[i].onMapResize(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - │ │ │ │ │ - if (this.baseLayer != null && center != null) { │ │ │ │ │ - var zoom = this.getZoom(); │ │ │ │ │ - this.zoom = null; │ │ │ │ │ - this.setCenter(center, zoom); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + this.components[i].move(x, y); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("updatesize"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentSize │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A new object with the dimensions │ │ │ │ │ - * of the map div │ │ │ │ │ - */ │ │ │ │ │ - getCurrentSize: function() { │ │ │ │ │ - │ │ │ │ │ - var size = new OpenLayers.Size(this.div.clientWidth, │ │ │ │ │ - this.div.clientHeight); │ │ │ │ │ - │ │ │ │ │ - if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ - size.w = this.div.offsetWidth; │ │ │ │ │ - size.h = this.div.offsetHeight; │ │ │ │ │ - } │ │ │ │ │ - if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ - size.w = parseInt(this.div.style.width); │ │ │ │ │ - size.h = parseInt(this.div.style.height); │ │ │ │ │ - } │ │ │ │ │ - return size; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a geometry around some origin │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * center - {} Default is this.getCenter() │ │ │ │ │ - * resolution - {float} Default is this.getResolution() │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A bounds based on resolution, center, and │ │ │ │ │ - * current mapsize. │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - calculateBounds: function(center, resolution) { │ │ │ │ │ - │ │ │ │ │ - var extent = null; │ │ │ │ │ - │ │ │ │ │ - if (center == null) { │ │ │ │ │ - center = this.getCachedCenter(); │ │ │ │ │ - } │ │ │ │ │ - if (resolution == null) { │ │ │ │ │ - resolution = this.getResolution(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if ((center != null) && (resolution != null)) { │ │ │ │ │ - var halfWDeg = (this.size.w * resolution) / 2; │ │ │ │ │ - var halfHDeg = (this.size.h * resolution) / 2; │ │ │ │ │ - │ │ │ │ │ - extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ - center.lat - halfHDeg, │ │ │ │ │ - center.lon + halfWDeg, │ │ │ │ │ - center.lat + halfHDeg); │ │ │ │ │ + rotate: function(angle, origin) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + this.components[i].rotate(angle, origin); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return extent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Zoom, Center, Pan Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions handle the validation, */ │ │ │ │ │ - /* getting and setting of the Zoom Level and Center */ │ │ │ │ │ - /* as well as the panning of the Map */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getCenter │ │ │ │ │ + * APIMethod: resize │ │ │ │ │ + * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ + * a uniform scaling to a geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scale - {Float} Factor by which to scale the geometry. A scale of 2 │ │ │ │ │ + * doubles the size of the geometry in each dimension │ │ │ │ │ + * (lines, for example, will be twice as long, and polygons │ │ │ │ │ + * will have four times the area). │ │ │ │ │ + * origin - {} Point of origin for resizing │ │ │ │ │ + * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - getCenter: function() { │ │ │ │ │ - var center = null; │ │ │ │ │ - var cachedCenter = this.getCachedCenter(); │ │ │ │ │ - if (cachedCenter) { │ │ │ │ │ - center = cachedCenter.clone(); │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ + this.components[i].resize(scale, origin, ratio); │ │ │ │ │ } │ │ │ │ │ - return center; │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCachedCenter │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getCachedCenter: function() { │ │ │ │ │ - if (!this.center && this.size) { │ │ │ │ │ - this.center = this.getLonLatFromViewPortPx({ │ │ │ │ │ - x: this.size.w / 2, │ │ │ │ │ - y: this.size.h / 2 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return this.center; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoom │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ - getZoom: function() { │ │ │ │ │ - return this.zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: pan │ │ │ │ │ - * Allows user to pan by a value of screen pixels │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Integer} │ │ │ │ │ - * dy - {Integer} │ │ │ │ │ - * options - {Object} Options to configure panning: │ │ │ │ │ - * - *animate* {Boolean} Use panTo instead of setCenter. Default is true. │ │ │ │ │ - * - *dragging* {Boolean} Call setCenter with dragging true. Default is │ │ │ │ │ - * false. │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ + * If details is true, the return will be an object with distance, │ │ │ │ │ + * x0, y0, x1, and y1 properties. The x0 and y0 properties represent │ │ │ │ │ + * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ + * properties represent the coordinates of the closest point on the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - pan: function(dx, dy, options) { │ │ │ │ │ - options = OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ - animate: true, │ │ │ │ │ - dragging: false │ │ │ │ │ - }); │ │ │ │ │ - if (options.dragging) { │ │ │ │ │ - if (dx != 0 || dy != 0) { │ │ │ │ │ - this.moveByPx(dx, dy); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // getCenter │ │ │ │ │ - var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter()); │ │ │ │ │ - │ │ │ │ │ - // adjust │ │ │ │ │ - var newCenterPx = centerPx.add(dx, dy); │ │ │ │ │ - │ │ │ │ │ - if (this.dragging || !newCenterPx.equals(centerPx)) { │ │ │ │ │ - var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); │ │ │ │ │ - if (options.animate) { │ │ │ │ │ - this.panTo(newCenterLonLat); │ │ │ │ │ - } else { │ │ │ │ │ - this.moveTo(newCenterLonLat); │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.events.triggerEvent("moveend"); │ │ │ │ │ - } │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var result, best, distance; │ │ │ │ │ + var min = Number.POSITIVE_INFINITY; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + result = this.components[i].distanceTo(geometry, options); │ │ │ │ │ + distance = details ? result.distance : result; │ │ │ │ │ + if (distance < min) { │ │ │ │ │ + min = distance; │ │ │ │ │ + best = result; │ │ │ │ │ + if (min == 0) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: panTo │ │ │ │ │ - * Allows user to pan to a new lonlat │ │ │ │ │ - * If the new lonlat is in the current extent the map will slide smoothly │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + * geometry - {} The geometry to test. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - panTo: function(lonlat) { │ │ │ │ │ - if (this.panTween && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - │ │ │ │ │ - // center will not change, don't do nothing │ │ │ │ │ - if (lonlat.equals(center)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var from = this.getPixelFromLonLat(center); │ │ │ │ │ - var to = this.getPixelFromLonLat(lonlat); │ │ │ │ │ - var vector = { │ │ │ │ │ - x: to.x - from.x, │ │ │ │ │ - y: to.y - from.y │ │ │ │ │ - }; │ │ │ │ │ - var last = { │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - this.panTween.start({ │ │ │ │ │ - x: 0, │ │ │ │ │ - y: 0 │ │ │ │ │ - }, vector, this.panDuration, { │ │ │ │ │ - callbacks: { │ │ │ │ │ - eachStep: OpenLayers.Function.bind(function(px) { │ │ │ │ │ - var x = px.x - last.x, │ │ │ │ │ - y = px.y - last.y; │ │ │ │ │ - this.moveByPx(x, y); │ │ │ │ │ - last.x = Math.round(px.x); │ │ │ │ │ - last.y = Math.round(px.y); │ │ │ │ │ - }, this), │ │ │ │ │ - done: OpenLayers.Function.bind(function(px) { │ │ │ │ │ - this.moveTo(lonlat); │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.events.triggerEvent("moveend"); │ │ │ │ │ - }, this) │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ + equals: function(geometry) { │ │ │ │ │ + var equivalent = true; │ │ │ │ │ + if (!geometry || !geometry.CLASS_NAME || │ │ │ │ │ + (this.CLASS_NAME != geometry.CLASS_NAME)) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ + } else if (!(OpenLayers.Util.isArray(geometry.components)) || │ │ │ │ │ + (geometry.components.length != this.components.length)) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ } else { │ │ │ │ │ - this.setCenter(lonlat); │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + if (!this.components[i].equals(geometry.components[i])) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return equivalent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setCenter │ │ │ │ │ - * Set the map center (and optionally, the zoom level). │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Reproject the components geometry from source to dest. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {|Array} The new center location. │ │ │ │ │ - * If provided as array, the first value is the x coordinate, │ │ │ │ │ - * and the 2nd value is the y coordinate. │ │ │ │ │ - * zoom - {Integer} Optional zoom level. │ │ │ │ │ - * dragging - {Boolean} Specifies whether or not to trigger │ │ │ │ │ - * movestart/end events │ │ │ │ │ - * forceZoomChange - {Boolean} Specifies whether or not to trigger zoom │ │ │ │ │ - * change events (needed on baseLayer change) │ │ │ │ │ - * │ │ │ │ │ - * TBD: reconsider forceZoomChange in 3.0 │ │ │ │ │ - */ │ │ │ │ │ - setCenter: function(lonlat, zoom, dragging, forceZoomChange) { │ │ │ │ │ - if (this.panTween) { │ │ │ │ │ - this.panTween.stop(); │ │ │ │ │ - } │ │ │ │ │ - if (this.zoomTween) { │ │ │ │ │ - this.zoomTween.stop(); │ │ │ │ │ - } │ │ │ │ │ - this.moveTo(lonlat, zoom, { │ │ │ │ │ - 'dragging': dragging, │ │ │ │ │ - 'forceZoomChange': forceZoomChange │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Drag the map by pixels. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} │ │ │ │ │ - * dy - {Number} │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - var hw = this.size.w / 2; │ │ │ │ │ - var hh = this.size.h / 2; │ │ │ │ │ - var x = hw + dx; │ │ │ │ │ - var y = hh + dy; │ │ │ │ │ - var wrapDateLine = this.baseLayer.wrapDateLine; │ │ │ │ │ - var xRestriction = 0; │ │ │ │ │ - var yRestriction = 0; │ │ │ │ │ - if (this.restrictedExtent) { │ │ │ │ │ - xRestriction = hw; │ │ │ │ │ - yRestriction = hh; │ │ │ │ │ - // wrapping the date line makes no sense for restricted extents │ │ │ │ │ - wrapDateLine = false; │ │ │ │ │ - } │ │ │ │ │ - dx = wrapDateLine || │ │ │ │ │ - x <= this.maxPx.x - xRestriction && │ │ │ │ │ - x >= this.minPx.x + xRestriction ? Math.round(dx) : 0; │ │ │ │ │ - dy = y <= this.maxPx.y - yRestriction && │ │ │ │ │ - y >= this.minPx.y + yRestriction ? Math.round(dy) : 0; │ │ │ │ │ - if (dx || dy) { │ │ │ │ │ - if (!this.dragging) { │ │ │ │ │ - this.dragging = true; │ │ │ │ │ - this.events.triggerEvent("movestart"); │ │ │ │ │ - } │ │ │ │ │ - this.center = null; │ │ │ │ │ - if (dx) { │ │ │ │ │ - this.layerContainerOriginPx.x -= dx; │ │ │ │ │ - this.minPx.x -= dx; │ │ │ │ │ - this.maxPx.x -= dx; │ │ │ │ │ - } │ │ │ │ │ - if (dy) { │ │ │ │ │ - this.layerContainerOriginPx.y -= dy; │ │ │ │ │ - this.minPx.y -= dy; │ │ │ │ │ - this.maxPx.y -= dy; │ │ │ │ │ - } │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - var layer, i, len; │ │ │ │ │ - for (i = 0, len = this.layers.length; i < len; ++i) { │ │ │ │ │ - layer = this.layers[i]; │ │ │ │ │ - if (layer.visibility && │ │ │ │ │ - (layer === this.baseLayer || layer.inRange)) { │ │ │ │ │ - layer.moveByPx(dx, dy); │ │ │ │ │ - layer.events.triggerEvent("move"); │ │ │ │ │ - } │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if (source && dest) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + var component = this.components[i]; │ │ │ │ │ + component.transform(source, dest); │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("move"); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: adjustZoom │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoom - {Number} The zoom level to adjust │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Integer} Adjusted zoom level that shows a map not wider than its │ │ │ │ │ - * 's maxExtent. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - adjustZoom: function(zoom) { │ │ │ │ │ - if (this.baseLayer && this.baseLayer.wrapDateLine) { │ │ │ │ │ - var resolution, resolutions = this.baseLayer.resolutions, │ │ │ │ │ - maxResolution = this.getMaxExtent().getWidth() / this.size.w; │ │ │ │ │ - if (this.getResolutionForZoom(zoom) > maxResolution) { │ │ │ │ │ - if (this.fractionalZoom) { │ │ │ │ │ - zoom = this.getZoomForResolution(maxResolution); │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = zoom | 0, ii = resolutions.length; i < ii; ++i) { │ │ │ │ │ - if (resolutions[i] <= maxResolution) { │ │ │ │ │ - zoom = i; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + intersect = geometry.intersects(this.components[i]); │ │ │ │ │ + if (intersect) { │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getMinZoom │ │ │ │ │ - * Returns the minimum zoom level for the current map view. If the base │ │ │ │ │ - * layer is configured with set to true, this will be the │ │ │ │ │ - * first zoom level that shows no more than one world width in the current │ │ │ │ │ - * map viewport. Components that rely on this value (e.g. zoom sliders) │ │ │ │ │ - * should also listen to the map's "updatesize" event and call this method │ │ │ │ │ - * in the "updatesize" listener. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} Minimum zoom level that shows a map not wider than its │ │ │ │ │ - * 's maxExtent. This is an Integer value, unless the map is │ │ │ │ │ - * configured with set to true. │ │ │ │ │ - */ │ │ │ │ │ - getMinZoom: function() { │ │ │ │ │ - return this.adjustZoom(0); │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * zoom - {Integer} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ + * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ + * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ + * be returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(lonlat, zoom, options) { │ │ │ │ │ - if (lonlat != null && !(lonlat instanceof OpenLayers.LonLat)) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lonlat); │ │ │ │ │ - } │ │ │ │ │ - if (!options) { │ │ │ │ │ - options = {}; │ │ │ │ │ - } │ │ │ │ │ - if (zoom != null) { │ │ │ │ │ - zoom = parseFloat(zoom); │ │ │ │ │ - if (!this.fractionalZoom) { │ │ │ │ │ - zoom = Math.round(zoom); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var requestedZoom = zoom; │ │ │ │ │ - zoom = this.adjustZoom(zoom); │ │ │ │ │ - if (zoom !== requestedZoom) { │ │ │ │ │ - // zoom was adjusted, so keep old lonlat to avoid panning │ │ │ │ │ - lonlat = this.getCenter(); │ │ │ │ │ - } │ │ │ │ │ - // dragging is false by default │ │ │ │ │ - var dragging = options.dragging || this.dragging; │ │ │ │ │ - // forceZoomChange is false by default │ │ │ │ │ - var forceZoomChange = options.forceZoomChange; │ │ │ │ │ - │ │ │ │ │ - if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) { │ │ │ │ │ - lonlat = this.maxExtent.getCenterLonLat(); │ │ │ │ │ - this.center = lonlat.clone(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.restrictedExtent != null) { │ │ │ │ │ - // In 3.0, decide if we want to change interpretation of maxExtent. │ │ │ │ │ - if (lonlat == null) { │ │ │ │ │ - lonlat = this.center; │ │ │ │ │ - } │ │ │ │ │ - if (zoom == null) { │ │ │ │ │ - zoom = this.getZoom(); │ │ │ │ │ - } │ │ │ │ │ - var resolution = this.getResolutionForZoom(zoom); │ │ │ │ │ - var extent = this.calculateBounds(lonlat, resolution); │ │ │ │ │ - if (!this.restrictedExtent.containsBounds(extent)) { │ │ │ │ │ - var maxCenter = this.restrictedExtent.getCenterLonLat(); │ │ │ │ │ - if (extent.getWidth() > this.restrictedExtent.getWidth()) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(maxCenter.lon, lonlat.lat); │ │ │ │ │ - } else if (extent.left < this.restrictedExtent.left) { │ │ │ │ │ - lonlat = lonlat.add(this.restrictedExtent.left - │ │ │ │ │ - extent.left, 0); │ │ │ │ │ - } else if (extent.right > this.restrictedExtent.right) { │ │ │ │ │ - lonlat = lonlat.add(this.restrictedExtent.right - │ │ │ │ │ - extent.right, 0); │ │ │ │ │ - } │ │ │ │ │ - if (extent.getHeight() > this.restrictedExtent.getHeight()) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lonlat.lon, maxCenter.lat); │ │ │ │ │ - } else if (extent.bottom < this.restrictedExtent.bottom) { │ │ │ │ │ - lonlat = lonlat.add(0, this.restrictedExtent.bottom - │ │ │ │ │ - extent.bottom); │ │ │ │ │ - } else if (extent.top > this.restrictedExtent.top) { │ │ │ │ │ - lonlat = lonlat.add(0, this.restrictedExtent.top - │ │ │ │ │ - extent.top); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + var vertices = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + Array.prototype.push.apply( │ │ │ │ │ + vertices, this.components[i].getVertices(nodes) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return vertices; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var zoomChanged = forceZoomChange || ( │ │ │ │ │ - (this.isValidZoomLevel(zoom)) && │ │ │ │ │ - (zoom != this.getZoom())); │ │ │ │ │ │ │ │ │ │ - var centerChanged = (this.isValidLonLat(lonlat)) && │ │ │ │ │ - (!lonlat.equals(this.center)); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // if neither center nor zoom will change, no need to do anything │ │ │ │ │ - if (zoomChanged || centerChanged || dragging) { │ │ │ │ │ - dragging || this.events.triggerEvent("movestart", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - }); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - if (centerChanged) { │ │ │ │ │ - if (!zoomChanged && this.center) { │ │ │ │ │ - // if zoom hasnt changed, just slide layerContainer │ │ │ │ │ - // (must be done before setting this.center to new value) │ │ │ │ │ - this.centerLayerContainer(lonlat); │ │ │ │ │ - } │ │ │ │ │ - this.center = lonlat.clone(); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - var res = zoomChanged ? │ │ │ │ │ - this.getResolutionForZoom(zoom) : this.getResolution(); │ │ │ │ │ - // (re)set the layerContainerDiv's location │ │ │ │ │ - if (zoomChanged || this.layerContainerOrigin == null) { │ │ │ │ │ - this.layerContainerOrigin = this.getCachedCenter(); │ │ │ │ │ - this.layerContainerOriginPx.x = 0; │ │ │ │ │ - this.layerContainerOriginPx.y = 0; │ │ │ │ │ - this.applyTransform(); │ │ │ │ │ - var maxExtent = this.getMaxExtent({ │ │ │ │ │ - restricted: true │ │ │ │ │ - }); │ │ │ │ │ - var maxExtentCenter = maxExtent.getCenterLonLat(); │ │ │ │ │ - var lonDelta = this.center.lon - maxExtentCenter.lon; │ │ │ │ │ - var latDelta = maxExtentCenter.lat - this.center.lat; │ │ │ │ │ - var extentWidth = Math.round(maxExtent.getWidth() / res); │ │ │ │ │ - var extentHeight = Math.round(maxExtent.getHeight() / res); │ │ │ │ │ - this.minPx = { │ │ │ │ │ - x: (this.size.w - extentWidth) / 2 - lonDelta / res, │ │ │ │ │ - y: (this.size.h - extentHeight) / 2 - latDelta / res │ │ │ │ │ - }; │ │ │ │ │ - this.maxPx = { │ │ │ │ │ - x: this.minPx.x + Math.round(maxExtent.getWidth() / res), │ │ │ │ │ - y: this.minPx.y + Math.round(maxExtent.getHeight() / res) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * MultiPoint is a collection of Points. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.MultiPoint = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ - if (zoomChanged) { │ │ │ │ │ - this.zoom = zoom; │ │ │ │ │ - this.resolution = res; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null value means the │ │ │ │ │ + * component types are not restricted. │ │ │ │ │ + */ │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ - var bounds = this.getExtent(); │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * Create a new MultiPoint Geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - //send the move call to the baselayer and all the overlays │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addPoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be added │ │ │ │ │ + * index - {Integer} Optional index │ │ │ │ │ + */ │ │ │ │ │ + addPoint: function(point, index) { │ │ │ │ │ + this.addComponent(point, index); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.baseLayer.visibility) { │ │ │ │ │ - this.baseLayer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ - options.dragging || this.baseLayer.events.triggerEvent( │ │ │ │ │ - "moveend", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removePoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be removed │ │ │ │ │ + */ │ │ │ │ │ + removePoint: function(point) { │ │ │ │ │ + this.removeComponent(point); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - bounds = this.baseLayer.getExtent(); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Curve.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer !== this.baseLayer && !layer.isBaseLayer) { │ │ │ │ │ - var inRange = layer.calculateInRange(); │ │ │ │ │ - if (layer.inRange != inRange) { │ │ │ │ │ - // the inRange property has changed. If the layer is │ │ │ │ │ - // no longer in range, we turn it off right away. If │ │ │ │ │ - // the layer is no longer out of range, the moveTo │ │ │ │ │ - // call below will turn on the layer. │ │ │ │ │ - layer.inRange = inRange; │ │ │ │ │ - if (!inRange) { │ │ │ │ │ - layer.display(false); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: layer, │ │ │ │ │ - property: "visibility" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (inRange && layer.visibility) { │ │ │ │ │ - layer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ - options.dragging || layer.events.triggerEvent( │ │ │ │ │ - "moveend", { │ │ │ │ │ - zoomChanged: zoomChanged │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - this.events.triggerEvent("move"); │ │ │ │ │ - dragging || this.events.triggerEvent("moveend"); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (zoomChanged) { │ │ │ │ │ - //redraw popups │ │ │ │ │ - for (var i = 0, len = this.popups.length; i < len; i++) { │ │ │ │ │ - this.popups[i].updatePosition(); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("zoomend"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.Curve │ │ │ │ │ + * A Curve is a MultiPoint, whose points are assumed to be connected. To │ │ │ │ │ + * this end, we provide a "getLength()" function, which iterates through │ │ │ │ │ + * the points, summing the distances between them. │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: centerLayerContainer │ │ │ │ │ - * This function takes care to recenter the layerContainerDiv. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: componentTypes │ │ │ │ │ + * {Array(String)} An array of class names representing the types of │ │ │ │ │ + * components that the collection can include. A null │ │ │ │ │ + * value means the component types are not restricted. │ │ │ │ │ */ │ │ │ │ │ - centerLayerContainer: function(lonlat) { │ │ │ │ │ - var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin); │ │ │ │ │ - var newPx = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ - │ │ │ │ │ - if ((originPx != null) && (newPx != null)) { │ │ │ │ │ - var oldLeft = this.layerContainerOriginPx.x; │ │ │ │ │ - var oldTop = this.layerContainerOriginPx.y; │ │ │ │ │ - var newLeft = Math.round(originPx.x - newPx.x); │ │ │ │ │ - var newTop = Math.round(originPx.y - newPx.y); │ │ │ │ │ - this.applyTransform( │ │ │ │ │ - (this.layerContainerOriginPx.x = newLeft), │ │ │ │ │ - (this.layerContainerOriginPx.y = newTop)); │ │ │ │ │ - var dx = oldLeft - newLeft; │ │ │ │ │ - var dy = oldTop - newTop; │ │ │ │ │ - this.minPx.x -= dx; │ │ │ │ │ - this.maxPx.x -= dx; │ │ │ │ │ - this.minPx.y -= dy; │ │ │ │ │ - this.maxPx.y -= dy; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isValidZoomLevel │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoomLevel - {Integer} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the zoom level passed in is non-null and │ │ │ │ │ - * within the min/max range of zoom levels. │ │ │ │ │ + * point - {Array()} │ │ │ │ │ */ │ │ │ │ │ - isValidZoomLevel: function(zoomLevel) { │ │ │ │ │ - return ((zoomLevel != null) && │ │ │ │ │ - (zoomLevel >= 0) && │ │ │ │ │ - (zoomLevel < this.getNumZoomLevels())); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isValidLonLat │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the lonlat passed in is non-null and within │ │ │ │ │ - * the maxExtent bounds │ │ │ │ │ + * {Float} The length of the curve │ │ │ │ │ */ │ │ │ │ │ - isValidLonLat: function(lonlat) { │ │ │ │ │ - var valid = false; │ │ │ │ │ - if (lonlat != null) { │ │ │ │ │ - var maxExtent = this.getMaxExtent(); │ │ │ │ │ - var worldBounds = this.baseLayer.wrapDateLine && maxExtent; │ │ │ │ │ - valid = maxExtent.containsLonLat(lonlat, { │ │ │ │ │ - worldBounds: worldBounds │ │ │ │ │ - }); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + if (this.components && (this.components.length > 1)) { │ │ │ │ │ + for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i - 1].distanceTo(this.components[i]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return valid; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Layer Options */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Accessor functions to Layer Options parameters */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getProjection │ │ │ │ │ - * This method returns a string representing the projection. In │ │ │ │ │ - * the case of projection support, this will be the srsCode which │ │ │ │ │ - * is loaded -- otherwise it will simply be the string value that │ │ │ │ │ - * was passed to the projection at startup. │ │ │ │ │ + * APIMethod: getGeodesicLength │ │ │ │ │ + * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ * │ │ │ │ │ - * FIXME: In 3.0, we will remove getProjectionObject, and instead │ │ │ │ │ - * return a Projection object from this function. │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The Projection string from the base layer or null. │ │ │ │ │ - */ │ │ │ │ │ - getProjection: function() { │ │ │ │ │ - var projection = this.getProjectionObject(); │ │ │ │ │ - return projection ? projection.getCode() : null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getProjectionObject │ │ │ │ │ - * Returns the projection obect from the baselayer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The Projection of the base layer. │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - getProjectionObject: function() { │ │ │ │ │ - var projection = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - projection = this.baseLayer.projection; │ │ │ │ │ + getGeodesicLength: function(projection) { │ │ │ │ │ + var geom = this; // so we can work with a clone if needed │ │ │ │ │ + if (projection) { │ │ │ │ │ + var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + if (!gg.equals(projection)) { │ │ │ │ │ + geom = this.clone().transform(projection, gg); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return projection; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getMaxResolution │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The Map's Maximum Resolution │ │ │ │ │ - */ │ │ │ │ │ - getMaxResolution: function() { │ │ │ │ │ - var maxResolution = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - maxResolution = this.baseLayer.maxResolution; │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + if (geom.components && (geom.components.length > 1)) { │ │ │ │ │ + var p1, p2; │ │ │ │ │ + for (var i = 1, len = geom.components.length; i < len; i++) { │ │ │ │ │ + p1 = geom.components[i - 1]; │ │ │ │ │ + p2 = geom.components[i]; │ │ │ │ │ + // this returns km and requires lon/lat properties │ │ │ │ │ + length += OpenLayers.Util.distVincenty({ │ │ │ │ │ + lon: p1.x, │ │ │ │ │ + lat: p1.y │ │ │ │ │ + }, { │ │ │ │ │ + lon: p2.x, │ │ │ │ │ + lat: p2.y │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return maxResolution; │ │ │ │ │ + // convert to m │ │ │ │ │ + return length * 1000; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/LineString.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Geometry.LineString │ │ │ │ │ + * A LineString is a Curve which, once two points have been added to it, can │ │ │ │ │ + * never be less than two points long. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getMaxExtent │ │ │ │ │ + * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ + * Create a new LineString geometry │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Allowed Options: │ │ │ │ │ - * restricted - {Boolean} If true, returns restricted extent (if it is │ │ │ │ │ - * available.) │ │ │ │ │ + * points - {Array()} An array of points used to │ │ │ │ │ + * generate the linestring │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The maxExtent property as set on the current │ │ │ │ │ - * baselayer, unless the 'restricted' option is set, in which case │ │ │ │ │ - * the 'restrictedExtent' option from the map is returned (if it │ │ │ │ │ - * is set). │ │ │ │ │ */ │ │ │ │ │ - getMaxExtent: function(options) { │ │ │ │ │ - var maxExtent = null; │ │ │ │ │ - if (options && options.restricted && this.restrictedExtent) { │ │ │ │ │ - maxExtent = this.restrictedExtent; │ │ │ │ │ - } else if (this.baseLayer != null) { │ │ │ │ │ - maxExtent = this.baseLayer.maxExtent; │ │ │ │ │ - } │ │ │ │ │ - return maxExtent; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getNumZoomLevels │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The total number of zoom levels that can be displayed by the │ │ │ │ │ - * current baseLayer. │ │ │ │ │ + * APIMethod: removeComponent │ │ │ │ │ + * Only allows removal of a point if there are three or more points in │ │ │ │ │ + * the linestring. (otherwise the result would be just a single point) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} The point to be removed │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - getNumZoomLevels: function() { │ │ │ │ │ - var numZoomLevels = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - numZoomLevels = this.baseLayer.numZoomLevels; │ │ │ │ │ + removeComponent: function(point) { │ │ │ │ │ + var removed = this.components && (this.components.length > 2); │ │ │ │ │ + if (removed) { │ │ │ │ │ + OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ } │ │ │ │ │ - return numZoomLevels; │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions, all publicly exposed */ │ │ │ │ │ - /* in the API?, are all merely wrappers to the */ │ │ │ │ │ - /* the same calls on whatever layer is set as */ │ │ │ │ │ - /* the current base layer */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Test for instersection between two geometries. This is a cheapo │ │ │ │ │ + * implementation of the Bently-Ottmann algorigithm. It doesn't │ │ │ │ │ + * really keep track of a sweep line data structure. It is closer │ │ │ │ │ + * to the brute force method, except that segments are sorted and │ │ │ │ │ + * potential intersections are only calculated when bounding boxes │ │ │ │ │ + * intersect. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Boolean} The input geometry intersects this geometry. │ │ │ │ │ */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - var extent = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - extent = this.baseLayer.getExtent(); │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + var type = geometry.CLASS_NAME; │ │ │ │ │ + if (type == "OpenLayers.Geometry.LineString" || │ │ │ │ │ + type == "OpenLayers.Geometry.LinearRing" || │ │ │ │ │ + type == "OpenLayers.Geometry.Point") { │ │ │ │ │ + var segs1 = this.getSortedSegments(); │ │ │ │ │ + var segs2; │ │ │ │ │ + if (type == "OpenLayers.Geometry.Point") { │ │ │ │ │ + segs2 = [{ │ │ │ │ │ + x1: geometry.x, │ │ │ │ │ + y1: geometry.y, │ │ │ │ │ + x2: geometry.x, │ │ │ │ │ + y2: geometry.y │ │ │ │ │ + }]; │ │ │ │ │ + } else { │ │ │ │ │ + segs2 = geometry.getSortedSegments(); │ │ │ │ │ + } │ │ │ │ │ + var seg1, seg1x1, seg1x2, seg1y1, seg1y2, │ │ │ │ │ + seg2, seg2y1, seg2y2; │ │ │ │ │ + // sweep right │ │ │ │ │ + outer: for (var i = 0, len = segs1.length; i < len; ++i) { │ │ │ │ │ + seg1 = segs1[i]; │ │ │ │ │ + seg1x1 = seg1.x1; │ │ │ │ │ + seg1x2 = seg1.x2; │ │ │ │ │ + seg1y1 = seg1.y1; │ │ │ │ │ + seg1y2 = seg1.y2; │ │ │ │ │ + inner: for (var j = 0, jlen = segs2.length; j < jlen; ++j) { │ │ │ │ │ + seg2 = segs2[j]; │ │ │ │ │ + if (seg2.x1 > seg1x2) { │ │ │ │ │ + // seg1 still left of seg2 │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + if (seg2.x2 < seg1x1) { │ │ │ │ │ + // seg2 still left of seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + seg2y1 = seg2.y1; │ │ │ │ │ + seg2y2 = seg2.y2; │ │ │ │ │ + if (Math.min(seg2y1, seg2y2) > Math.max(seg1y1, seg1y2)) { │ │ │ │ │ + // seg2 above seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (Math.max(seg2y1, seg2y2) < Math.min(seg1y1, seg1y2)) { │ │ │ │ │ + // seg2 below seg1 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Geometry.segmentsIntersect(seg1, seg2)) { │ │ │ │ │ + intersect = true; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ } │ │ │ │ │ - return extent; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ - * │ │ │ │ │ + * Method: getSortedSegments │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The current resolution of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Array} An array of segment objects. Segment objects have properties │ │ │ │ │ + * x1, y1, x2, and y2. The start point is represented by x1 and y1. │ │ │ │ │ + * The end point is represented by x2 and y2. Start and end are │ │ │ │ │ + * ordered so that x1 < x2. │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var resolution = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - resolution = this.baseLayer.getResolution(); │ │ │ │ │ - } else if (this.allOverlays === true && this.layers.length > 0) { │ │ │ │ │ - // while adding the 1st layer to the map in allOverlays mode, │ │ │ │ │ - // this.baseLayer is not set yet when we need the resolution │ │ │ │ │ - // for calculateInRange. │ │ │ │ │ - resolution = this.layers[0].getResolution(); │ │ │ │ │ + getSortedSegments: function() { │ │ │ │ │ + var numSeg = this.components.length - 1; │ │ │ │ │ + var segments = new Array(numSeg), │ │ │ │ │ + point1, point2; │ │ │ │ │ + for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ + point1 = this.components[i]; │ │ │ │ │ + point2 = this.components[i + 1]; │ │ │ │ │ + if (point1.x < point2.x) { │ │ │ │ │ + segments[i] = { │ │ │ │ │ + x1: point1.x, │ │ │ │ │ + y1: point1.y, │ │ │ │ │ + x2: point2.x, │ │ │ │ │ + y2: point2.y │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + segments[i] = { │ │ │ │ │ + x1: point2.x, │ │ │ │ │ + y1: point2.y, │ │ │ │ │ + x2: point1.x, │ │ │ │ │ + y2: point1.y │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getUnits │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The current units of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getUnits: function() { │ │ │ │ │ - var units = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - units = this.baseLayer.units; │ │ │ │ │ + // more efficient to define this somewhere static │ │ │ │ │ + function byX1(seg1, seg2) { │ │ │ │ │ + return seg1.x1 - seg2.x1; │ │ │ │ │ } │ │ │ │ │ - return units; │ │ │ │ │ + return segments.sort(byX1); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getScale │ │ │ │ │ - * │ │ │ │ │ + * Method: splitWithSegment │ │ │ │ │ + * Split this geometry with the given segment. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * seg - {Object} An object with x1, y1, x2, and y2 properties referencing │ │ │ │ │ + * segment endpoint coordinates. │ │ │ │ │ + * options - {Object} Properties of this object will be used to determine │ │ │ │ │ + * how the split is conducted. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ + * true. If false, a vertex on the source segment must be within the │ │ │ │ │ + * tolerance distance of the intersection to be considered a split. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ + * within the tolerance distance of one of the source segment's │ │ │ │ │ + * endpoints will be assumed to occur at the endpoint. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The current scale denominator of the map. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ + * {Object} An object with *lines* and *points* properties. If the given │ │ │ │ │ + * segment intersects this linestring, the lines array will reference │ │ │ │ │ + * geometries that result from the split. The points array will contain │ │ │ │ │ + * all intersection points. Intersection points are sorted along the │ │ │ │ │ + * segment (in order from x1,y1 to x2,y2). │ │ │ │ │ */ │ │ │ │ │ - getScale: function() { │ │ │ │ │ - var scale = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - var res = this.getResolution(); │ │ │ │ │ - var units = this.baseLayer.units; │ │ │ │ │ - scale = OpenLayers.Util.getScaleFromResolution(res, units); │ │ │ │ │ + splitWithSegment: function(seg, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var tolerance = options && options.tolerance; │ │ │ │ │ + var lines = []; │ │ │ │ │ + var verts = this.getVertices(); │ │ │ │ │ + var points = []; │ │ │ │ │ + var intersections = []; │ │ │ │ │ + var split = false; │ │ │ │ │ + var vert1, vert2, point; │ │ │ │ │ + var node, vertex, target; │ │ │ │ │ + var interOptions = { │ │ │ │ │ + point: true, │ │ │ │ │ + tolerance: tolerance │ │ │ │ │ + }; │ │ │ │ │ + var result = null; │ │ │ │ │ + for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ + vert1 = verts[i]; │ │ │ │ │ + points.push(vert1.clone()); │ │ │ │ │ + vert2 = verts[i + 1]; │ │ │ │ │ + target = { │ │ │ │ │ + x1: vert1.x, │ │ │ │ │ + y1: vert1.y, │ │ │ │ │ + x2: vert2.x, │ │ │ │ │ + y2: vert2.y │ │ │ │ │ + }; │ │ │ │ │ + point = OpenLayers.Geometry.segmentsIntersect( │ │ │ │ │ + seg, target, interOptions │ │ │ │ │ + ); │ │ │ │ │ + if (point instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + if ((point.x === seg.x1 && point.y === seg.y1) || │ │ │ │ │ + (point.x === seg.x2 && point.y === seg.y2) || │ │ │ │ │ + point.equals(vert1) || point.equals(vert2)) { │ │ │ │ │ + vertex = true; │ │ │ │ │ + } else { │ │ │ │ │ + vertex = false; │ │ │ │ │ + } │ │ │ │ │ + if (vertex || edge) { │ │ │ │ │ + // push intersections different than the previous │ │ │ │ │ + if (!point.equals(intersections[intersections.length - 1])) { │ │ │ │ │ + intersections.push(point.clone()); │ │ │ │ │ + } │ │ │ │ │ + if (i === 0) { │ │ │ │ │ + if (point.equals(vert1)) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (point.equals(vert2)) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + split = true; │ │ │ │ │ + if (!point.equals(vert1)) { │ │ │ │ │ + points.push(point); │ │ │ │ │ + } │ │ │ │ │ + lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + points = [point.clone()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return scale; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForExtent │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} A suitable zoom level for the specified bounds. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForExtent: function(bounds, closest) { │ │ │ │ │ - var zoom = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - zoom = this.baseLayer.getZoomForExtent(bounds, closest); │ │ │ │ │ + if (split) { │ │ │ │ │ + points.push(vert2.clone()); │ │ │ │ │ + lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} A suitable resolution for the specified zoom. If no baselayer │ │ │ │ │ - * is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getResolutionForZoom: function(zoom) { │ │ │ │ │ - var resolution = null; │ │ │ │ │ - if (this.baseLayer) { │ │ │ │ │ - resolution = this.baseLayer.getResolutionForZoom(zoom); │ │ │ │ │ + if (intersections.length > 0) { │ │ │ │ │ + // sort intersections along segment │ │ │ │ │ + var xDir = seg.x1 < seg.x2 ? 1 : -1; │ │ │ │ │ + var yDir = seg.y1 < seg.y2 ? 1 : -1; │ │ │ │ │ + result = { │ │ │ │ │ + lines: lines, │ │ │ │ │ + points: intersections.sort(function(p1, p2) { │ │ │ │ │ + return (xDir * p1.x - xDir * p2.x) || (yDir * p1.y - yDir * p2.y); │ │ │ │ │ + }) │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ - return resolution; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getZoomForResolution │ │ │ │ │ + * Method: split │ │ │ │ │ + * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * resolution - {Float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ - * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ - * resolution is actually smaller than we would have desired (if this │ │ │ │ │ - * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ - * the returned zoom index might not actually contain the entire │ │ │ │ │ - * extent specified... but it'll be close). │ │ │ │ │ - * Default is false. │ │ │ │ │ + * target - {} The target geometry. │ │ │ │ │ + * options - {Object} Properties of this object will be used to determine │ │ │ │ │ + * how the split is conducted. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ + * geometry. Default is false. │ │ │ │ │ + * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ + * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ + * distance of the intersection to be considered a split. │ │ │ │ │ + * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ + * within the tolerance distance of an existing vertex on the source │ │ │ │ │ + * will be assumed to occur at the vertex. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Integer} A suitable zoom level for the specified resolution. │ │ │ │ │ - * If no baselayer is set, returns null. │ │ │ │ │ - */ │ │ │ │ │ - getZoomForResolution: function(resolution, closest) { │ │ │ │ │ - var zoom = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - zoom = this.baseLayer.getZoomForResolution(resolution, closest); │ │ │ │ │ - } │ │ │ │ │ - return zoom; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Zooming Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions, all publicly exposed */ │ │ │ │ │ - /* in the API, are all merely wrappers to the */ │ │ │ │ │ - /* the setCenter() function */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomTo │ │ │ │ │ - * Zoom to a specific zoom level. Zooming will be animated unless the map │ │ │ │ │ - * is configured with {zoomMethod: null}. To zoom without animation, use │ │ │ │ │ - * without a lonlat argument. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * zoom - {Integer} │ │ │ │ │ + * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ + * result from splitting the target with the source geometry. The │ │ │ │ │ + * source and target geometry will remain unmodified. If no split │ │ │ │ │ + * results, null will be returned. If mutual is true and a split │ │ │ │ │ + * results, return will be an array of two arrays - the first will be │ │ │ │ │ + * all geometries that result from splitting the source geometry and │ │ │ │ │ + * the second will be all geometries that result from splitting the │ │ │ │ │ + * target geometry. │ │ │ │ │ */ │ │ │ │ │ - zoomTo: function(zoom, xy) { │ │ │ │ │ - // non-API arguments: │ │ │ │ │ - // xy - {} optional zoom origin │ │ │ │ │ - │ │ │ │ │ - var map = this; │ │ │ │ │ - if (map.isValidZoomLevel(zoom)) { │ │ │ │ │ - if (map.baseLayer.wrapDateLine) { │ │ │ │ │ - zoom = map.adjustZoom(zoom); │ │ │ │ │ - } │ │ │ │ │ - if (map.zoomTween) { │ │ │ │ │ - var currentRes = map.getResolution(), │ │ │ │ │ - targetRes = map.getResolutionForZoom(zoom), │ │ │ │ │ - start = { │ │ │ │ │ - scale: 1 │ │ │ │ │ - }, │ │ │ │ │ - end = { │ │ │ │ │ - scale: currentRes / targetRes │ │ │ │ │ - }; │ │ │ │ │ - if (map.zoomTween.playing && map.zoomTween.duration < 3 * map.zoomDuration) { │ │ │ │ │ - // update the end scale, and reuse the running zoomTween │ │ │ │ │ - map.zoomTween.finish = { │ │ │ │ │ - scale: map.zoomTween.finish.scale * end.scale │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - if (!xy) { │ │ │ │ │ - var size = map.getSize(); │ │ │ │ │ - xy = { │ │ │ │ │ - x: size.w / 2, │ │ │ │ │ - y: size.h / 2 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - map.zoomTween.start(start, end, map.zoomDuration, { │ │ │ │ │ - minFrameRate: 50, // don't spend much time zooming │ │ │ │ │ - callbacks: { │ │ │ │ │ - eachStep: function(data) { │ │ │ │ │ - var containerOrigin = map.layerContainerOriginPx, │ │ │ │ │ - scale = data.scale, │ │ │ │ │ - dx = ((scale - 1) * (containerOrigin.x - xy.x)) | 0, │ │ │ │ │ - dy = ((scale - 1) * (containerOrigin.y - xy.y)) | 0; │ │ │ │ │ - map.applyTransform(containerOrigin.x + dx, containerOrigin.y + dy, scale); │ │ │ │ │ - }, │ │ │ │ │ - done: function(data) { │ │ │ │ │ - map.applyTransform(); │ │ │ │ │ - var resolution = map.getResolution() / data.scale, │ │ │ │ │ - zoom = map.getZoomForResolution(resolution, true) │ │ │ │ │ - map.moveTo(map.getZoomTargetCenter(xy, resolution), zoom, true); │ │ │ │ │ + split: function(target, options) { │ │ │ │ │ + var results = null; │ │ │ │ │ + var mutual = options && options.mutual; │ │ │ │ │ + var sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ + if (target instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ + var verts = this.getVertices(); │ │ │ │ │ + var vert1, vert2, seg, splits, lines, point; │ │ │ │ │ + var points = []; │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ + vert1 = verts[i]; │ │ │ │ │ + vert2 = verts[i + 1]; │ │ │ │ │ + seg = { │ │ │ │ │ + x1: vert1.x, │ │ │ │ │ + y1: vert1.y, │ │ │ │ │ + x2: vert2.x, │ │ │ │ │ + y2: vert2.y │ │ │ │ │ + }; │ │ │ │ │ + targetParts = targetParts || [target]; │ │ │ │ │ + if (mutual) { │ │ │ │ │ + points.push(vert1.clone()); │ │ │ │ │ + } │ │ │ │ │ + for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ + splits = targetParts[j].splitWithSegment(seg, options); │ │ │ │ │ + if (splits) { │ │ │ │ │ + // splice in new features │ │ │ │ │ + lines = splits.lines; │ │ │ │ │ + if (lines.length > 0) { │ │ │ │ │ + lines.unshift(j, 1); │ │ │ │ │ + Array.prototype.splice.apply(targetParts, lines); │ │ │ │ │ + j += lines.length - 2; │ │ │ │ │ + } │ │ │ │ │ + if (mutual) { │ │ │ │ │ + for (var k = 0, len = splits.points.length; k < len; ++k) { │ │ │ │ │ + point = splits.points[k]; │ │ │ │ │ + if (!point.equals(vert1)) { │ │ │ │ │ + points.push(point); │ │ │ │ │ + sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + if (point.equals(vert2)) { │ │ │ │ │ + points = []; │ │ │ │ │ + } else { │ │ │ │ │ + points = [point.clone()]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - var center = xy ? │ │ │ │ │ - map.getZoomTargetCenter(xy, map.getResolutionForZoom(zoom)) : │ │ │ │ │ - null; │ │ │ │ │ - map.setCenter(center, zoom); │ │ │ │ │ } │ │ │ │ │ + if (mutual && sourceParts.length > 0 && points.length > 0) { │ │ │ │ │ + points.push(vert2.clone()); │ │ │ │ │ + sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + results = target.splitWith(this, options); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomIn │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomIn: function() { │ │ │ │ │ - this.zoomTo(this.getZoom() + 1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomOut │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomOut: function() { │ │ │ │ │ - this.zoomTo(this.getZoom() - 1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToExtent │ │ │ │ │ - * Zoom to the passed in bounds, recenter │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {|Array} If provided as an array, the array │ │ │ │ │ - * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomToExtent: function(bounds, closest) { │ │ │ │ │ - if (!(bounds instanceof OpenLayers.Bounds)) { │ │ │ │ │ - bounds = new OpenLayers.Bounds(bounds); │ │ │ │ │ + if (targetParts && targetParts.length > 1) { │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + targetParts = []; │ │ │ │ │ } │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - if (this.baseLayer.wrapDateLine) { │ │ │ │ │ - var maxExtent = this.getMaxExtent(); │ │ │ │ │ - │ │ │ │ │ - //fix straddling bounds (in the case of a bbox that straddles the │ │ │ │ │ - // dateline, it's left and right boundaries will appear backwards. │ │ │ │ │ - // we fix this by allowing a right value that is greater than the │ │ │ │ │ - // max value at the dateline -- this allows us to pass a valid │ │ │ │ │ - // bounds to calculate zoom) │ │ │ │ │ - // │ │ │ │ │ - bounds = bounds.clone(); │ │ │ │ │ - while (bounds.right < bounds.left) { │ │ │ │ │ - bounds.right += maxExtent.getWidth(); │ │ │ │ │ + if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + } else { │ │ │ │ │ + sourceParts = []; │ │ │ │ │ + } │ │ │ │ │ + if (targetSplit || sourceSplit) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + results = [sourceParts, targetParts]; │ │ │ │ │ + } else { │ │ │ │ │ + results = targetParts; │ │ │ │ │ } │ │ │ │ │ - //if the bounds was straddling (see above), then the center point │ │ │ │ │ - // we got from it was wrong. So we take our new bounds and ask it │ │ │ │ │ - // for the center. │ │ │ │ │ - // │ │ │ │ │ - center = bounds.getCenterLonLat().wrapDateLine(maxExtent); │ │ │ │ │ } │ │ │ │ │ - this.setCenter(center, this.getZoomForExtent(bounds, closest)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToMaxExtent │ │ │ │ │ - * Zoom to the full extent and recenter. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Allowed Options: │ │ │ │ │ - * restricted - {Boolean} True to zoom to restricted extent if it is │ │ │ │ │ - * set. Defaults to true. │ │ │ │ │ - */ │ │ │ │ │ - zoomToMaxExtent: function(options) { │ │ │ │ │ - //restricted is true by default │ │ │ │ │ - var restricted = (options) ? options.restricted : true; │ │ │ │ │ - │ │ │ │ │ - var maxExtent = this.getMaxExtent({ │ │ │ │ │ - 'restricted': restricted │ │ │ │ │ - }); │ │ │ │ │ - this.zoomToExtent(maxExtent); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: zoomToScale │ │ │ │ │ - * Zoom to a specified scale │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified scale. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - zoomToScale: function(scale, closest) { │ │ │ │ │ - var res = OpenLayers.Util.getResolutionFromScale(scale, │ │ │ │ │ - this.baseLayer.units); │ │ │ │ │ - │ │ │ │ │ - var halfWDeg = (this.size.w * res) / 2; │ │ │ │ │ - var halfHDeg = (this.size.h * res) / 2; │ │ │ │ │ - var center = this.getCachedCenter(); │ │ │ │ │ - │ │ │ │ │ - var extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ - center.lat - halfHDeg, │ │ │ │ │ - center.lon + halfWDeg, │ │ │ │ │ - center.lat + halfHDeg); │ │ │ │ │ - this.zoomToExtent(extent, closest); │ │ │ │ │ + return results; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Translation Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions translate between */ │ │ │ │ │ - /* LonLat, LayerPx, and ViewPortPx */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: LonLat <-> ViewPortPx │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromViewPortPx │ │ │ │ │ - * │ │ │ │ │ + * Method: splitWith │ │ │ │ │ + * Split this geometry (the target) with the given geometry (the source). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ - * an object with a 'x' │ │ │ │ │ - * and 'y' properties. │ │ │ │ │ + * 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: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ - * port , translated into lon/lat │ │ │ │ │ - * by the current base layer. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ - } │ │ │ │ │ - return lonlat; │ │ │ │ │ - }, │ │ │ │ │ + splitWith: function(geometry, options) { │ │ │ │ │ + return geometry.split(this, options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * , translated into view port │ │ │ │ │ - * pixels by the current base layer. │ │ │ │ │ - */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ - var px = null; │ │ │ │ │ - if (this.baseLayer != null) { │ │ │ │ │ - px = this.baseLayer.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ - } │ │ │ │ │ - return px; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getZoomTargetCenter │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The zoom origin pixel location on the screen │ │ │ │ │ - * resolution - {Float} The resolution we want to get the center for │ │ │ │ │ + * 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: │ │ │ │ │ - * {} The location of the map center after the │ │ │ │ │ - * transformation described by the origin xy and the target resolution. │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getZoomTargetCenter: function(xy, resolution) { │ │ │ │ │ - var lonlat = null, │ │ │ │ │ - size = this.getSize(), │ │ │ │ │ - deltaX = size.w / 2 - xy.x, │ │ │ │ │ - deltaY = xy.y - size.h / 2, │ │ │ │ │ - zoomPoint = this.getLonLatFromPixel(xy); │ │ │ │ │ - if (zoomPoint) { │ │ │ │ │ - lonlat = new OpenLayers.LonLat( │ │ │ │ │ - zoomPoint.lon + deltaX * resolution, │ │ │ │ │ - zoomPoint.lat + deltaY * resolution │ │ │ │ │ - ); │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + var vertices; │ │ │ │ │ + if (nodes === true) { │ │ │ │ │ + vertices = [ │ │ │ │ │ + this.components[0], │ │ │ │ │ + this.components[this.components.length - 1] │ │ │ │ │ + ]; │ │ │ │ │ + } else if (nodes === false) { │ │ │ │ │ + vertices = this.components.slice(1, this.components.length - 1); │ │ │ │ │ + } else { │ │ │ │ │ + vertices = this.components.slice(); │ │ │ │ │ } │ │ │ │ │ - return lonlat; │ │ │ │ │ + return vertices; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // CONVENIENCE TRANSLATION FUNCTIONS FOR API │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLonLatFromPixel │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {|Object} An OpenLayers.Pixel or an object with │ │ │ │ │ - * a 'x' and 'y' properties. │ │ │ │ │ + * geometry - {} The target geometry. │ │ │ │ │ + * options - {Object} Optional properties for configuring the distance │ │ │ │ │ + * calculation. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ + * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ + * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ + * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ + * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ + * details cannot be returned. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat corresponding to the given │ │ │ │ │ - * OpenLayers.Pixel, translated into lon/lat by the │ │ │ │ │ - * current base layer │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromPixel: function(px) { │ │ │ │ │ - return this.getLonLatFromViewPortPx(px); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getPixelFromLonLat │ │ │ │ │ - * Returns a pixel location given a map location. The map location is │ │ │ │ │ - * translated to an integer pixel location (in viewport pixel │ │ │ │ │ - * coordinates) by the current base layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} A map location. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel corresponding to the │ │ │ │ │ - * translated into view port pixels by the current │ │ │ │ │ - * base layer. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - getPixelFromLonLat: function(lonlat) { │ │ │ │ │ - var px = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ - px.x = Math.round(px.x); │ │ │ │ │ - px.y = Math.round(px.y); │ │ │ │ │ - return px; │ │ │ │ │ + distanceTo: function(geometry, options) { │ │ │ │ │ + var edge = !(options && options.edge === false); │ │ │ │ │ + var details = edge && options && options.details; │ │ │ │ │ + var result, best = {}; │ │ │ │ │ + var min = Number.POSITIVE_INFINITY; │ │ │ │ │ + if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ + var segs = this.getSortedSegments(); │ │ │ │ │ + var x = geometry.x; │ │ │ │ │ + var y = geometry.y; │ │ │ │ │ + var seg; │ │ │ │ │ + for (var i = 0, len = segs.length; i < len; ++i) { │ │ │ │ │ + seg = segs[i]; │ │ │ │ │ + result = OpenLayers.Geometry.distanceToSegment(geometry, seg); │ │ │ │ │ + if (result.distance < min) { │ │ │ │ │ + min = result.distance; │ │ │ │ │ + best = result; │ │ │ │ │ + if (min === 0) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // if distance increases and we cross y0 to the right of x0, no need to keep looking. │ │ │ │ │ + if (seg.x2 > x && ((y > seg.y1 && y < seg.y2) || (y < seg.y1 && y > seg.y2))) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: best.distance, │ │ │ │ │ + x0: best.x, │ │ │ │ │ + y0: best.y, │ │ │ │ │ + x1: x, │ │ │ │ │ + y1: y │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + best = best.distance; │ │ │ │ │ + } │ │ │ │ │ + } else if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ + var segs0 = this.getSortedSegments(); │ │ │ │ │ + var segs1 = geometry.getSortedSegments(); │ │ │ │ │ + var seg0, seg1, intersection, x0, y0; │ │ │ │ │ + var len1 = segs1.length; │ │ │ │ │ + var interOptions = { │ │ │ │ │ + point: true │ │ │ │ │ + }; │ │ │ │ │ + outer: for (var i = 0, len = segs0.length; i < len; ++i) { │ │ │ │ │ + seg0 = segs0[i]; │ │ │ │ │ + x0 = seg0.x1; │ │ │ │ │ + y0 = seg0.y1; │ │ │ │ │ + for (var j = 0; j < len1; ++j) { │ │ │ │ │ + seg1 = segs1[j]; │ │ │ │ │ + intersection = OpenLayers.Geometry.segmentsIntersect(seg0, seg1, interOptions); │ │ │ │ │ + if (intersection) { │ │ │ │ │ + min = 0; │ │ │ │ │ + best = { │ │ │ │ │ + distance: 0, │ │ │ │ │ + x0: intersection.x, │ │ │ │ │ + y0: intersection.y, │ │ │ │ │ + x1: intersection.x, │ │ │ │ │ + y1: intersection.y │ │ │ │ │ + }; │ │ │ │ │ + break outer; │ │ │ │ │ + } else { │ │ │ │ │ + result = OpenLayers.Geometry.distanceToSegment({ │ │ │ │ │ + x: x0, │ │ │ │ │ + y: y0 │ │ │ │ │ + }, seg1); │ │ │ │ │ + if (result.distance < min) { │ │ │ │ │ + min = result.distance; │ │ │ │ │ + best = { │ │ │ │ │ + distance: min, │ │ │ │ │ + x0: x0, │ │ │ │ │ + y0: y0, │ │ │ │ │ + x1: result.x, │ │ │ │ │ + y1: result.y │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!details) { │ │ │ │ │ + best = best.distance; │ │ │ │ │ + } │ │ │ │ │ + if (min !== 0) { │ │ │ │ │ + // check the final vertex in this line's sorted segments │ │ │ │ │ + if (seg0) { │ │ │ │ │ + result = geometry.distanceTo( │ │ │ │ │ + new OpenLayers.Geometry.Point(seg0.x2, seg0.y2), │ │ │ │ │ + options │ │ │ │ │ + ); │ │ │ │ │ + var dist = details ? result.distance : result; │ │ │ │ │ + if (dist < min) { │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: min, │ │ │ │ │ + x0: result.x1, │ │ │ │ │ + y0: result.y1, │ │ │ │ │ + x1: result.x0, │ │ │ │ │ + y1: result.y0 │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + best = dist; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + best = geometry.distanceTo(this, options); │ │ │ │ │ + // swap since target comes from this line │ │ │ │ │ + if (details) { │ │ │ │ │ + best = { │ │ │ │ │ + distance: best.distance, │ │ │ │ │ + x0: best.x1, │ │ │ │ │ + y0: best.y1, │ │ │ │ │ + x1: best.x0, │ │ │ │ │ + y1: best.y0 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeodesicPixelSize │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: simplify │ │ │ │ │ + * This function will return a simplified LineString. │ │ │ │ │ + * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} The pixel to get the geodesic length for. If │ │ │ │ │ - * not provided, the center pixel of the map viewport will be used. │ │ │ │ │ - * │ │ │ │ │ + * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The geodesic size of the pixel in kilometers. │ │ │ │ │ + * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ */ │ │ │ │ │ - getGeodesicPixelSize: function(px) { │ │ │ │ │ - var lonlat = px ? this.getLonLatFromPixel(px) : ( │ │ │ │ │ - this.getCachedCenter() || new OpenLayers.LonLat(0, 0)); │ │ │ │ │ - var res = this.getResolution(); │ │ │ │ │ - var left = lonlat.add(-res / 2, 0); │ │ │ │ │ - var right = lonlat.add(res / 2, 0); │ │ │ │ │ - var bottom = lonlat.add(0, -res / 2); │ │ │ │ │ - var top = lonlat.add(0, res / 2); │ │ │ │ │ - var dest = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - var source = this.getProjectionObject() || dest; │ │ │ │ │ - if (!source.equals(dest)) { │ │ │ │ │ - left.transform(source, dest); │ │ │ │ │ - right.transform(source, dest); │ │ │ │ │ - bottom.transform(source, dest); │ │ │ │ │ - top.transform(source, dest); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return new OpenLayers.Size( │ │ │ │ │ - OpenLayers.Util.distVincenty(left, right), │ │ │ │ │ - OpenLayers.Util.distVincenty(bottom, top) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ + 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); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: ViewPortPx <-> LayerPx │ │ │ │ │ - // │ │ │ │ │ + /** │ │ │ │ │ + * Private function doing the Douglas-Peucker reduction │ │ │ │ │ + */ │ │ │ │ │ + var douglasPeuckerReduction = function(points, firstPoint, lastPoint, tolerance) { │ │ │ │ │ + var maxDistance = 0; │ │ │ │ │ + var indexFarthest = 0; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLayerPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layerPx - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Layer Pixel translated into ViewPort Pixel │ │ │ │ │ - * coordinates │ │ │ │ │ - */ │ │ │ │ │ - getViewPortPxFromLayerPx: function(layerPx) { │ │ │ │ │ - var viewPortPx = null; │ │ │ │ │ - if (layerPx != null) { │ │ │ │ │ - var dX = this.layerContainerOriginPx.x; │ │ │ │ │ - var dY = this.layerContainerOriginPx.y; │ │ │ │ │ - viewPortPx = layerPx.add(dX, dY); │ │ │ │ │ - } │ │ │ │ │ - return viewPortPx; │ │ │ │ │ - }, │ │ │ │ │ + for (var index = firstPoint, distance; index < lastPoint; index++) { │ │ │ │ │ + distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]); │ │ │ │ │ + if (distance > maxDistance) { │ │ │ │ │ + maxDistance = distance; │ │ │ │ │ + indexFarthest = index; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerPxFromViewPortPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} ViewPort Pixel translated into Layer Pixel │ │ │ │ │ - * coordinates │ │ │ │ │ - */ │ │ │ │ │ - getLayerPxFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var layerPx = null; │ │ │ │ │ - if (viewPortPx != null) { │ │ │ │ │ - var dX = -this.layerContainerOriginPx.x; │ │ │ │ │ - var dY = -this.layerContainerOriginPx.y; │ │ │ │ │ - layerPx = viewPortPx.add(dX, dY); │ │ │ │ │ - if (isNaN(layerPx.x) || isNaN(layerPx.y)) { │ │ │ │ │ - layerPx = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return layerPx; │ │ │ │ │ - }, │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: LonLat <-> LayerPx │ │ │ │ │ - // │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getLonLatFromLayerPx │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getLonLatFromLayerPx: function(px) { │ │ │ │ │ - //adjust for displacement of layerContainerDiv │ │ │ │ │ - px = this.getViewPortPxFromLayerPx(px); │ │ │ │ │ - return this.getLonLatFromViewPortPx(px); │ │ │ │ │ - }, │ │ │ │ │ + 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; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLayerPxFromLonLat │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} lonlat │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * , translated into layer pixels │ │ │ │ │ - * by the current base layer │ │ │ │ │ - */ │ │ │ │ │ - getLayerPxFromLonLat: function(lonlat) { │ │ │ │ │ - //adjust for displacement of layerContainerDiv │ │ │ │ │ - var px = this.getPixelFromLonLat(lonlat); │ │ │ │ │ - return this.getLayerPxFromViewPortPx(px); │ │ │ │ │ - }, │ │ │ │ │ + return height; │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: applyTransform │ │ │ │ │ - * Applies the given transform to the . This method has │ │ │ │ │ - * a 2-stage fallback from translate3d/scale3d via translate/scale to plain │ │ │ │ │ - * style.left/style.top, in which case no scaling is supported. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Number} x parameter for the translation. Defaults to the x value of │ │ │ │ │ - * the map's │ │ │ │ │ - * y - {Number} y parameter for the translation. Defaults to the y value of │ │ │ │ │ - * the map's │ │ │ │ │ - * scale - {Number} scale. Defaults to 1 if not provided. │ │ │ │ │ - */ │ │ │ │ │ - applyTransform: function(x, y, scale) { │ │ │ │ │ - scale = scale || 1; │ │ │ │ │ - var origin = this.layerContainerOriginPx, │ │ │ │ │ - needTransform = scale !== 1; │ │ │ │ │ - x = x || origin.x; │ │ │ │ │ - y = y || origin.y; │ │ │ │ │ + var firstPoint = 0; │ │ │ │ │ + var lastPoint = points.length - 1; │ │ │ │ │ + var pointIndexsToKeep = []; │ │ │ │ │ │ │ │ │ │ - var style = this.layerContainerDiv.style, │ │ │ │ │ - transform = this.applyTransform.transform, │ │ │ │ │ - template = this.applyTransform.template; │ │ │ │ │ + //Add the first and last index to the keepers │ │ │ │ │ + pointIndexsToKeep.push(firstPoint); │ │ │ │ │ + pointIndexsToKeep.push(lastPoint); │ │ │ │ │ │ │ │ │ │ - if (transform === undefined) { │ │ │ │ │ - transform = OpenLayers.Util.vendorPrefix.style('transform'); │ │ │ │ │ - this.applyTransform.transform = transform; │ │ │ │ │ - if (transform) { │ │ │ │ │ - // Try translate3d, but only if the viewPortDiv has a transform │ │ │ │ │ - // defined in a stylesheet │ │ │ │ │ - var computedStyle = OpenLayers.Element.getStyle(this.viewPortDiv, │ │ │ │ │ - OpenLayers.Util.vendorPrefix.css('transform')); │ │ │ │ │ - if (!computedStyle || computedStyle !== 'none') { │ │ │ │ │ - template = ['translate3d(', ',0) ', 'scale3d(', ',1)']; │ │ │ │ │ - style[transform] = [template[0], '0,0', template[1]].join(''); │ │ │ │ │ - } │ │ │ │ │ - // If no transform is defined in the stylesheet or translate3d │ │ │ │ │ - // does not stick, use translate and scale │ │ │ │ │ - if (!template || !~style[transform].indexOf(template[0])) { │ │ │ │ │ - template = ['translate(', ') ', 'scale(', ')']; │ │ │ │ │ - } │ │ │ │ │ - this.applyTransform.template = template; │ │ │ │ │ + //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); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - // If we do 3d transforms, we always want to use them. If we do 2d │ │ │ │ │ - // transforms, we only use them when we need to. │ │ │ │ │ - if (transform !== null && (template[0] === 'translate3d(' || needTransform === true)) { │ │ │ │ │ - // Our 2d transforms are combined with style.left and style.top, so │ │ │ │ │ - // adjust x and y values and set the origin as left and top │ │ │ │ │ - if (needTransform === true && template[0] === 'translate(') { │ │ │ │ │ - x -= origin.x; │ │ │ │ │ - y -= origin.y; │ │ │ │ │ - style.left = origin.x + 'px'; │ │ │ │ │ - style.top = origin.y + 'px'; │ │ │ │ │ + douglasPeuckerReduction(points, firstPoint, lastPoint, tolerance); │ │ │ │ │ + var returnPoints = []; │ │ │ │ │ + pointIndexsToKeep.sort(compareNumbers); │ │ │ │ │ + for (var index = 0; index < pointIndexsToKeep.length; index++) { │ │ │ │ │ + returnPoints.push(points[pointIndexsToKeep[index]]); │ │ │ │ │ } │ │ │ │ │ - style[transform] = [ │ │ │ │ │ - template[0], x, 'px,', y, 'px', template[1], │ │ │ │ │ - template[2], scale, ',', scale, template[3] │ │ │ │ │ - ].join(''); │ │ │ │ │ + return new OpenLayers.Geometry.LineString(returnPoints); │ │ │ │ │ + │ │ │ │ │ } else { │ │ │ │ │ - style.left = x + 'px'; │ │ │ │ │ - style.top = y + 'px'; │ │ │ │ │ - // We previously might have had needTransform, so remove transform │ │ │ │ │ - if (transform !== null) { │ │ │ │ │ - style[transform] = ''; │ │ │ │ │ - } │ │ │ │ │ + return this; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Map" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.LineString" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: TILE_WIDTH │ │ │ │ │ - * {Integer} 256 Default tile width (unless otherwise specified) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: TILE_HEIGHT │ │ │ │ │ - * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Icon.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/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.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.Geometry.MultiLineString │ │ │ │ │ + * A MultiLineString is a geometry with multiple │ │ │ │ │ + * components. │ │ │ │ │ * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} image url │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: offset │ │ │ │ │ - * {|Object} distance in pixels to offset the │ │ │ │ │ - * image when being rendered. An OpenLayers.Pixel or an object │ │ │ │ │ - * with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - offset: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: calculateOffset │ │ │ │ │ - * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ - */ │ │ │ │ │ - calculateOffset: null, │ │ │ │ │ +OpenLayers.Geometry.MultiLineString = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Geometry.Collection, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: imageDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - imageDiv: 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.LineString"], │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ - * with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - px: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Icon │ │ │ │ │ - * Creates an icon, which is an image tag in a div. │ │ │ │ │ - * │ │ │ │ │ - * url - {String} │ │ │ │ │ - * size - {|Object} An OpenLayers.Size or an │ │ │ │ │ - * object with a 'w' and 'h' │ │ │ │ │ - * properties. │ │ │ │ │ - * offset - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ - * object with a 'x' and 'y' │ │ │ │ │ - * properties. │ │ │ │ │ - * calculateOffset - {Function} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(url, size, offset, calculateOffset) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - this.size = size || { │ │ │ │ │ - w: 20, │ │ │ │ │ - h: 20 │ │ │ │ │ - }; │ │ │ │ │ - this.offset = offset || { │ │ │ │ │ - x: -(this.size.w / 2), │ │ │ │ │ - y: -(this.size.h / 2) │ │ │ │ │ - }; │ │ │ │ │ - this.calculateOffset = calculateOffset; │ │ │ │ │ - │ │ │ │ │ - var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ - this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Nullify references and remove event listeners to prevent circular │ │ │ │ │ - * references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // erase any drawn elements │ │ │ │ │ - this.erase(); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ - this.imageDiv.innerHTML = ""; │ │ │ │ │ - this.imageDiv = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A fresh copy of the icon. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Icon(this.url, │ │ │ │ │ - this.size, │ │ │ │ │ - this.offset, │ │ │ │ │ - this.calculateOffset); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {|Object} An OpenLayers.Size or │ │ │ │ │ - * an object with a 'w' and 'h' properties. │ │ │ │ │ - */ │ │ │ │ │ - setSize: function(size) { │ │ │ │ │ - if (size != null) { │ │ │ │ │ - this.size = size; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} │ │ │ │ │ - */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - if (url != null) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Move the div to the given pixel. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ - * object with a 'x' and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image of this icon set at the location passed-in │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - this.size, │ │ │ │ │ - this.url, │ │ │ │ │ - "absolute"); │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - return this.imageDiv; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erase the underlying image element. │ │ │ │ │ - */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ - OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the icon's opacity │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ - null, null, null, null, opacity); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * move icon to passed in px. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - //if no px passed in, use stored location │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.px = px; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.imageDiv != null) { │ │ │ │ │ - if (this.px == null) { │ │ │ │ │ - this.display(false); │ │ │ │ │ - } else { │ │ │ │ │ - if (this.calculateOffset) { │ │ │ │ │ - this.offset = this.calculateOffset(this.size); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { │ │ │ │ │ - x: this.px.x + this.offset.x, │ │ │ │ │ - y: this.px.y + this.offset.y │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ - */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - // nodeType 11 for ie, whose nodes *always* have a parentNode │ │ │ │ │ - // (of type document fragment) │ │ │ │ │ - var isDrawn = (this.imageDiv && this.imageDiv.parentNode && │ │ │ │ │ - (this.imageDiv.parentNode.nodeType != 11)); │ │ │ │ │ - │ │ │ │ │ - return isDrawn; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry │ │ │ │ │ - * A Geometry is a description of a geographic object. Create an instance of │ │ │ │ │ - * this class with the constructor. This is a base class, │ │ │ │ │ - * typical geometry types are described by subclasses of this class. │ │ │ │ │ - * │ │ │ │ │ - * Note that if you use the method, you must │ │ │ │ │ - * explicitly include the OpenLayers.Format.WKT in your build. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique identifier for this geometry. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: parent │ │ │ │ │ - * {}This is set when a Geometry is added as component │ │ │ │ │ - * of another geometry │ │ │ │ │ - */ │ │ │ │ │ - parent: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The bounds of this geometry │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry │ │ │ │ │ - * Creates a geometry object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function() { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this geometry. Does not set any non-standard │ │ │ │ │ - * properties of the cloned geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this geometry. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Geometry(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setBounds │ │ │ │ │ - * Set the bounds for this Geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - setBounds: function(bounds) { │ │ │ │ │ - if (bounds) { │ │ │ │ │ - this.bounds = bounds.clone(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearBounds │ │ │ │ │ - * Nullify this components bounds and that of its parent as well. │ │ │ │ │ - */ │ │ │ │ │ - clearBounds: function() { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - if (this.parent) { │ │ │ │ │ - this.parent.clearBounds(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: extendBounds │ │ │ │ │ - * Extend the existing bounds to include the new bounds. │ │ │ │ │ - * If geometry's bounds is not yet set, then set a new Bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newBounds - {} │ │ │ │ │ - */ │ │ │ │ │ - extendBounds: function(newBounds) { │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if (!bounds) { │ │ │ │ │ - this.setBounds(newBounds); │ │ │ │ │ - } else { │ │ │ │ │ - this.bounds.extend(newBounds); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getBounds │ │ │ │ │ - * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ - * is calculated again, this makes queries faster. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getBounds: function() { │ │ │ │ │ - if (this.bounds == null) { │ │ │ │ │ - this.calculateBounds(); │ │ │ │ │ - } │ │ │ │ │ - return this.bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds for the geometry. │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - // │ │ │ │ │ - // This should be overridden by subclasses. │ │ │ │ │ - // │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options depend on the specific geometry type. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: atPoint │ │ │ │ │ - * Note - This is only an approximation based on the bounds of the │ │ │ │ │ - * geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ - * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the geometry is at the specified location │ │ │ │ │ - */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - var bounds = this.getBounds(); │ │ │ │ │ - if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ - │ │ │ │ │ - var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ - var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ - │ │ │ │ │ - var toleranceBounds = │ │ │ │ │ - new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ - this.bounds.bottom - dY, │ │ │ │ │ - this.bounds.right + dX, │ │ │ │ │ - this.bounds.top + dY); │ │ │ │ │ - │ │ │ │ │ - atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ - } │ │ │ │ │ - return atPoint; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getLength │ │ │ │ │ - * Calculate the length of this geometry. This method is defined in │ │ │ │ │ - * subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - //to be overridden by geometries that actually have a length │ │ │ │ │ - // │ │ │ │ │ - return 0.0; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getArea │ │ │ │ │ - * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The area of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - //to be overridden by geometries that actually have an area │ │ │ │ │ - // │ │ │ │ │ - return 0.0; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toString │ │ │ │ │ - * Returns a text representation of the geometry. If the WKT format is │ │ │ │ │ - * included in a build, this will be the Well-Known Text │ │ │ │ │ - * representation. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} String representation of this geometry. │ │ │ │ │ - */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - var string; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ - string = OpenLayers.Format.WKT.prototype.write( │ │ │ │ │ - new OpenLayers.Feature.Vector(this) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - string = Object.prototype.toString.call(this); │ │ │ │ │ - } │ │ │ │ │ - return string; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.fromWKT │ │ │ │ │ - * Generate a geometry given a Well-Known Text string. For this method to │ │ │ │ │ - * work, you must include the OpenLayers.Format.WKT in your build │ │ │ │ │ - * explicitly. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * wkt - {String} A string representing the geometry in Well-Known Text. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A geometry of the appropriate class. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.fromWKT = function(wkt) { │ │ │ │ │ - var geom; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ - var format = OpenLayers.Geometry.fromWKT.format; │ │ │ │ │ - if (!format) { │ │ │ │ │ - format = new OpenLayers.Format.WKT(); │ │ │ │ │ - OpenLayers.Geometry.fromWKT.format = format; │ │ │ │ │ - } │ │ │ │ │ - var result = format.read(wkt); │ │ │ │ │ - if (result instanceof OpenLayers.Feature.Vector) { │ │ │ │ │ - geom = result.geometry; │ │ │ │ │ - } else if (OpenLayers.Util.isArray(result)) { │ │ │ │ │ - var len = result.length; │ │ │ │ │ - var components = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - components[i] = result[i].geometry; │ │ │ │ │ - } │ │ │ │ │ - geom = new OpenLayers.Geometry.Collection(components); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return geom; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Method: OpenLayers.Geometry.segmentsIntersect │ │ │ │ │ - * Determine whether two line segments intersect. Optionally calculates │ │ │ │ │ - * and returns the intersection point. This function is optimized for │ │ │ │ │ - * cases where seg1.x2 >= seg2.x1 || seg2.x2 >= seg1.x1. In those │ │ │ │ │ - * obvious cases where there is no intersection, the function should │ │ │ │ │ - * not be called. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * seg1 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ - * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ - * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ - * seg2 - {Object} Object representing a segment with properties x1, y1, x2, │ │ │ │ │ - * and y2. The start point is represented by x1 and y1. The end point │ │ │ │ │ - * is represented by x2 and y2. Start and end are ordered so that x1 < x2. │ │ │ │ │ - * options - {Object} Optional properties for calculating the intersection. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * point - {Boolean} Return the intersection point. If false, the actual │ │ │ │ │ - * intersection point will not be calculated. If true and the segments │ │ │ │ │ - * intersect, the intersection point will be returned. If true and │ │ │ │ │ - * the segments do not intersect, false will be returned. If true and │ │ │ │ │ - * the segments are coincident, true will be returned. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, if the segments are │ │ │ │ │ - * within the tolerance distance, this will be considered an intersection. │ │ │ │ │ - * In addition, if the point option is true and the calculated intersection │ │ │ │ │ - * is within the tolerance distance of an end point, the endpoint will be │ │ │ │ │ - * returned instead of the calculated intersection. Further, if the │ │ │ │ │ - * intersection is within the tolerance of endpoints on both segments, or │ │ │ │ │ - * if two segment endpoints are within the tolerance distance of eachother │ │ │ │ │ - * (but no intersection is otherwise calculated), an endpoint on the │ │ │ │ │ - * first segment provided will be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean | } The two segments intersect. │ │ │ │ │ - * If the point argument is true, the return will be the intersection │ │ │ │ │ - * point or false if none exists. If point is true and the segments │ │ │ │ │ - * are coincident, return will be true (and the instersection is equal │ │ │ │ │ - * to the shorter segment). │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.segmentsIntersect = function(seg1, seg2, options) { │ │ │ │ │ - var point = options && options.point; │ │ │ │ │ - var tolerance = options && options.tolerance; │ │ │ │ │ - var intersection = false; │ │ │ │ │ - var x11_21 = seg1.x1 - seg2.x1; │ │ │ │ │ - var y11_21 = seg1.y1 - seg2.y1; │ │ │ │ │ - var x12_11 = seg1.x2 - seg1.x1; │ │ │ │ │ - var y12_11 = seg1.y2 - seg1.y1; │ │ │ │ │ - var y22_21 = seg2.y2 - seg2.y1; │ │ │ │ │ - var x22_21 = seg2.x2 - seg2.x1; │ │ │ │ │ - var d = (y22_21 * x12_11) - (x22_21 * y12_11); │ │ │ │ │ - var n1 = (x22_21 * y11_21) - (y22_21 * x11_21); │ │ │ │ │ - var n2 = (x12_11 * y11_21) - (y12_11 * x11_21); │ │ │ │ │ - if (d == 0) { │ │ │ │ │ - // parallel │ │ │ │ │ - if (n1 == 0 && n2 == 0) { │ │ │ │ │ - // coincident │ │ │ │ │ - intersection = true; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - var along1 = n1 / d; │ │ │ │ │ - var along2 = n2 / d; │ │ │ │ │ - if (along1 >= 0 && along1 <= 1 && along2 >= 0 && along2 <= 1) { │ │ │ │ │ - // intersect │ │ │ │ │ - if (!point) { │ │ │ │ │ - intersection = true; │ │ │ │ │ - } else { │ │ │ │ │ - // calculate the intersection point │ │ │ │ │ - var x = seg1.x1 + (along1 * x12_11); │ │ │ │ │ - var y = seg1.y1 + (along1 * y12_11); │ │ │ │ │ - intersection = new OpenLayers.Geometry.Point(x, y); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (tolerance) { │ │ │ │ │ - var dist; │ │ │ │ │ - if (intersection) { │ │ │ │ │ - if (point) { │ │ │ │ │ - var segs = [seg1, seg2]; │ │ │ │ │ - var seg, x, y; │ │ │ │ │ - // check segment endpoints for proximity to intersection │ │ │ │ │ - // set intersection to first endpoint within the tolerance │ │ │ │ │ - outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ - seg = segs[i]; │ │ │ │ │ - for (var j = 1; j < 3; ++j) { │ │ │ │ │ - x = seg["x" + j]; │ │ │ │ │ - y = seg["y" + j]; │ │ │ │ │ - dist = Math.sqrt( │ │ │ │ │ - Math.pow(x - intersection.x, 2) + │ │ │ │ │ - Math.pow(y - intersection.y, 2) │ │ │ │ │ - ); │ │ │ │ │ - if (dist < tolerance) { │ │ │ │ │ - intersection.x = x; │ │ │ │ │ - intersection.y = y; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // no calculated intersection, but segments could be within │ │ │ │ │ - // the tolerance of one another │ │ │ │ │ - var segs = [seg1, seg2]; │ │ │ │ │ - var source, target, x, y, p, result; │ │ │ │ │ - // check segment endpoints for proximity to intersection │ │ │ │ │ - // set intersection to first endpoint within the tolerance │ │ │ │ │ - outer: for (var i = 0; i < 2; ++i) { │ │ │ │ │ - source = segs[i]; │ │ │ │ │ - target = segs[(i + 1) % 2]; │ │ │ │ │ - for (var j = 1; j < 3; ++j) { │ │ │ │ │ - p = { │ │ │ │ │ - x: source["x" + j], │ │ │ │ │ - y: source["y" + j] │ │ │ │ │ - }; │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment(p, target); │ │ │ │ │ - if (result.distance < tolerance) { │ │ │ │ │ - if (point) { │ │ │ │ │ - intersection = new OpenLayers.Geometry.Point(p.x, p.y); │ │ │ │ │ - } else { │ │ │ │ │ - intersection = true; │ │ │ │ │ - } │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return intersection; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.distanceToSegment │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Object} An object with x and y properties representing the │ │ │ │ │ - * point coordinates. │ │ │ │ │ - * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ - * representing endpoint coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with distance, along, x, and y properties. The distance │ │ │ │ │ - * will be the shortest distance between the input point and segment. │ │ │ │ │ - * The x and y properties represent the coordinates along the segment │ │ │ │ │ - * where the shortest distance meets the segment. The along attribute │ │ │ │ │ - * describes how far between the two segment points the given point is. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.distanceToSegment = function(point, segment) { │ │ │ │ │ - var result = OpenLayers.Geometry.distanceSquaredToSegment(point, segment); │ │ │ │ │ - result.distance = Math.sqrt(result.distance); │ │ │ │ │ - return result; │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: OpenLayers.Geometry.distanceSquaredToSegment │ │ │ │ │ - * │ │ │ │ │ - * Usually the distanceToSegment function should be used. This variant however │ │ │ │ │ - * can be used for comparisons where the exact distance is not important. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Object} An object with x and y properties representing the │ │ │ │ │ - * point coordinates. │ │ │ │ │ - * segment - {Object} An object with x1, y1, x2, and y2 properties │ │ │ │ │ - * representing endpoint coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with squared distance, along, x, and y properties. │ │ │ │ │ - * The distance will be the shortest distance between the input point and │ │ │ │ │ - * segment. The x and y properties represent the coordinates along the │ │ │ │ │ - * segment where the shortest distance meets the segment. The along │ │ │ │ │ - * attribute describes how far between the two segment points the given │ │ │ │ │ - * point is. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.distanceSquaredToSegment = function(point, segment) { │ │ │ │ │ - var x0 = point.x; │ │ │ │ │ - var y0 = point.y; │ │ │ │ │ - var x1 = segment.x1; │ │ │ │ │ - var y1 = segment.y1; │ │ │ │ │ - var x2 = segment.x2; │ │ │ │ │ - var y2 = segment.y2; │ │ │ │ │ - var dx = x2 - x1; │ │ │ │ │ - var dy = y2 - y1; │ │ │ │ │ - var along = ((dx * (x0 - x1)) + (dy * (y0 - y1))) / │ │ │ │ │ - (Math.pow(dx, 2) + Math.pow(dy, 2)); │ │ │ │ │ - var x, y; │ │ │ │ │ - if (along <= 0.0) { │ │ │ │ │ - x = x1; │ │ │ │ │ - y = y1; │ │ │ │ │ - } else if (along >= 1.0) { │ │ │ │ │ - x = x2; │ │ │ │ │ - y = y2; │ │ │ │ │ - } else { │ │ │ │ │ - x = x1 + along * dx; │ │ │ │ │ - y = y1 + along * dy; │ │ │ │ │ - } │ │ │ │ │ - return { │ │ │ │ │ - distance: Math.pow(x - x0, 2) + Math.pow(y - y0, 2), │ │ │ │ │ - x: x, │ │ │ │ │ - y: y, │ │ │ │ │ - along: along │ │ │ │ │ - }; │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Feature.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Feature │ │ │ │ │ - * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ - * class specifically combines a marker and a lonlat. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: data │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - data: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: marker │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - marker: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: popupClass │ │ │ │ │ - * {} The class which will be used to instantiate │ │ │ │ │ - * a new Popup. Default is . │ │ │ │ │ - */ │ │ │ │ │ - popupClass: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: popup │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - popup: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature │ │ │ │ │ - * Constructor for features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * data - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, lonlat, data) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ - this.data = (data != null) ? data : {}; │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - //remove the popup from the map │ │ │ │ │ - if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ - if (this.popup != null) { │ │ │ │ │ - this.layer.map.removePopup(this.popup); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // remove the marker from the layer │ │ │ │ │ - if (this.layer != null && this.marker != null) { │ │ │ │ │ - this.layer.removeMarker(this.marker); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.data = null; │ │ │ │ │ - if (this.marker != null) { │ │ │ │ │ - this.destroyMarker(this.marker); │ │ │ │ │ - this.marker = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.popup != null) { │ │ │ │ │ - this.destroyPopup(this.popup); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ - * (based on its 'lonlat' property) │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ - var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Marker Object created from the 'lonlat' and 'icon' properties │ │ │ │ │ - * set in this.data. If no 'lonlat' is set, returns null. If no │ │ │ │ │ - * 'icon' is set, OpenLayers.Marker() will load the default image. │ │ │ │ │ - * │ │ │ │ │ - * Note - this.marker is set to return value │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ - } │ │ │ │ │ - return this.marker; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * Destroys marker. │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ - */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - this.marker.destroy(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * Creates a popup object created from the 'lonlat', 'popupSize', │ │ │ │ │ - * and 'popupContentHTML' properties set in this.data. It uses │ │ │ │ │ - * this.marker.icon as default anchor. │ │ │ │ │ - * │ │ │ │ │ - * If no 'lonlat' is set, returns null. │ │ │ │ │ - * If no this.marker has been created, no anchor is sent. │ │ │ │ │ - * │ │ │ │ │ - * Note - the returned popup object is 'owned' by the feature, so you │ │ │ │ │ - * cannot use the popup's destroy method to discard the popup. │ │ │ │ │ - * Instead, you must use the feature's destroyPopup │ │ │ │ │ - * │ │ │ │ │ - * Note - this.popup is set to return value │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * closeBox - {Boolean} create popup with closebox or not │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Returns the created popup, which is also set │ │ │ │ │ - * as 'popup' property of this feature. Will be of whatever type │ │ │ │ │ - * specified by this feature's 'popupClass' property, but must be │ │ │ │ │ - * of type . │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - createPopup: function(closeBox) { │ │ │ │ │ - │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - if (!this.popup) { │ │ │ │ │ - var anchor = (this.marker) ? this.marker.icon : null; │ │ │ │ │ - var popupClass = this.popupClass ? │ │ │ │ │ - this.popupClass : OpenLayers.Popup.Anchored; │ │ │ │ │ - this.popup = new popupClass(this.id + "_popup", │ │ │ │ │ - this.lonlat, │ │ │ │ │ - this.data.popupSize, │ │ │ │ │ - this.data.popupContentHTML, │ │ │ │ │ - anchor, │ │ │ │ │ - closeBox); │ │ │ │ │ - } │ │ │ │ │ - if (this.data.overflow != null) { │ │ │ │ │ - this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.popup.feature = this; │ │ │ │ │ - } │ │ │ │ │ - return this.popup; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * Destroys the popup created via createPopup. │ │ │ │ │ - * │ │ │ │ │ - * As with the marker, if user overrides the createPopup() function, s/he │ │ │ │ │ - * should also be able to override the destruction │ │ │ │ │ - */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - if (this.popup) { │ │ │ │ │ - this.popup.feature = null; │ │ │ │ │ - this.popup.destroy(); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Feature/Vector.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -// TRASH THIS │ │ │ │ │ -OpenLayers.State = { │ │ │ │ │ - /** states */ │ │ │ │ │ - UNKNOWN: 'Unknown', │ │ │ │ │ - INSERT: 'Insert', │ │ │ │ │ - UPDATE: 'Update', │ │ │ │ │ - DELETE: 'Delete' │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Feature.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Feature.Vector │ │ │ │ │ - * Vector features use the OpenLayers.Geometry classes as geometry description. │ │ │ │ │ - * They have an 'attributes' property, which is the data object, and a 'style' │ │ │ │ │ - * property, the default values of which are defined in the │ │ │ │ │ - * objects. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: fid │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - fid: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometry │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - geometry: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: attributes │ │ │ │ │ - * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ - * describe the feature. │ │ │ │ │ - */ │ │ │ │ │ - attributes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: bounds │ │ │ │ │ - * {} The box bounding that feature's geometry, that │ │ │ │ │ - * property can be set by an object when │ │ │ │ │ - * deserializing the feature, so in most cases it represents an │ │ │ │ │ - * information set by the server. │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: state │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - state: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - style: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} If this property is set it will be taken into account by │ │ │ │ │ - * {} when upadting or deleting the feature. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: renderIntent │ │ │ │ │ - * {String} rendering intent currently being used │ │ │ │ │ - */ │ │ │ │ │ - renderIntent: "default", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: modified │ │ │ │ │ - * {Object} An object with the originals of the geometry and attributes of │ │ │ │ │ - * the feature, if they were changed. Currently this property is only read │ │ │ │ │ - * by , and written by │ │ │ │ │ - * , which sets the geometry property. │ │ │ │ │ - * Applications can set the originals of modified attributes in the │ │ │ │ │ - * attributes property. Note that applications have to check if this │ │ │ │ │ - * object and the attributes property is already created before using it. │ │ │ │ │ - * After a change made with ModifyFeature, this object could look like │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * geometry: >Object │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * When an application has made changes to feature attributes, it could │ │ │ │ │ - * have set the attributes to something like this: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * attributes: { │ │ │ │ │ - * myAttribute: "original" │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Note that only checks for truthy values in │ │ │ │ │ - * *modified.geometry* and the attribute names in *modified.attributes*, │ │ │ │ │ - * but it is recommended to set the original values (and not just true) as │ │ │ │ │ - * attribute value, so applications could use this information to undo │ │ │ │ │ - * changes. │ │ │ │ │ - */ │ │ │ │ │ - modified: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature.Vector │ │ │ │ │ - * Create a vector feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The geometry that this feature │ │ │ │ │ - * represents. │ │ │ │ │ - * attributes - {Object} An optional object that will be mapped to the │ │ │ │ │ - * property. │ │ │ │ │ - * style - {Object} An optional style object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(geometry, attributes, style) { │ │ │ │ │ - OpenLayers.Feature.prototype.initialize.apply(this, │ │ │ │ │ - [null, null, attributes]); │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.geometry = geometry ? geometry : null; │ │ │ │ │ - this.state = null; │ │ │ │ │ - this.attributes = {}; │ │ │ │ │ - if (attributes) { │ │ │ │ │ - this.attributes = OpenLayers.Util.extend(this.attributes, │ │ │ │ │ - attributes); │ │ │ │ │ - } │ │ │ │ │ - this.style = style ? style : null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.layer) { │ │ │ │ │ - this.layer.removeFeatures(this); │ │ │ │ │ - this.layer = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.geometry = null; │ │ │ │ │ - this.modified = null; │ │ │ │ │ - OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this vector feature. Does not set any non-standard │ │ │ │ │ - * properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this vector feature. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - this.geometry ? this.geometry.clone() : null, │ │ │ │ │ - this.attributes, │ │ │ │ │ - this.style); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * Determine whether the feature is within the map viewport. This method │ │ │ │ │ - * tests for an intersection between the geometry and the viewport │ │ │ │ │ - * bounds. If a more effecient but less precise geometry bounds │ │ │ │ │ - * intersection is desired, call the method with the boundsOnly │ │ │ │ │ - * parameter true. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * boundsOnly - {Boolean} Only test whether a feature's bounds intersects │ │ │ │ │ - * the viewport bounds. Default is false. If false, the feature's │ │ │ │ │ - * geometry must intersect the viewport for onScreen to return true. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ - * based on its bounds if boundsOnly is true). │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function(boundsOnly) { │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.layer && this.layer.map) { │ │ │ │ │ - var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ - if (boundsOnly) { │ │ │ │ │ - var featureBounds = this.geometry.getBounds(); │ │ │ │ │ - onScreen = screenBounds.intersectsBounds(featureBounds); │ │ │ │ │ - } else { │ │ │ │ │ - var screenPoly = screenBounds.toGeometry(); │ │ │ │ │ - onScreen = screenPoly.intersects(this.geometry); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getVisibility │ │ │ │ │ - * Determine whether the feature is displayed or not. It may not displayed │ │ │ │ │ - * because: │ │ │ │ │ - * - its style display property is set to 'none', │ │ │ │ │ - * - it doesn't belong to any layer, │ │ │ │ │ - * - the styleMap creates a symbolizer with display property set to 'none' │ │ │ │ │ - * for it, │ │ │ │ │ - * - the layer which it belongs to is not visible. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The feature is currently displayed. │ │ │ │ │ - */ │ │ │ │ │ - getVisibility: function() { │ │ │ │ │ - return !(this.style && this.style.display == 'none' || │ │ │ │ │ - !this.layer || │ │ │ │ │ - this.layer && this.layer.styleMap && │ │ │ │ │ - this.layer.styleMap.createSymbolizer(this, this.renderIntent).display == 'none' || │ │ │ │ │ - this.layer && !this.layer.getVisibility()); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create markers │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ - */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * delete markers │ │ │ │ │ - * │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ - */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - // pass │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create popups │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ - */ │ │ │ │ │ - createPopup: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: atPoint │ │ │ │ │ - * Determins whether the feature intersects with the specified location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * toleranceLon - {float} Optional tolerance in Geometric Coords │ │ │ │ │ - * toleranceLat - {float} Optional tolerance in Geographic Coords │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ - */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - if (this.geometry) { │ │ │ │ │ - atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ - toleranceLat); │ │ │ │ │ - } │ │ │ │ │ - return atPoint; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * delete popups │ │ │ │ │ - */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - // pass │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Moves the feature and redraws it at its new location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * location - { or } the │ │ │ │ │ - * location to which to move the feature. │ │ │ │ │ - */ │ │ │ │ │ - move: function(location) { │ │ │ │ │ - │ │ │ │ │ - if (!this.layer || !this.geometry.move) { │ │ │ │ │ - //do nothing if no layer or immoveable geometry │ │ │ │ │ - return undefined; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var pixel; │ │ │ │ │ - if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ - pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ - } else { │ │ │ │ │ - pixel = location; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat()); │ │ │ │ │ - var res = this.layer.map.getResolution(); │ │ │ │ │ - this.geometry.move(res * (pixel.x - lastPixel.x), │ │ │ │ │ - res * (lastPixel.y - pixel.y)); │ │ │ │ │ - this.layer.drawFeature(this); │ │ │ │ │ - return lastPixel; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toState │ │ │ │ │ - * Sets the new state │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * state - {String} │ │ │ │ │ - */ │ │ │ │ │ - toState: function(state) { │ │ │ │ │ - if (state == OpenLayers.State.UPDATE) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - case OpenLayers.State.DELETE: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.UPDATE: │ │ │ │ │ - case OpenLayers.State.INSERT: │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.DELETE) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.INSERT: │ │ │ │ │ - // the feature should be destroyed │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.DELETE: │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - case OpenLayers.State.UPDATE: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (state == OpenLayers.State.UNKNOWN) { │ │ │ │ │ - this.state = state; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature.Vector" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Feature.Vector.style │ │ │ │ │ - * OpenLayers features can have a number of style attributes. The 'default' │ │ │ │ │ - * style will typically be used if no other style is specified. These │ │ │ │ │ - * styles correspond for the most part, to the styling properties defined │ │ │ │ │ - * by the SVG standard. │ │ │ │ │ - * Information on fill properties: http://www.w3.org/TR/SVG/painting.html#FillProperties │ │ │ │ │ - * Information on stroke properties: http://www.w3.org/TR/SVG/painting.html#StrokeProperties │ │ │ │ │ - * │ │ │ │ │ - * Symbolizer properties: │ │ │ │ │ - * fill - {Boolean} Set to false if no fill is desired. │ │ │ │ │ - * fillColor - {String} Hex fill color. Default is "#ee9900". │ │ │ │ │ - * fillOpacity - {Number} Fill opacity (0-1). Default is 0.4 │ │ │ │ │ - * stroke - {Boolean} Set to false if no stroke is desired. │ │ │ │ │ - * strokeColor - {String} Hex stroke color. Default is "#ee9900". │ │ │ │ │ - * strokeOpacity - {Number} Stroke opacity (0-1). Default is 1. │ │ │ │ │ - * strokeWidth - {Number} Pixel stroke width. Default is 1. │ │ │ │ │ - * strokeLinecap - {String} Stroke cap type. Default is "round". [butt | round | square] │ │ │ │ │ - * strokeDashstyle - {String} Stroke dash style. Default is "solid". [dot | dash | dashdot | longdash | longdashdot | solid] │ │ │ │ │ - * graphic - {Boolean} Set to false if no graphic is desired. │ │ │ │ │ - * pointRadius - {Number} Pixel point radius. Default is 6. │ │ │ │ │ - * pointerEvents - {String} Default is "visiblePainted". │ │ │ │ │ - * cursor - {String} Default is "". │ │ │ │ │ - * externalGraphic - {String} Url to an external graphic that will be used for rendering points. │ │ │ │ │ - * graphicWidth - {Number} Pixel width for sizing an external graphic. │ │ │ │ │ - * graphicHeight - {Number} Pixel height for sizing an external graphic. │ │ │ │ │ - * graphicOpacity - {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ - * graphicXOffset - {Number} Pixel offset along the positive x axis for displacing an external graphic. │ │ │ │ │ - * graphicYOffset - {Number} Pixel offset along the positive y axis for displacing an external graphic. │ │ │ │ │ - * rotation - {Number} For point symbolizers, this is the rotation of a graphic in the clockwise direction about its center point (or any point off center as specified by graphicXOffset and graphicYOffset). │ │ │ │ │ - * graphicZIndex - {Number} The integer z-index value to use in rendering. │ │ │ │ │ - * graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default), │ │ │ │ │ - * "square", "star", "x", "cross", "triangle". │ │ │ │ │ - * graphicTitle - {String} Tooltip when hovering over a feature. *deprecated*, use title instead │ │ │ │ │ - * title - {String} Tooltip when hovering over a feature. Not supported by the canvas renderer. │ │ │ │ │ - * backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic. │ │ │ │ │ - * backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic. │ │ │ │ │ - * backgroundXOffset - {Number} The x offset (in pixels) for the background graphic. │ │ │ │ │ - * backgroundYOffset - {Number} The y offset (in pixels) for the background graphic. │ │ │ │ │ - * backgroundHeight - {Number} The height of the background graphic. If not provided, the graphicHeight will be used. │ │ │ │ │ - * backgroundWidth - {Number} The width of the background width. If not provided, the graphicWidth will be used. │ │ │ │ │ - * label - {String} The text for an optional label. For browsers that use the canvas renderer, this requires either │ │ │ │ │ - * fillText or mozDrawText to be available. │ │ │ │ │ - * labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string │ │ │ │ │ - * composed of two characters. The first character is for the horizontal alignment, the second for the vertical │ │ │ │ │ - * alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical │ │ │ │ │ - * alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". Default is "cm". │ │ │ │ │ - * labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ - * labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer. │ │ │ │ │ - * labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * labelOutlineColor - {String} The color of the label outline. Default is 'white'. Only supported by the canvas & SVG renderers. │ │ │ │ │ - * labelOutlineWidth - {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the SVG renderers. │ │ │ │ │ - * labelOutlineOpacity - {Number} The opacity (0-1) of the label outline. Default is fontOpacity. Only supported by the canvas & SVG renderers. │ │ │ │ │ - * fontColor - {String} The font color for the label, to be provided like CSS. │ │ │ │ │ - * fontOpacity - {Number} Opacity (0-1) for the label │ │ │ │ │ - * fontFamily - {String} The font family for the label, to be provided like in CSS. │ │ │ │ │ - * fontSize - {String} The font size for the label, to be provided like in CSS. │ │ │ │ │ - * fontStyle - {String} The font style for the label, to be provided like in CSS. │ │ │ │ │ - * fontWeight - {String} The font weight for the label, to be provided like in CSS. │ │ │ │ │ - * display - {String} Symbolizers will have no effect if display is set to "none". All other values have no effect. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Feature.Vector.style = { │ │ │ │ │ - 'default': { │ │ │ │ │ - fillColor: "#ee9900", │ │ │ │ │ - fillOpacity: 0.4, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "#ee9900", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "inherit", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - }, │ │ │ │ │ - 'select': { │ │ │ │ │ - fillColor: "blue", │ │ │ │ │ - fillOpacity: 0.4, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "blue", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeWidth: 2, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "pointer", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - 'temporary': { │ │ │ │ │ - fillColor: "#66cccc", │ │ │ │ │ - fillOpacity: 0.2, │ │ │ │ │ - hoverFillColor: "white", │ │ │ │ │ - hoverFillOpacity: 0.8, │ │ │ │ │ - strokeColor: "#66cccc", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeLinecap: "round", │ │ │ │ │ - strokeWidth: 2, │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - hoverStrokeColor: "red", │ │ │ │ │ - hoverStrokeOpacity: 1, │ │ │ │ │ - hoverStrokeWidth: 0.2, │ │ │ │ │ - pointRadius: 6, │ │ │ │ │ - hoverPointRadius: 1, │ │ │ │ │ - hoverPointUnit: "%", │ │ │ │ │ - pointerEvents: "visiblePainted", │ │ │ │ │ - cursor: "inherit", │ │ │ │ │ - fontColor: "#000000", │ │ │ │ │ - labelAlign: "cm", │ │ │ │ │ - labelOutlineColor: "white", │ │ │ │ │ - labelOutlineWidth: 3 │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - 'delete': { │ │ │ │ │ - display: "none" │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * 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.Format = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} A reference to options passed to the constructor. │ │ │ │ │ - */ │ │ │ │ │ - options: 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. │ │ │ │ │ - */ │ │ │ │ │ - externalProjection: 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. │ │ │ │ │ - */ │ │ │ │ │ - internalProjection: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: data │ │ │ │ │ - * {Object} When is true, this is the parsed string sent to │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - data: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: keepData │ │ │ │ │ - * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - keepData: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ - * │ │ │ │ │ - * 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 │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: read │ │ │ │ │ - * Read data from a string, and return an object whose type depends on the │ │ │ │ │ - * subclass. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {string} Data to read/parse. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * Depends on the subclass │ │ │ │ │ - */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - throw new Error('Read not implemented.'); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: write │ │ │ │ │ - * Accept an object, and return a string. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * object - {Object} Object to be serialized │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representation of the object. │ │ │ │ │ - */ │ │ │ │ │ - write: function(object) { │ │ │ │ │ - throw new Error('Write not implemented.'); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Point.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Point │ │ │ │ │ - * Point geometry class. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: x │ │ │ │ │ - * {float} │ │ │ │ │ - */ │ │ │ │ │ - x: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: y │ │ │ │ │ - * {float} │ │ │ │ │ - */ │ │ │ │ │ - y: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ - * Construct a point geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {float} │ │ │ │ │ - * y - {float} │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.x = parseFloat(x); │ │ │ │ │ - this.y = parseFloat(y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ - */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateBounds │ │ │ │ │ - * Create a new Bounds based on the lon/lat │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ - this.x, this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var distance, x0, y0, x1, y1, result; │ │ │ │ │ - if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - x0 = this.x; │ │ │ │ │ - y0 = this.y; │ │ │ │ │ - x1 = geometry.x; │ │ │ │ │ - y1 = geometry.y; │ │ │ │ │ - distance = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); │ │ │ │ │ - result = !details ? │ │ │ │ │ - distance : { │ │ │ │ │ - x0: x0, │ │ │ │ │ - y0: y0, │ │ │ │ │ - x1: x1, │ │ │ │ │ - y1: y1, │ │ │ │ │ - distance: distance │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - result = geometry.distanceTo(this, options); │ │ │ │ │ - if (details) { │ │ │ │ │ - // switch coord order since this geom is target │ │ │ │ │ - result = { │ │ │ │ │ - x0: result.x1, │ │ │ │ │ - y0: result.y1, │ │ │ │ │ - x1: result.x0, │ │ │ │ │ - y1: result.y0, │ │ │ │ │ - distance: result.distance │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geom - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ - */ │ │ │ │ │ - equals: function(geom) { │ │ │ │ │ - var equals = false; │ │ │ │ │ - if (geom != null) { │ │ │ │ │ - equals = ((this.x == geom.x && this.y == geom.y) || │ │ │ │ │ - (isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y))); │ │ │ │ │ - } │ │ │ │ │ - return equals; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toShortString │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Shortened String representation of Point object. │ │ │ │ │ - * (ex. "5, 42") │ │ │ │ │ - */ │ │ │ │ │ - toShortString: function() { │ │ │ │ │ - return (this.x + ", " + this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: move │ │ │ │ │ - * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ - * This modifies the position of the geometry and clears the cached │ │ │ │ │ - * bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ - * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ - */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - this.x = this.x + x; │ │ │ │ │ - this.y = this.y + y; │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: rotate │ │ │ │ │ - * Rotate a point around another. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ - * from the positive x-axis) │ │ │ │ │ - * origin - {} Center point for the rotation │ │ │ │ │ - */ │ │ │ │ │ - rotate: function(angle, origin) { │ │ │ │ │ - angle *= Math.PI / 180; │ │ │ │ │ - var radius = this.distanceTo(origin); │ │ │ │ │ - var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x); │ │ │ │ │ - this.x = origin.x + (radius * Math.cos(theta)); │ │ │ │ │ - this.y = origin.y + (radius * Math.sin(theta)); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function() { │ │ │ │ │ - return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: resize │ │ │ │ │ - * Resize a point relative to some origin. For points, this has the effect │ │ │ │ │ - * of scaling a vector (from the origin to the point). This method is │ │ │ │ │ - * more useful on geometry collection subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {Float} Ratio of the new distance from the origin to the old │ │ │ │ │ - * distance from the origin. A scale of 2 doubles the │ │ │ │ │ - * distance between the point and origin. │ │ │ │ │ - * origin - {} Point of origin for resizing │ │ │ │ │ - * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ - */ │ │ │ │ │ - resize: function(scale, origin, ratio) { │ │ │ │ │ - ratio = (ratio == undefined) ? 1 : ratio; │ │ │ │ │ - this.x = origin.x + (scale * ratio * (this.x - origin.x)); │ │ │ │ │ - this.y = origin.y + (scale * (this.y - origin.y)); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - intersect = this.equals(geometry); │ │ │ │ │ - } else { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Translate the x,y properties of the point from source to dest. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - transform: function(source, dest) { │ │ │ │ │ - if ((source && dest)) { │ │ │ │ │ - OpenLayers.Projection.transform( │ │ │ │ │ - this, source, dest); │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - return [this]; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Collection.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Collection │ │ │ │ │ - * A Collection is exactly what it sounds like: A collection of different │ │ │ │ │ - * Geometries. These are stored in the local parameter (which │ │ │ │ │ - * can be passed as a parameter to the constructor). │ │ │ │ │ - * │ │ │ │ │ - * As new geometries are added to the collection, they are NOT cloned. │ │ │ │ │ - * When removing geometries, they need to be specified by reference (ie you │ │ │ │ │ - * have to pass in the *exact* geometry to be removed). │ │ │ │ │ - * │ │ │ │ │ - * The and functions here merely iterate through │ │ │ │ │ - * the components, summing their respective areas and lengths. │ │ │ │ │ - * │ │ │ │ │ - * Create a new instance with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: components │ │ │ │ │ - * {Array()} The component parts of this geometry │ │ │ │ │ - */ │ │ │ │ │ - components: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null value means the │ │ │ │ │ - * component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ - * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} Optional array of geometries │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(components) { │ │ │ │ │ - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.components = []; │ │ │ │ │ - if (components != null) { │ │ │ │ │ - this.addComponents(components); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this geometry. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.components.length = 0; │ │ │ │ │ - this.components = null; │ │ │ │ │ - OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clone this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this collection │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var geometry = eval("new " + this.CLASS_NAME + "()"); │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - geometry.addComponent(this.components[i].clone()); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ - │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getComponentsString │ │ │ │ │ - * Get a string representing the components for this collection │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representation of the components of this geometry │ │ │ │ │ - */ │ │ │ │ │ - getComponentsString: function() { │ │ │ │ │ - var strings = []; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - strings.push(this.components[i].toShortString()); │ │ │ │ │ - } │ │ │ │ │ - return strings.join(","); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: calculateBounds │ │ │ │ │ - * Recalculate the bounds by iterating through the components and │ │ │ │ │ - * calling calling extendBounds() on each item. │ │ │ │ │ - */ │ │ │ │ │ - calculateBounds: function() { │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - var bounds = new OpenLayers.Bounds(); │ │ │ │ │ - var components = this.components; │ │ │ │ │ - if (components) { │ │ │ │ │ - for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ - bounds.extend(components[i].getBounds()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // to preserve old behavior, we only set bounds if non-null │ │ │ │ │ - // in the future, we could add bounds.isEmpty() │ │ │ │ │ - if (bounds.left != null && bounds.bottom != null && │ │ │ │ │ - bounds.right != null && bounds.top != null) { │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addComponents │ │ │ │ │ - * Add components to this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} An array of geometries to add │ │ │ │ │ - */ │ │ │ │ │ - addComponents: function(components) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0, len = components.length; i < len; i++) { │ │ │ │ │ - this.addComponent(components[i]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addComponent │ │ │ │ │ - * Add a new component (geometry) to the collection. If this.componentTypes │ │ │ │ │ - * is set, then the component class name must be in the componentTypes array. │ │ │ │ │ - * │ │ │ │ │ - * The bounds cache is reset. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * component - {} A geometry to add │ │ │ │ │ - * index - {int} Optional index into the array to insert the component │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component geometry was successfully added │ │ │ │ │ - */ │ │ │ │ │ - addComponent: function(component, index) { │ │ │ │ │ - var added = false; │ │ │ │ │ - if (component) { │ │ │ │ │ - if (this.componentTypes == null || │ │ │ │ │ - (OpenLayers.Util.indexOf(this.componentTypes, │ │ │ │ │ - component.CLASS_NAME) > -1)) { │ │ │ │ │ - │ │ │ │ │ - if (index != null && (index < this.components.length)) { │ │ │ │ │ - var components1 = this.components.slice(0, index); │ │ │ │ │ - var components2 = this.components.slice(index, │ │ │ │ │ - this.components.length); │ │ │ │ │ - components1.push(component); │ │ │ │ │ - this.components = components1.concat(components2); │ │ │ │ │ - } else { │ │ │ │ │ - this.components.push(component); │ │ │ │ │ - } │ │ │ │ │ - component.parent = this; │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - added = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return added; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeComponents │ │ │ │ │ - * Remove components from this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} The components to be removed │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponents: function(components) { │ │ │ │ │ - var removed = false; │ │ │ │ │ - │ │ │ │ │ - if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ - components = [components]; │ │ │ │ │ - } │ │ │ │ │ - for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ - removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ - } │ │ │ │ │ - return removed; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeComponent │ │ │ │ │ - * Remove a component from this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * component - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponent: function(component) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ - │ │ │ │ │ - // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ - // to this.getBounds(); │ │ │ │ │ - this.clearBounds(); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLength │ │ │ │ │ - * Calculate the length of this geometry │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the geometry │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i].getLength(); │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getArea │ │ │ │ │ - * Calculate the area of this geometry. Note how this function is overridden │ │ │ │ │ - * in . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The area of the collection by summing its parts │ │ │ │ │ - */ │ │ │ │ │ - getArea: function() { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - area += this.components[i].getArea(); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicArea │ │ │ │ │ - * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Reference: │ │ │ │ │ - * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for │ │ │ │ │ - * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion │ │ │ │ │ - * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {float} The approximate geodesic area of the geometry in square meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicArea: function(projection) { │ │ │ │ │ - var area = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - area += this.components[i].getGeodesicArea(projection); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCentroid │ │ │ │ │ - * │ │ │ │ │ - * Compute the centroid for this geometry collection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ - * returning an area weighted average of all geometries in this collection. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The centroid of the collection │ │ │ │ │ - */ │ │ │ │ │ - getCentroid: function(weighted) { │ │ │ │ │ - if (!weighted) { │ │ │ │ │ - return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ - } │ │ │ │ │ - var len = this.components.length; │ │ │ │ │ - if (!len) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var areas = []; │ │ │ │ │ - var centroids = []; │ │ │ │ │ - var areaSum = 0; │ │ │ │ │ - var minArea = Number.MAX_VALUE; │ │ │ │ │ - var component; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - component = this.components[i]; │ │ │ │ │ - var area = component.getArea(); │ │ │ │ │ - var centroid = component.getCentroid(true); │ │ │ │ │ - if (isNaN(area) || isNaN(centroid.x) || isNaN(centroid.y)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - areas.push(area); │ │ │ │ │ - areaSum += area; │ │ │ │ │ - minArea = (area < minArea && area > 0) ? area : minArea; │ │ │ │ │ - centroids.push(centroid); │ │ │ │ │ - } │ │ │ │ │ - len = areas.length; │ │ │ │ │ - if (areaSum === 0) { │ │ │ │ │ - // all the components in this collection have 0 area │ │ │ │ │ - // probably a collection of points -- weight all the points the same │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - areas[i] = 1; │ │ │ │ │ - } │ │ │ │ │ - areaSum = areas.length; │ │ │ │ │ - } else { │ │ │ │ │ - // normalize all the areas where the smallest area will get │ │ │ │ │ - // a value of 1 │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - areas[i] /= minArea; │ │ │ │ │ - } │ │ │ │ │ - areaSum /= minArea; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var xSum = 0, │ │ │ │ │ - ySum = 0, │ │ │ │ │ - centroid, area; │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - centroid = centroids[i]; │ │ │ │ │ - area = areas[i]; │ │ │ │ │ - xSum += centroid.x * area; │ │ │ │ │ - ySum += centroid.y * area; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicLength: function(projection) { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i].getGeodesicLength(projection); │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: move │ │ │ │ │ - * Moves a geometry by the given displacement along positive x and y axes. │ │ │ │ │ - * This modifies the position of the geometry and clears the cached │ │ │ │ │ - * bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Float} Distance to move geometry in positive x direction. │ │ │ │ │ - * y - {Float} Distance to move geometry in positive y direction. │ │ │ │ │ - */ │ │ │ │ │ - move: function(x, y) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - this.components[i].move(x, y); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: rotate │ │ │ │ │ - * Rotate a geometry around some origin │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ - * from the positive x-axis) │ │ │ │ │ - * origin - {} Center point for the rotation │ │ │ │ │ - */ │ │ │ │ │ - rotate: function(angle, origin) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - this.components[i].rotate(angle, origin); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: resize │ │ │ │ │ - * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ - * a uniform scaling to a geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scale - {Float} Factor by which to scale the geometry. A scale of 2 │ │ │ │ │ - * doubles the size of the geometry in each dimension │ │ │ │ │ - * (lines, for example, will be twice as long, and polygons │ │ │ │ │ - * will have four times the area). │ │ │ │ │ - * origin - {} Point of origin for resizing │ │ │ │ │ - * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} - The current geometry. │ │ │ │ │ - */ │ │ │ │ │ - resize: function(scale, origin, ratio) { │ │ │ │ │ - for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ - this.components[i].resize(scale, origin, ratio); │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and y1 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var result, best, distance; │ │ │ │ │ - var min = Number.POSITIVE_INFINITY; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - result = this.components[i].distanceTo(geometry, options); │ │ │ │ │ - distance = details ? result.distance : result; │ │ │ │ │ - if (distance < min) { │ │ │ │ │ - min = distance; │ │ │ │ │ - best = result; │ │ │ │ │ - if (min == 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return best; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: equals │ │ │ │ │ - * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ - * are considered equivalent if all components have the same coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The geometry to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ - */ │ │ │ │ │ - equals: function(geometry) { │ │ │ │ │ - var equivalent = true; │ │ │ │ │ - if (!geometry || !geometry.CLASS_NAME || │ │ │ │ │ - (this.CLASS_NAME != geometry.CLASS_NAME)) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - } else if (!(OpenLayers.Util.isArray(geometry.components)) || │ │ │ │ │ - (geometry.components.length != this.components.length)) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - } else { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - if (!this.components[i].equals(geometry.components[i])) { │ │ │ │ │ - equivalent = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return equivalent; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: transform │ │ │ │ │ - * Reproject the components geometry from source to dest. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {} │ │ │ │ │ - * dest - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - transform: function(source, dest) { │ │ │ │ │ - if (source && dest) { │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ - var component = this.components[i]; │ │ │ │ │ - component.transform(source, dest); │ │ │ │ │ - } │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - } │ │ │ │ │ - return this; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Determine if the input geometry intersects this one. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} Any type of geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this one. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - intersect = geometry.intersects(this.components[i]); │ │ │ │ │ - if (intersect) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - var vertices = []; │ │ │ │ │ - for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ - Array.prototype.push.apply( │ │ │ │ │ - vertices, this.components[i].getVertices(nodes) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return vertices; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * MultiPoint is a collection of Points. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.MultiPoint = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Geometry.Collection, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null value means the │ │ │ │ │ - * component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ - * Create a new MultiPoint Geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addPoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be added │ │ │ │ │ - * index - {Integer} Optional index │ │ │ │ │ - */ │ │ │ │ │ - addPoint: function(point, index) { │ │ │ │ │ - this.addComponent(point, index); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removePoint │ │ │ │ │ - * Wrapper for │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} Point to be removed │ │ │ │ │ - */ │ │ │ │ │ - removePoint: function(point) { │ │ │ │ │ - this.removeComponent(point); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/Curve.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.Curve │ │ │ │ │ - * A Curve is a MultiPoint, whose points are assumed to be connected. To │ │ │ │ │ - * this end, we provide a "getLength()" function, which iterates through │ │ │ │ │ - * the points, summing the distances between them. │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: componentTypes │ │ │ │ │ - * {Array(String)} An array of class names representing the types of │ │ │ │ │ - * components that the collection can include. A null │ │ │ │ │ - * value means the component types are not restricted. │ │ │ │ │ - */ │ │ │ │ │ - componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {Array()} │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getLength │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The length of the curve │ │ │ │ │ - */ │ │ │ │ │ - getLength: function() { │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - if (this.components && (this.components.length > 1)) { │ │ │ │ │ - for (var i = 1, len = this.components.length; i < len; i++) { │ │ │ │ │ - length += this.components[i - 1].distanceTo(this.components[i]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return length; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getGeodesicLength │ │ │ │ │ - * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ - * the earth. │ │ │ │ │ - * │ │ │ │ │ - * projection - {} The spatial reference system │ │ │ │ │ - * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ - * assumed. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ - */ │ │ │ │ │ - getGeodesicLength: function(projection) { │ │ │ │ │ - var geom = this; // so we can work with a clone if needed │ │ │ │ │ - if (projection) { │ │ │ │ │ - var gg = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - if (!gg.equals(projection)) { │ │ │ │ │ - geom = this.clone().transform(projection, gg); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var length = 0.0; │ │ │ │ │ - if (geom.components && (geom.components.length > 1)) { │ │ │ │ │ - var p1, p2; │ │ │ │ │ - for (var i = 1, len = geom.components.length; i < len; i++) { │ │ │ │ │ - p1 = geom.components[i - 1]; │ │ │ │ │ - p2 = geom.components[i]; │ │ │ │ │ - // this returns km and requires lon/lat properties │ │ │ │ │ - length += OpenLayers.Util.distVincenty({ │ │ │ │ │ - lon: p1.x, │ │ │ │ │ - lat: p1.y │ │ │ │ │ - }, { │ │ │ │ │ - lon: p2.x, │ │ │ │ │ - lat: p2.y │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // convert to m │ │ │ │ │ - return length * 1000; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/LineString.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.LineString │ │ │ │ │ - * A LineString is a Curve which, once two points have been added to it, can │ │ │ │ │ - * never be less than two points long. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ - * Create a new LineString geometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * points - {Array()} An array of points used to │ │ │ │ │ - * generate the linestring │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeComponent │ │ │ │ │ - * Only allows removal of a point if there are three or more points in │ │ │ │ │ - * the linestring. (otherwise the result would be just a single point) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * point - {} The point to be removed │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The component was removed. │ │ │ │ │ - */ │ │ │ │ │ - removeComponent: function(point) { │ │ │ │ │ - var removed = this.components && (this.components.length > 2); │ │ │ │ │ - if (removed) { │ │ │ │ │ - OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - } │ │ │ │ │ - return removed; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: intersects │ │ │ │ │ - * Test for instersection between two geometries. This is a cheapo │ │ │ │ │ - * implementation of the Bently-Ottmann algorigithm. It doesn't │ │ │ │ │ - * really keep track of a sweep line data structure. It is closer │ │ │ │ │ - * to the brute force method, except that segments are sorted and │ │ │ │ │ - * potential intersections are only calculated when bounding boxes │ │ │ │ │ - * intersect. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The input geometry intersects this geometry. │ │ │ │ │ - */ │ │ │ │ │ - intersects: function(geometry) { │ │ │ │ │ - var intersect = false; │ │ │ │ │ - var type = geometry.CLASS_NAME; │ │ │ │ │ - if (type == "OpenLayers.Geometry.LineString" || │ │ │ │ │ - type == "OpenLayers.Geometry.LinearRing" || │ │ │ │ │ - type == "OpenLayers.Geometry.Point") { │ │ │ │ │ - var segs1 = this.getSortedSegments(); │ │ │ │ │ - var segs2; │ │ │ │ │ - if (type == "OpenLayers.Geometry.Point") { │ │ │ │ │ - segs2 = [{ │ │ │ │ │ - x1: geometry.x, │ │ │ │ │ - y1: geometry.y, │ │ │ │ │ - x2: geometry.x, │ │ │ │ │ - y2: geometry.y │ │ │ │ │ - }]; │ │ │ │ │ - } else { │ │ │ │ │ - segs2 = geometry.getSortedSegments(); │ │ │ │ │ - } │ │ │ │ │ - var seg1, seg1x1, seg1x2, seg1y1, seg1y2, │ │ │ │ │ - seg2, seg2y1, seg2y2; │ │ │ │ │ - // sweep right │ │ │ │ │ - outer: for (var i = 0, len = segs1.length; i < len; ++i) { │ │ │ │ │ - seg1 = segs1[i]; │ │ │ │ │ - seg1x1 = seg1.x1; │ │ │ │ │ - seg1x2 = seg1.x2; │ │ │ │ │ - seg1y1 = seg1.y1; │ │ │ │ │ - seg1y2 = seg1.y2; │ │ │ │ │ - inner: for (var j = 0, jlen = segs2.length; j < jlen; ++j) { │ │ │ │ │ - seg2 = segs2[j]; │ │ │ │ │ - if (seg2.x1 > seg1x2) { │ │ │ │ │ - // seg1 still left of seg2 │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - if (seg2.x2 < seg1x1) { │ │ │ │ │ - // seg2 still left of seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - seg2y1 = seg2.y1; │ │ │ │ │ - seg2y2 = seg2.y2; │ │ │ │ │ - if (Math.min(seg2y1, seg2y2) > Math.max(seg1y1, seg1y2)) { │ │ │ │ │ - // seg2 above seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (Math.max(seg2y1, seg2y2) < Math.min(seg1y1, seg1y2)) { │ │ │ │ │ - // seg2 below seg1 │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Geometry.segmentsIntersect(seg1, seg2)) { │ │ │ │ │ - intersect = true; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - intersect = geometry.intersects(this); │ │ │ │ │ - } │ │ │ │ │ - return intersect; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getSortedSegments │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} An array of segment objects. Segment objects have properties │ │ │ │ │ - * x1, y1, x2, and y2. The start point is represented by x1 and y1. │ │ │ │ │ - * The end point is represented by x2 and y2. Start and end are │ │ │ │ │ - * ordered so that x1 < x2. │ │ │ │ │ - */ │ │ │ │ │ - getSortedSegments: function() { │ │ │ │ │ - var numSeg = this.components.length - 1; │ │ │ │ │ - var segments = new Array(numSeg), │ │ │ │ │ - point1, point2; │ │ │ │ │ - for (var i = 0; i < numSeg; ++i) { │ │ │ │ │ - point1 = this.components[i]; │ │ │ │ │ - point2 = this.components[i + 1]; │ │ │ │ │ - if (point1.x < point2.x) { │ │ │ │ │ - segments[i] = { │ │ │ │ │ - x1: point1.x, │ │ │ │ │ - y1: point1.y, │ │ │ │ │ - x2: point2.x, │ │ │ │ │ - y2: point2.y │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - segments[i] = { │ │ │ │ │ - x1: point2.x, │ │ │ │ │ - y1: point2.y, │ │ │ │ │ - x2: point1.x, │ │ │ │ │ - y2: point1.y │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // more efficient to define this somewhere static │ │ │ │ │ - function byX1(seg1, seg2) { │ │ │ │ │ - return seg1.x1 - seg2.x1; │ │ │ │ │ - } │ │ │ │ │ - return segments.sort(byX1); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: splitWithSegment │ │ │ │ │ - * Split this geometry with the given segment. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * seg - {Object} An object with x1, y1, x2, and y2 properties referencing │ │ │ │ │ - * segment endpoint coordinates. │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source segment must be within the │ │ │ │ │ - * tolerance distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of one of the source segment's │ │ │ │ │ - * endpoints will be assumed to occur at the endpoint. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with *lines* and *points* properties. If the given │ │ │ │ │ - * segment intersects this linestring, the lines array will reference │ │ │ │ │ - * geometries that result from the split. The points array will contain │ │ │ │ │ - * all intersection points. Intersection points are sorted along the │ │ │ │ │ - * segment (in order from x1,y1 to x2,y2). │ │ │ │ │ - */ │ │ │ │ │ - splitWithSegment: function(seg, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var tolerance = options && options.tolerance; │ │ │ │ │ - var lines = []; │ │ │ │ │ - var verts = this.getVertices(); │ │ │ │ │ - var points = []; │ │ │ │ │ - var intersections = []; │ │ │ │ │ - var split = false; │ │ │ │ │ - var vert1, vert2, point; │ │ │ │ │ - var node, vertex, target; │ │ │ │ │ - var interOptions = { │ │ │ │ │ - point: true, │ │ │ │ │ - tolerance: tolerance │ │ │ │ │ - }; │ │ │ │ │ - var result = null; │ │ │ │ │ - for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ - vert1 = verts[i]; │ │ │ │ │ - points.push(vert1.clone()); │ │ │ │ │ - vert2 = verts[i + 1]; │ │ │ │ │ - target = { │ │ │ │ │ - x1: vert1.x, │ │ │ │ │ - y1: vert1.y, │ │ │ │ │ - x2: vert2.x, │ │ │ │ │ - y2: vert2.y │ │ │ │ │ - }; │ │ │ │ │ - point = OpenLayers.Geometry.segmentsIntersect( │ │ │ │ │ - seg, target, interOptions │ │ │ │ │ - ); │ │ │ │ │ - if (point instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - if ((point.x === seg.x1 && point.y === seg.y1) || │ │ │ │ │ - (point.x === seg.x2 && point.y === seg.y2) || │ │ │ │ │ - point.equals(vert1) || point.equals(vert2)) { │ │ │ │ │ - vertex = true; │ │ │ │ │ - } else { │ │ │ │ │ - vertex = false; │ │ │ │ │ - } │ │ │ │ │ - if (vertex || edge) { │ │ │ │ │ - // push intersections different than the previous │ │ │ │ │ - if (!point.equals(intersections[intersections.length - 1])) { │ │ │ │ │ - intersections.push(point.clone()); │ │ │ │ │ - } │ │ │ │ │ - if (i === 0) { │ │ │ │ │ - if (point.equals(vert1)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (point.equals(vert2)) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - split = true; │ │ │ │ │ - if (!point.equals(vert1)) { │ │ │ │ │ - points.push(point); │ │ │ │ │ - } │ │ │ │ │ - lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - points = [point.clone()]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (split) { │ │ │ │ │ - points.push(vert2.clone()); │ │ │ │ │ - lines.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - } │ │ │ │ │ - if (intersections.length > 0) { │ │ │ │ │ - // sort intersections along segment │ │ │ │ │ - var xDir = seg.x1 < seg.x2 ? 1 : -1; │ │ │ │ │ - var yDir = seg.y1 < seg.y2 ? 1 : -1; │ │ │ │ │ - result = { │ │ │ │ │ - lines: lines, │ │ │ │ │ - points: intersections.sort(function(p1, p2) { │ │ │ │ │ - return (xDir * p1.x - xDir * p2.x) || (yDir * p1.y - yDir * p2.y); │ │ │ │ │ - }) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - return result; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: split │ │ │ │ │ - * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {} The target geometry. │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ - * geometry. Default is false. │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ - * distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of an existing vertex on the source │ │ │ │ │ - * will be assumed to occur at the vertex. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ - * result from splitting the target with the source geometry. The │ │ │ │ │ - * source and target geometry will remain unmodified. If no split │ │ │ │ │ - * results, null will be returned. If mutual is true and a split │ │ │ │ │ - * results, return will be an array of two arrays - the first will be │ │ │ │ │ - * all geometries that result from splitting the source geometry and │ │ │ │ │ - * the second will be all geometries that result from splitting the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - split: function(target, options) { │ │ │ │ │ - var results = null; │ │ │ │ │ - var mutual = options && options.mutual; │ │ │ │ │ - var sourceSplit, targetSplit, sourceParts, targetParts; │ │ │ │ │ - if (target instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ - var verts = this.getVertices(); │ │ │ │ │ - var vert1, vert2, seg, splits, lines, point; │ │ │ │ │ - var points = []; │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - for (var i = 0, stop = verts.length - 2; i <= stop; ++i) { │ │ │ │ │ - vert1 = verts[i]; │ │ │ │ │ - vert2 = verts[i + 1]; │ │ │ │ │ - seg = { │ │ │ │ │ - x1: vert1.x, │ │ │ │ │ - y1: vert1.y, │ │ │ │ │ - x2: vert2.x, │ │ │ │ │ - y2: vert2.y │ │ │ │ │ - }; │ │ │ │ │ - targetParts = targetParts || [target]; │ │ │ │ │ - if (mutual) { │ │ │ │ │ - points.push(vert1.clone()); │ │ │ │ │ - } │ │ │ │ │ - for (var j = 0; j < targetParts.length; ++j) { │ │ │ │ │ - splits = targetParts[j].splitWithSegment(seg, options); │ │ │ │ │ - if (splits) { │ │ │ │ │ - // splice in new features │ │ │ │ │ - lines = splits.lines; │ │ │ │ │ - if (lines.length > 0) { │ │ │ │ │ - lines.unshift(j, 1); │ │ │ │ │ - Array.prototype.splice.apply(targetParts, lines); │ │ │ │ │ - j += lines.length - 2; │ │ │ │ │ - } │ │ │ │ │ - if (mutual) { │ │ │ │ │ - for (var k = 0, len = splits.points.length; k < len; ++k) { │ │ │ │ │ - point = splits.points[k]; │ │ │ │ │ - if (!point.equals(vert1)) { │ │ │ │ │ - points.push(point); │ │ │ │ │ - sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - if (point.equals(vert2)) { │ │ │ │ │ - points = []; │ │ │ │ │ - } else { │ │ │ │ │ - points = [point.clone()]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (mutual && sourceParts.length > 0 && points.length > 0) { │ │ │ │ │ - points.push(vert2.clone()); │ │ │ │ │ - sourceParts.push(new OpenLayers.Geometry.LineString(points)); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - results = target.splitWith(this, options); │ │ │ │ │ - } │ │ │ │ │ - if (targetParts && targetParts.length > 1) { │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - targetParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - } else { │ │ │ │ │ - sourceParts = []; │ │ │ │ │ - } │ │ │ │ │ - if (targetSplit || sourceSplit) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - results = [sourceParts, targetParts]; │ │ │ │ │ - } else { │ │ │ │ │ - results = targetParts; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return results; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: splitWith │ │ │ │ │ - * Split this geometry (the target) with the given geometry (the source). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} A geometry used to split this │ │ │ │ │ - * geometry (the source). │ │ │ │ │ - * options - {Object} Properties of this object will be used to determine │ │ │ │ │ - * how the split is conducted. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * mutual - {Boolean} Split the source geometry in addition to the target │ │ │ │ │ - * geometry. Default is false. │ │ │ │ │ - * edge - {Boolean} Allow splitting when only edges intersect. Default is │ │ │ │ │ - * true. If false, a vertex on the source must be within the tolerance │ │ │ │ │ - * distance of the intersection to be considered a split. │ │ │ │ │ - * tolerance - {Number} If a non-null value is provided, intersections │ │ │ │ │ - * within the tolerance distance of an existing vertex on the source │ │ │ │ │ - * will be assumed to occur at the vertex. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of geometries (of this same type as the target) that │ │ │ │ │ - * result from splitting the target with the source geometry. The │ │ │ │ │ - * source and target geometry will remain unmodified. If no split │ │ │ │ │ - * results, null will be returned. If mutual is true and a split │ │ │ │ │ - * results, return will be an array of two arrays - the first will be │ │ │ │ │ - * all geometries that result from splitting the source geometry and │ │ │ │ │ - * the second will be all geometries that result from splitting the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - splitWith: function(geometry, options) { │ │ │ │ │ - return geometry.split(this, options); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getVertices │ │ │ │ │ - * Return a list of all points in this geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * nodes - {Boolean} For lines, only return vertices that are │ │ │ │ │ - * endpoints. If false, for lines, only vertices that are not │ │ │ │ │ - * endpoints will be returned. If not provided, all vertices will │ │ │ │ │ - * be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} A list of all vertices in the geometry. │ │ │ │ │ - */ │ │ │ │ │ - getVertices: function(nodes) { │ │ │ │ │ - var vertices; │ │ │ │ │ - if (nodes === true) { │ │ │ │ │ - vertices = [ │ │ │ │ │ - this.components[0], │ │ │ │ │ - this.components[this.components.length - 1] │ │ │ │ │ - ]; │ │ │ │ │ - } else if (nodes === false) { │ │ │ │ │ - vertices = this.components.slice(1, this.components.length - 1); │ │ │ │ │ - } else { │ │ │ │ │ - vertices = this.components.slice(); │ │ │ │ │ - } │ │ │ │ │ - return vertices; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: distanceTo │ │ │ │ │ - * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} The target geometry. │ │ │ │ │ - * options - {Object} Optional properties for configuring the distance │ │ │ │ │ - * calculation. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * details - {Boolean} Return details from the distance calculation. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * edge - {Boolean} Calculate the distance from this geometry to the │ │ │ │ │ - * nearest edge of the target geometry. Default is true. If true, │ │ │ │ │ - * calling distanceTo from a geometry that is wholly contained within │ │ │ │ │ - * the target will result in a non-zero distance. If false, whenever │ │ │ │ │ - * geometries intersect, calling distanceTo will return 0. If false, │ │ │ │ │ - * details cannot be returned. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number | Object} The distance between this geometry and the target. │ │ │ │ │ - * If details is true, the return will be an object with distance, │ │ │ │ │ - * x0, y0, x1, and x2 properties. The x0 and y0 properties represent │ │ │ │ │ - * the coordinates of the closest point on this geometry. The x1 and y1 │ │ │ │ │ - * properties represent the coordinates of the closest point on the │ │ │ │ │ - * target geometry. │ │ │ │ │ - */ │ │ │ │ │ - distanceTo: function(geometry, options) { │ │ │ │ │ - var edge = !(options && options.edge === false); │ │ │ │ │ - var details = edge && options && options.details; │ │ │ │ │ - var result, best = {}; │ │ │ │ │ - var min = Number.POSITIVE_INFINITY; │ │ │ │ │ - if (geometry instanceof OpenLayers.Geometry.Point) { │ │ │ │ │ - var segs = this.getSortedSegments(); │ │ │ │ │ - var x = geometry.x; │ │ │ │ │ - var y = geometry.y; │ │ │ │ │ - var seg; │ │ │ │ │ - for (var i = 0, len = segs.length; i < len; ++i) { │ │ │ │ │ - seg = segs[i]; │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment(geometry, seg); │ │ │ │ │ - if (result.distance < min) { │ │ │ │ │ - min = result.distance; │ │ │ │ │ - best = result; │ │ │ │ │ - if (min === 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // if distance increases and we cross y0 to the right of x0, no need to keep looking. │ │ │ │ │ - if (seg.x2 > x && ((y > seg.y1 && y < seg.y2) || (y < seg.y1 && y > seg.y2))) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: best.distance, │ │ │ │ │ - x0: best.x, │ │ │ │ │ - y0: best.y, │ │ │ │ │ - x1: x, │ │ │ │ │ - y1: y │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - best = best.distance; │ │ │ │ │ - } │ │ │ │ │ - } else if (geometry instanceof OpenLayers.Geometry.LineString) { │ │ │ │ │ - var segs0 = this.getSortedSegments(); │ │ │ │ │ - var segs1 = geometry.getSortedSegments(); │ │ │ │ │ - var seg0, seg1, intersection, x0, y0; │ │ │ │ │ - var len1 = segs1.length; │ │ │ │ │ - var interOptions = { │ │ │ │ │ - point: true │ │ │ │ │ - }; │ │ │ │ │ - outer: for (var i = 0, len = segs0.length; i < len; ++i) { │ │ │ │ │ - seg0 = segs0[i]; │ │ │ │ │ - x0 = seg0.x1; │ │ │ │ │ - y0 = seg0.y1; │ │ │ │ │ - for (var j = 0; j < len1; ++j) { │ │ │ │ │ - seg1 = segs1[j]; │ │ │ │ │ - intersection = OpenLayers.Geometry.segmentsIntersect(seg0, seg1, interOptions); │ │ │ │ │ - if (intersection) { │ │ │ │ │ - min = 0; │ │ │ │ │ - best = { │ │ │ │ │ - distance: 0, │ │ │ │ │ - x0: intersection.x, │ │ │ │ │ - y0: intersection.y, │ │ │ │ │ - x1: intersection.x, │ │ │ │ │ - y1: intersection.y │ │ │ │ │ - }; │ │ │ │ │ - break outer; │ │ │ │ │ - } else { │ │ │ │ │ - result = OpenLayers.Geometry.distanceToSegment({ │ │ │ │ │ - x: x0, │ │ │ │ │ - y: y0 │ │ │ │ │ - }, seg1); │ │ │ │ │ - if (result.distance < min) { │ │ │ │ │ - min = result.distance; │ │ │ │ │ - best = { │ │ │ │ │ - distance: min, │ │ │ │ │ - x0: x0, │ │ │ │ │ - y0: y0, │ │ │ │ │ - x1: result.x, │ │ │ │ │ - y1: result.y │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!details) { │ │ │ │ │ - best = best.distance; │ │ │ │ │ - } │ │ │ │ │ - if (min !== 0) { │ │ │ │ │ - // check the final vertex in this line's sorted segments │ │ │ │ │ - if (seg0) { │ │ │ │ │ - result = geometry.distanceTo( │ │ │ │ │ - new OpenLayers.Geometry.Point(seg0.x2, seg0.y2), │ │ │ │ │ - options │ │ │ │ │ - ); │ │ │ │ │ - var dist = details ? result.distance : result; │ │ │ │ │ - if (dist < min) { │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: min, │ │ │ │ │ - x0: result.x1, │ │ │ │ │ - y0: result.y1, │ │ │ │ │ - x1: result.x0, │ │ │ │ │ - y1: result.y0 │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - best = dist; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - best = geometry.distanceTo(this, options); │ │ │ │ │ - // swap since target comes from this line │ │ │ │ │ - if (details) { │ │ │ │ │ - best = { │ │ │ │ │ - distance: best.distance, │ │ │ │ │ - x0: best.x1, │ │ │ │ │ - y0: best.y1, │ │ │ │ │ - x1: best.x0, │ │ │ │ │ - y1: best.y0 │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return best; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: simplify │ │ │ │ │ - * This function will return a simplified LineString. │ │ │ │ │ - * Simplification is based on the Douglas-Peucker algorithm. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tolerance - {number} threshhold for simplification in map units │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {OpenLayers.Geometry.LineString} the simplified LineString │ │ │ │ │ - */ │ │ │ │ │ - simplify: function(tolerance) { │ │ │ │ │ - if (this && this !== null) { │ │ │ │ │ - var points = this.getVertices(); │ │ │ │ │ - if (points.length < 3) { │ │ │ │ │ - return this; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var compareNumbers = function(a, b) { │ │ │ │ │ - return (a - b); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Private function doing the Douglas-Peucker reduction │ │ │ │ │ - */ │ │ │ │ │ - var douglasPeuckerReduction = function(points, firstPoint, lastPoint, tolerance) { │ │ │ │ │ - var maxDistance = 0; │ │ │ │ │ - var indexFarthest = 0; │ │ │ │ │ - │ │ │ │ │ - for (var index = firstPoint, distance; index < lastPoint; index++) { │ │ │ │ │ - distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]); │ │ │ │ │ - if (distance > maxDistance) { │ │ │ │ │ - maxDistance = distance; │ │ │ │ │ - indexFarthest = index; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (maxDistance > tolerance && indexFarthest != firstPoint) { │ │ │ │ │ - //Add the largest point that exceeds the tolerance │ │ │ │ │ - pointIndexsToKeep.push(indexFarthest); │ │ │ │ │ - douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance); │ │ │ │ │ - douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Private function calculating the perpendicular distance │ │ │ │ │ - * TODO: check whether OpenLayers.Geometry.LineString::distanceTo() is faster or slower │ │ │ │ │ - */ │ │ │ │ │ - var perpendicularDistance = function(point1, point2, point) { │ │ │ │ │ - //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)| *Area of triangle │ │ │ │ │ - //Base = v((x1-x2)²+(x1-x2)²) *Base of Triangle* │ │ │ │ │ - //Area = .5*Base*H *Solve for height │ │ │ │ │ - //Height = Area/.5/Base │ │ │ │ │ - │ │ │ │ │ - var area = Math.abs(0.5 * (point1.x * point2.y + point2.x * point.y + point.x * point1.y - point2.x * point1.y - point.x * point2.y - point1.x * point.y)); │ │ │ │ │ - var bottom = Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)); │ │ │ │ │ - var height = area / bottom * 2; │ │ │ │ │ - │ │ │ │ │ - return height; │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - var firstPoint = 0; │ │ │ │ │ - var lastPoint = points.length - 1; │ │ │ │ │ - var pointIndexsToKeep = []; │ │ │ │ │ - │ │ │ │ │ - //Add the first and last index to the keepers │ │ │ │ │ - pointIndexsToKeep.push(firstPoint); │ │ │ │ │ - pointIndexsToKeep.push(lastPoint); │ │ │ │ │ - │ │ │ │ │ - //The first and the last point cannot be the same │ │ │ │ │ - while (points[firstPoint].equals(points[lastPoint])) { │ │ │ │ │ - lastPoint--; │ │ │ │ │ - //Addition: the first point not equal to first point in the LineString is kept as well │ │ │ │ │ - pointIndexsToKeep.push(lastPoint); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - douglasPeuckerReduction(points, firstPoint, lastPoint, tolerance); │ │ │ │ │ - var returnPoints = []; │ │ │ │ │ - pointIndexsToKeep.sort(compareNumbers); │ │ │ │ │ - for (var index = 0; index < pointIndexsToKeep.length; index++) { │ │ │ │ │ - returnPoints.push(points[pointIndexsToKeep[index]]); │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Geometry.LineString(returnPoints); │ │ │ │ │ - │ │ │ │ │ - } else { │ │ │ │ │ - return this; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Geometry.LineString" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Geometry/MultiLineString.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of 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 │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Geometry.MultiLineString │ │ │ │ │ - * A MultiLineString is a geometry with multiple │ │ │ │ │ - * components. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Geometry.MultiLineString = 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.LineString"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Geometry.MultiLineString │ │ │ │ │ - * Constructor for a MultiLineString Geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * components - {Array()} │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiLineString │ │ │ │ │ + * Constructor for a MultiLineString Geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: split │ │ │ │ │ * Use this geometry (the source) to attempt to split a target geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * geometry - {} The target geometry. │ │ │ │ │ @@ -22676,379 +18049,1555 @@ │ │ │ │ │ "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Format.WPSExecute" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Request/XMLHttpRequest.js │ │ │ │ │ + OpenLayers/Events.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/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -(function() { │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Event │ │ │ │ │ + * Utility functions for event handling. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Event = { │ │ │ │ │ │ │ │ │ │ - // Save reference to earlier defined object implementation (if any) │ │ │ │ │ - var oXMLHttpRequest = window.XMLHttpRequest; │ │ │ │ │ + /** │ │ │ │ │ + * Property: observers │ │ │ │ │ + * {Object} A hashtable cache of the event observers. Keyed by │ │ │ │ │ + * element._eventCacheID │ │ │ │ │ + */ │ │ │ │ │ + observers: false, │ │ │ │ │ │ │ │ │ │ - // Define on browser type │ │ │ │ │ - var bGecko = !!window.controllers, │ │ │ │ │ - bIE = window.document.all && !window.opera, │ │ │ │ │ - bIE7 = bIE && window.navigator.userAgent.match(/MSIE 7.0/); │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_SPACE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_SPACE: 32, │ │ │ │ │ │ │ │ │ │ - // Enables "XMLHttpRequest()" call next to "new XMLHttpReques()" │ │ │ │ │ - function fXMLHttpRequest() { │ │ │ │ │ - this._object = oXMLHttpRequest && !bIE7 ? new oXMLHttpRequest : new window.ActiveXObject("Microsoft.XMLHTTP"); │ │ │ │ │ - this._listeners = []; │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_BACKSPACE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_BACKSPACE: 8, │ │ │ │ │ │ │ │ │ │ - // Constructor │ │ │ │ │ - function cXMLHttpRequest() { │ │ │ │ │ - return new fXMLHttpRequest; │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype = fXMLHttpRequest.prototype; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_TAB │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_TAB: 9, │ │ │ │ │ │ │ │ │ │ - // BUGFIX: Firefox with Firebug installed would break pages if not executed │ │ │ │ │ - if (bGecko && oXMLHttpRequest.wrapped) │ │ │ │ │ - cXMLHttpRequest.wrapped = oXMLHttpRequest.wrapped; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_RETURN │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_RETURN: 13, │ │ │ │ │ │ │ │ │ │ - // Constants │ │ │ │ │ - cXMLHttpRequest.UNSENT = 0; │ │ │ │ │ - cXMLHttpRequest.OPENED = 1; │ │ │ │ │ - cXMLHttpRequest.HEADERS_RECEIVED = 2; │ │ │ │ │ - cXMLHttpRequest.LOADING = 3; │ │ │ │ │ - cXMLHttpRequest.DONE = 4; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_ESC │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_ESC: 27, │ │ │ │ │ │ │ │ │ │ - // Public Properties │ │ │ │ │ - cXMLHttpRequest.prototype.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ - cXMLHttpRequest.prototype.responseText = ''; │ │ │ │ │ - cXMLHttpRequest.prototype.responseXML = null; │ │ │ │ │ - cXMLHttpRequest.prototype.status = 0; │ │ │ │ │ - cXMLHttpRequest.prototype.statusText = ''; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_LEFT │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_LEFT: 37, │ │ │ │ │ │ │ │ │ │ - // Priority proposal │ │ │ │ │ - cXMLHttpRequest.prototype.priority = "NORMAL"; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_UP │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_UP: 38, │ │ │ │ │ │ │ │ │ │ - // Instance-level Events Handlers │ │ │ │ │ - cXMLHttpRequest.prototype.onreadystatechange = null; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_RIGHT │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_RIGHT: 39, │ │ │ │ │ │ │ │ │ │ - // Class-level Events Handlers │ │ │ │ │ - cXMLHttpRequest.onreadystatechange = null; │ │ │ │ │ - cXMLHttpRequest.onopen = null; │ │ │ │ │ - cXMLHttpRequest.onsend = null; │ │ │ │ │ - cXMLHttpRequest.onabort = null; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_DOWN │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_DOWN: 40, │ │ │ │ │ │ │ │ │ │ - // Public Methods │ │ │ │ │ - cXMLHttpRequest.prototype.open = function(sMethod, sUrl, bAsync, sUser, sPassword) { │ │ │ │ │ - // Delete headers, required when object is reused │ │ │ │ │ - delete this._headers; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_DELETE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_DELETE: 46, │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ + /** │ │ │ │ │ + * Method: element │ │ │ │ │ + * Cross browser event element detection. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element that caused the event │ │ │ │ │ + */ │ │ │ │ │ + element: function(event) { │ │ │ │ │ + return event.target || event.srcElement; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Set the onreadystatechange handler │ │ │ │ │ - var oRequest = this, │ │ │ │ │ - nState = this.readyState, │ │ │ │ │ - fOnUnload; │ │ │ │ │ + /** │ │ │ │ │ + * Method: isSingleTouch │ │ │ │ │ + * Determine whether event was caused by a single touch │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isSingleTouch: function(event) { │ │ │ │ │ + return event.touches && event.touches.length == 1; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: isMultiTouch │ │ │ │ │ + * Determine whether event was caused by a multi touch │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isMultiTouch: function(event) { │ │ │ │ │ + return event.touches && event.touches.length > 1; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Add method sniffer │ │ │ │ │ - if (cXMLHttpRequest.onopen) │ │ │ │ │ - cXMLHttpRequest.onopen.apply(this, arguments); │ │ │ │ │ + /** │ │ │ │ │ + * Method: isLeftClick │ │ │ │ │ + * Determine whether event was caused by a left click. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isLeftClick: function(event) { │ │ │ │ │ + return (((event.which) && (event.which == 1)) || │ │ │ │ │ + ((event.button) && (event.button == 1))); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + /** │ │ │ │ │ + * Method: isRightClick │ │ │ │ │ + * Determine whether event was caused by a right mouse click. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isRightClick: function(event) { │ │ │ │ │ + return (((event.which) && (event.which == 3)) || │ │ │ │ │ + ((event.button) && (event.button == 2))); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ - fReadyStateChange(this); │ │ │ │ │ + /** │ │ │ │ │ + * Method: stop │ │ │ │ │ + * Stops an event from propagating. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * allowDefault - {Boolean} If true, we stop the event chain but │ │ │ │ │ + * still allow the default browser behaviour (text selection, │ │ │ │ │ + * radio-button clicking, etc). Default is false. │ │ │ │ │ + */ │ │ │ │ │ + stop: function(event, allowDefault) { │ │ │ │ │ │ │ │ │ │ - this._object.onreadystatechange = function() { │ │ │ │ │ - if (bGecko && !bAsync) │ │ │ │ │ - return; │ │ │ │ │ + if (!allowDefault) { │ │ │ │ │ + OpenLayers.Event.preventDefault(event); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // Synchronize state │ │ │ │ │ - oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ + if (event.stopPropagation) { │ │ │ │ │ + event.stopPropagation(); │ │ │ │ │ + } else { │ │ │ │ │ + event.cancelBubble = true; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ + /** │ │ │ │ │ + * Method: preventDefault │ │ │ │ │ + * Cancels the event if it is cancelable, without stopping further │ │ │ │ │ + * propagation of the event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + */ │ │ │ │ │ + preventDefault: function(event) { │ │ │ │ │ + if (event.preventDefault) { │ │ │ │ │ + event.preventDefault(); │ │ │ │ │ + } else { │ │ │ │ │ + event.returnValue = false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // BUGFIX: Firefox fires unnecessary DONE when aborting │ │ │ │ │ - if (oRequest._aborted) { │ │ │ │ │ - // Reset readyState to UNSENT │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + /** │ │ │ │ │ + * Method: findElement │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ + * tagName - {String} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The first node with the given tagName, starting from the │ │ │ │ │ + * node the event was triggered on and traversing the DOM upwards │ │ │ │ │ + */ │ │ │ │ │ + findElement: function(event, tagName) { │ │ │ │ │ + var element = OpenLayers.Event.element(event); │ │ │ │ │ + while (element.parentNode && (!element.tagName || │ │ │ │ │ + (element.tagName.toUpperCase() != tagName.toUpperCase()))) { │ │ │ │ │ + element = element.parentNode; │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Return now │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: observe │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * elementParam - {DOMElement || String} │ │ │ │ │ + * name - {String} │ │ │ │ │ + * observer - {function} │ │ │ │ │ + * useCapture - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + observe: function(elementParam, name, observer, useCapture) { │ │ │ │ │ + var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ + useCapture = useCapture || false; │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + if (name == 'keypress' && │ │ │ │ │ + (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ + element.attachEvent)) { │ │ │ │ │ + name = 'keydown'; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // Instantiate a new transport object │ │ │ │ │ - cXMLHttpRequest.call(oRequest); │ │ │ │ │ + //if observers cache has not yet been created, create it │ │ │ │ │ + if (!this.observers) { │ │ │ │ │ + this.observers = {}; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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]); │ │ │ │ │ + //if not already assigned, make a new unique cache ID │ │ │ │ │ + if (!element._eventCacheID) { │ │ │ │ │ + var idPrefix = "eventCacheID_"; │ │ │ │ │ + if (element.id) { │ │ │ │ │ + idPrefix = element.id + "_" + idPrefix; │ │ │ │ │ + } │ │ │ │ │ + element._eventCacheID = OpenLayers.Util.createUniqueID(idPrefix); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - oRequest._object.onreadystatechange = function() { │ │ │ │ │ - // Synchronize state │ │ │ │ │ - oRequest.readyState = oRequest._object.readyState; │ │ │ │ │ + var cacheID = element._eventCacheID; │ │ │ │ │ │ │ │ │ │ - if (oRequest._aborted) { │ │ │ │ │ - // │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + //if there is not yet a hash entry for this element, add one │ │ │ │ │ + if (!this.observers[cacheID]) { │ │ │ │ │ + this.observers[cacheID] = []; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // Return │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + //add a new observer to this element's list │ │ │ │ │ + this.observers[cacheID].push({ │ │ │ │ │ + 'element': element, │ │ │ │ │ + 'name': name, │ │ │ │ │ + 'observer': observer, │ │ │ │ │ + 'useCapture': useCapture │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - if (oRequest.readyState == cXMLHttpRequest.DONE) { │ │ │ │ │ - // Clean Object │ │ │ │ │ - fCleanTransport(oRequest); │ │ │ │ │ + //add the actual browser event listener │ │ │ │ │ + if (element.addEventListener) { │ │ │ │ │ + element.addEventListener(name, observer, useCapture); │ │ │ │ │ + } else if (element.attachEvent) { │ │ │ │ │ + element.attachEvent('on' + name, observer); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // get cached request │ │ │ │ │ - if (oRequest.status == 304) │ │ │ │ │ - oRequest._object = oRequest._cached; │ │ │ │ │ + /** │ │ │ │ │ + * Method: stopObservingElement │ │ │ │ │ + * Given the id of an element to stop observing, cycle through the │ │ │ │ │ + * element's cached observers, calling stopObserving on each one, │ │ │ │ │ + * skipping those entries which can no longer be removed. │ │ │ │ │ + * │ │ │ │ │ + * parameters: │ │ │ │ │ + * elementParam - {DOMElement || String} │ │ │ │ │ + */ │ │ │ │ │ + stopObservingElement: function(elementParam) { │ │ │ │ │ + var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ + var cacheID = element._eventCacheID; │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - delete oRequest._cached; │ │ │ │ │ + this._removeElementObservers(OpenLayers.Event.observers[cacheID]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ + /** │ │ │ │ │ + * Method: _removeElementObservers │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * elementObservers - {Array(Object)} Array of (element, name, │ │ │ │ │ + * observer, usecapture) objects, │ │ │ │ │ + * taken directly from hashtable │ │ │ │ │ + */ │ │ │ │ │ + _removeElementObservers: function(elementObservers) { │ │ │ │ │ + if (elementObservers) { │ │ │ │ │ + for (var i = elementObservers.length - 1; i >= 0; i--) { │ │ │ │ │ + var entry = elementObservers[i]; │ │ │ │ │ + OpenLayers.Event.stopObserving.apply(this, [ │ │ │ │ │ + entry.element, entry.name, entry.observer, entry.useCapture │ │ │ │ │ + ]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - fReadyStateChange(oRequest); │ │ │ │ │ + /** │ │ │ │ │ + * Method: stopObserving │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * elementParam - {DOMElement || String} │ │ │ │ │ + * name - {String} │ │ │ │ │ + * observer - {function} │ │ │ │ │ + * useCapture - {Boolean} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the event observer was removed │ │ │ │ │ + */ │ │ │ │ │ + stopObserving: function(elementParam, name, observer, useCapture) { │ │ │ │ │ + useCapture = useCapture || false; │ │ │ │ │ │ │ │ │ │ - // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ - if (bIE && bAsync) │ │ │ │ │ - window.detachEvent("onunload", fOnUnload); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - oRequest._object.send(null); │ │ │ │ │ + var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ + var cacheID = element._eventCacheID; │ │ │ │ │ │ │ │ │ │ - // Return now - wait until re-sent request is finished │ │ │ │ │ - return; │ │ │ │ │ - }; │ │ │ │ │ - */ │ │ │ │ │ - // BUGFIX: IE - memory leak in interrupted │ │ │ │ │ - if (bIE && bAsync) │ │ │ │ │ - window.detachEvent("onunload", fOnUnload); │ │ │ │ │ + if (name == 'keypress') { │ │ │ │ │ + if (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ + element.detachEvent) { │ │ │ │ │ + name = 'keydown'; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // 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); │ │ │ │ │ + // find element's entry in this.observers cache and remove it │ │ │ │ │ + var foundEntry = false; │ │ │ │ │ + var elementObservers = OpenLayers.Event.observers[cacheID]; │ │ │ │ │ + if (elementObservers) { │ │ │ │ │ │ │ │ │ │ - // BUGFIX: Gecko - missing readystatechange calls in synchronous requests │ │ │ │ │ - if (bGecko && !oRequest._async) { │ │ │ │ │ - oRequest.readyState = cXMLHttpRequest.OPENED; │ │ │ │ │ + // find the specific event type in the element's list │ │ │ │ │ + var i = 0; │ │ │ │ │ + while (!foundEntry && i < elementObservers.length) { │ │ │ │ │ + var cacheEntry = elementObservers[i]; │ │ │ │ │ │ │ │ │ │ - // Synchronize state │ │ │ │ │ - fSynchronizeValues(oRequest); │ │ │ │ │ + if ((cacheEntry.name == name) && │ │ │ │ │ + (cacheEntry.observer == observer) && │ │ │ │ │ + (cacheEntry.useCapture == useCapture)) { │ │ │ │ │ │ │ │ │ │ - // Simulate missing states │ │ │ │ │ - while (oRequest.readyState < cXMLHttpRequest.DONE) { │ │ │ │ │ - oRequest.readyState++; │ │ │ │ │ - fReadyStateChange(oRequest); │ │ │ │ │ - // Check if we are aborted │ │ │ │ │ - if (oRequest._aborted) │ │ │ │ │ - return; │ │ │ │ │ + elementObservers.splice(i, 1); │ │ │ │ │ + if (elementObservers.length == 0) { │ │ │ │ │ + delete OpenLayers.Event.observers[cacheID]; │ │ │ │ │ + } │ │ │ │ │ + foundEntry = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + i++; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - cXMLHttpRequest.prototype.send = function(vData) { │ │ │ │ │ - // Add method sniffer │ │ │ │ │ - if (cXMLHttpRequest.onsend) │ │ │ │ │ - cXMLHttpRequest.onsend.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - if (!arguments.length) │ │ │ │ │ - vData = null; │ │ │ │ │ + //actually remove the event listener from browser │ │ │ │ │ + if (foundEntry) { │ │ │ │ │ + if (element.removeEventListener) { │ │ │ │ │ + element.removeEventListener(name, observer, useCapture); │ │ │ │ │ + } else if (element && element.detachEvent) { │ │ │ │ │ + element.detachEvent('on' + name, observer); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return foundEntry; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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"); │ │ │ │ │ + /** │ │ │ │ │ + * Method: unloadCache │ │ │ │ │ + * Cycle through all the element entries in the events cache and call │ │ │ │ │ + * stopObservingElement on each. │ │ │ │ │ + */ │ │ │ │ │ + unloadCache: function() { │ │ │ │ │ + // check for OpenLayers.Event before checking for observers, because │ │ │ │ │ + // OpenLayers.Event may be undefined in IE if no map instance was │ │ │ │ │ + // created │ │ │ │ │ + if (OpenLayers.Event && OpenLayers.Event.observers) { │ │ │ │ │ + for (var cacheID in OpenLayers.Event.observers) { │ │ │ │ │ + var elementObservers = OpenLayers.Event.observers[cacheID]; │ │ │ │ │ + OpenLayers.Event._removeElementObservers.apply(this, │ │ │ │ │ + [elementObservers]); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.observers = false; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Event" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - // BUGFIX: Gecko - unnecessary DONE when aborting │ │ │ │ │ - if (this.readyState > cXMLHttpRequest.UNSENT) │ │ │ │ │ - this._aborted = true; │ │ │ │ │ +/* prevent memory leaks in IE */ │ │ │ │ │ +OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, false); │ │ │ │ │ │ │ │ │ │ - this._object.abort(); │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Events │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Events = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - // BUGFIX: IE - memory leak │ │ │ │ │ - fCleanTransport(this); │ │ │ │ │ + /** │ │ │ │ │ + * Constant: BROWSER_EVENTS │ │ │ │ │ + * {Array(String)} supported events │ │ │ │ │ + */ │ │ │ │ │ + BROWSER_EVENTS: [ │ │ │ │ │ + "mouseover", "mouseout", │ │ │ │ │ + "mousedown", "mouseup", "mousemove", │ │ │ │ │ + "click", "dblclick", "rightclick", "dblrightclick", │ │ │ │ │ + "resize", "focus", "blur", │ │ │ │ │ + "touchstart", "touchmove", "touchend", │ │ │ │ │ + "keydown" │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ - this.readyState = cXMLHttpRequest.UNSENT; │ │ │ │ │ + /** │ │ │ │ │ + * Property: listeners │ │ │ │ │ + * {Object} Hashtable of Array(Function): events listener functions │ │ │ │ │ + */ │ │ │ │ │ + listeners: null, │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + /** │ │ │ │ │ + * Property: object │ │ │ │ │ + * {Object} the code object issuing application events │ │ │ │ │ + */ │ │ │ │ │ + object: null, │ │ │ │ │ │ │ │ │ │ - return this._object.setRequestHeader(sName, sValue); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} the DOM element receiving browser events │ │ │ │ │ + */ │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ - // 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]); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Property: eventHandler │ │ │ │ │ + * {Function} bound event handler attached to elements │ │ │ │ │ + */ │ │ │ │ │ + eventHandler: null, │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fallThrough │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + fallThrough: null, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: includeXY │ │ │ │ │ + * {Boolean} Should the .xy property automatically be created for browser │ │ │ │ │ + * mouse events? In general, this should be false. If it is true, then │ │ │ │ │ + * mouse events will automatically generate a '.xy' property on the │ │ │ │ │ + * event object that is passed. (Prior to OpenLayers 2.7, this was true │ │ │ │ │ + * by default.) Otherwise, you can call the getMousePosition on the │ │ │ │ │ + * relevant events handler on the object available via the 'evt.object' │ │ │ │ │ + * property of the evt object. So, for most events, you can call: │ │ │ │ │ + * function named(evt) { │ │ │ │ │ + * this.xy = this.object.events.getMousePosition(evt) │ │ │ │ │ + * } │ │ │ │ │ + * │ │ │ │ │ + * This option typically defaults to false for performance reasons: │ │ │ │ │ + * when creating an events object whose primary purpose is to manage │ │ │ │ │ + * relatively positioned mouse events within a div, it may make │ │ │ │ │ + * sense to set it to true. │ │ │ │ │ + * │ │ │ │ │ + * This option is also used to control whether the events object caches │ │ │ │ │ + * offsets. If this is false, it will not: the reason for this is that │ │ │ │ │ + * it is only expected to be called many times if the includeXY property │ │ │ │ │ + * is set to true. If you set this to true, you are expected to clear │ │ │ │ │ + * the offset cache manually (using this.clearMouseCache()) if: │ │ │ │ │ + * the border of the element changes │ │ │ │ │ + * the location of the element in the page changes │ │ │ │ │ + */ │ │ │ │ │ + includeXY: false, │ │ │ │ │ │ │ │ │ │ - // Execute onreadystatechange │ │ │ │ │ - if (oEventPseudo.type == "readystatechange" && this.onreadystatechange) │ │ │ │ │ - (this.onreadystatechange.handleEvent || this.onreadystatechange).apply(this, [oEventPseudo]); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: extensions │ │ │ │ │ + * {Object} Event extensions registered with this instance. Keys are │ │ │ │ │ + * event types, values are {OpenLayers.Events.*} extension instances or │ │ │ │ │ + * {Boolean} for events that an instantiated extension provides in │ │ │ │ │ + * addition to the one it was created for. │ │ │ │ │ + * │ │ │ │ │ + * Extensions create an event in addition to browser events, which usually │ │ │ │ │ + * fires when a sequence of browser events is completed. Extensions are │ │ │ │ │ + * automatically instantiated when a listener is registered for an event │ │ │ │ │ + * provided by an extension. │ │ │ │ │ + * │ │ │ │ │ + * Extensions are created in the namespace using │ │ │ │ │ + * , and named after the event they provide. │ │ │ │ │ + * The constructor receives the target instance as │ │ │ │ │ + * argument. Extensions that need to capture browser events before they │ │ │ │ │ + * propagate can register their listeners events using , with │ │ │ │ │ + * {extension: true} as 4th argument. │ │ │ │ │ + * │ │ │ │ │ + * If an extension creates more than one event, an alias for each event │ │ │ │ │ + * type should be created and reference the same class. The constructor │ │ │ │ │ + * should set a reference in the target's extensions registry to itself. │ │ │ │ │ + * │ │ │ │ │ + * Below is a minimal extension that provides the "foostart" and "fooend" │ │ │ │ │ + * event types, which replace the native "click" event type if clicked on │ │ │ │ │ + * an element with the css class "foo": │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * OpenLayers.Events.foostart = OpenLayers.Class({ │ │ │ │ │ + * initialize: function(target) { │ │ │ │ │ + * this.target = target; │ │ │ │ │ + * this.target.register("click", this, this.doStuff, {extension: true}); │ │ │ │ │ + * // only required if extension provides more than one event type │ │ │ │ │ + * this.target.extensions["foostart"] = true; │ │ │ │ │ + * this.target.extensions["fooend"] = true; │ │ │ │ │ + * }, │ │ │ │ │ + * destroy: function() { │ │ │ │ │ + * var target = this.target; │ │ │ │ │ + * target.unregister("click", this, this.doStuff); │ │ │ │ │ + * delete this.target; │ │ │ │ │ + * // only required if extension provides more than one event type │ │ │ │ │ + * delete target.extensions["foostart"]; │ │ │ │ │ + * delete target.extensions["fooend"]; │ │ │ │ │ + * }, │ │ │ │ │ + * doStuff: function(evt) { │ │ │ │ │ + * var propagate = true; │ │ │ │ │ + * if (OpenLayers.Event.element(evt).className === "foo") { │ │ │ │ │ + * propagate = false; │ │ │ │ │ + * var target = this.target; │ │ │ │ │ + * target.triggerEvent("foostart"); │ │ │ │ │ + * window.setTimeout(function() { │ │ │ │ │ + * target.triggerEvent("fooend"); │ │ │ │ │ + * }, 1000); │ │ │ │ │ + * } │ │ │ │ │ + * return propagate; │ │ │ │ │ + * } │ │ │ │ │ + * }); │ │ │ │ │ + * // only required if extension provides more than one event type │ │ │ │ │ + * OpenLayers.Events.fooend = OpenLayers.Events.foostart; │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + extensions: null, │ │ │ │ │ │ │ │ │ │ - // 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]); │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Property: extensionCount │ │ │ │ │ + * {Object} Keys are event types (like in ), values are the │ │ │ │ │ + * number of extension listeners for each event type. │ │ │ │ │ + */ │ │ │ │ │ + extensionCount: null, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - cXMLHttpRequest.prototype.toString = function() { │ │ │ │ │ - return '[' + "object" + ' ' + "XMLHttpRequest" + ']'; │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearMouseListener │ │ │ │ │ + * A version of that is bound to this instance so that │ │ │ │ │ + * it can be used with and │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + clearMouseListener: null, │ │ │ │ │ │ │ │ │ │ - cXMLHttpRequest.toString = function() { │ │ │ │ │ - return '[' + "XMLHttpRequest" + ']'; │ │ │ │ │ - }; │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Events │ │ │ │ │ + * Construct an OpenLayers.Events object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} The js object to which this Events object is being added │ │ │ │ │ + * element - {DOMElement} A dom element to respond to browser events │ │ │ │ │ + * eventTypes - {Array(String)} Deprecated. Array of custom application │ │ │ │ │ + * events. A listener may be registered for any named event, regardless │ │ │ │ │ + * of the values provided here. │ │ │ │ │ + * fallThrough - {Boolean} Allow events to fall through after these have │ │ │ │ │ + * been handled? │ │ │ │ │ + * options - {Object} Options for the events object. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(object, element, eventTypes, fallThrough, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.object = object; │ │ │ │ │ + this.fallThrough = fallThrough; │ │ │ │ │ + this.listeners = {}; │ │ │ │ │ + this.extensions = {}; │ │ │ │ │ + this.extensionCount = {}; │ │ │ │ │ + this._msTouches = []; │ │ │ │ │ │ │ │ │ │ - // Helper function │ │ │ │ │ - function fReadyStateChange(oRequest) { │ │ │ │ │ - // Sniffing code │ │ │ │ │ - if (cXMLHttpRequest.onreadystatechange) │ │ │ │ │ - cXMLHttpRequest.onreadystatechange.apply(oRequest); │ │ │ │ │ + // if a dom element is specified, add a listeners list │ │ │ │ │ + // for browser events on the element and register them │ │ │ │ │ + if (element != null) { │ │ │ │ │ + this.attachToElement(element); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Fake event │ │ │ │ │ - oRequest.dispatchEvent({ │ │ │ │ │ - 'type': "readystatechange", │ │ │ │ │ - 'bubbles': false, │ │ │ │ │ - 'cancelable': false, │ │ │ │ │ - 'timeStamp': new Date + 0 │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var e in this.extensions) { │ │ │ │ │ + if (typeof this.extensions[e] !== "boolean") { │ │ │ │ │ + this.extensions[e].destroy(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.extensions = null; │ │ │ │ │ + if (this.element) { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.element); │ │ │ │ │ + if (this.element.hasScrollEvent) { │ │ │ │ │ + OpenLayers.Event.stopObserving( │ │ │ │ │ + window, "scroll", this.clearMouseListener │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.element = null; │ │ │ │ │ + │ │ │ │ │ + this.listeners = null; │ │ │ │ │ + this.object = null; │ │ │ │ │ + this.fallThrough = null; │ │ │ │ │ + this.eventHandler = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addEventType │ │ │ │ │ + * Deprecated. Any event can be triggered without adding it first. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * eventName - {String} │ │ │ │ │ + */ │ │ │ │ │ + addEventType: function(eventName) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: attachToElement │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {HTMLDOMElement} a DOM element to attach browser events to │ │ │ │ │ + */ │ │ │ │ │ + attachToElement: function(element) { │ │ │ │ │ + if (this.element) { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.element); │ │ │ │ │ + } else { │ │ │ │ │ + // keep a bound copy of handleBrowserEvent() so that we can │ │ │ │ │ + // pass the same function to both Event.observe() and .stopObserving() │ │ │ │ │ + this.eventHandler = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ + this.handleBrowserEvent, this │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + // to be used with observe and stopObserving │ │ │ │ │ + this.clearMouseListener = OpenLayers.Function.bind( │ │ │ │ │ + this.clearMouseCache, this │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + this.element = element; │ │ │ │ │ + var msTouch = !!window.navigator.msMaxTouchPoints; │ │ │ │ │ + var type; │ │ │ │ │ + for (var i = 0, len = this.BROWSER_EVENTS.length; i < len; i++) { │ │ │ │ │ + type = this.BROWSER_EVENTS[i]; │ │ │ │ │ + // register the event cross-browser │ │ │ │ │ + OpenLayers.Event.observe(element, type, this.eventHandler); │ │ │ │ │ + if (msTouch && type.indexOf('touch') === 0) { │ │ │ │ │ + this.addMsTouchListener(element, type, this.eventHandler); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // disable dragstart in IE so that mousedown/move/up works normally │ │ │ │ │ + OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: on │ │ │ │ │ + * Convenience method for registering listeners with a common scope. │ │ │ │ │ + * Internally, this method calls as shown in the examples │ │ │ │ │ + * below. │ │ │ │ │ + * │ │ │ │ │ + * Example use: │ │ │ │ │ + * (code) │ │ │ │ │ + * // register a single listener for the "loadstart" event │ │ │ │ │ + * events.on({"loadstart": loadStartListener}); │ │ │ │ │ + * │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.register("loadstart", undefined, loadStartListener); │ │ │ │ │ + * │ │ │ │ │ + * // register multiple listeners to be called with the same `this` object │ │ │ │ │ + * events.on({ │ │ │ │ │ + * "loadstart": loadStartListener, │ │ │ │ │ + * "loadend": loadEndListener, │ │ │ │ │ + * scope: object │ │ │ │ │ + * }); │ │ │ │ │ + * │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.register("loadstart", object, loadStartListener); │ │ │ │ │ + * events.register("loadend", object, loadEndListener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + on: function(object) { │ │ │ │ │ + for (var type in object) { │ │ │ │ │ + if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ + this.register(type, object.scope, object[type]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: register │ │ │ │ │ + * Register an event on the events object. │ │ │ │ │ + * │ │ │ │ │ + * When the event is triggered, the 'func' function will be called, in the │ │ │ │ │ + * context of 'obj'. Imagine we were to register an event, specifying an │ │ │ │ │ + * OpenLayers.Bounds Object as 'obj'. When the event is triggered, the │ │ │ │ │ + * context in the callback function will be our Bounds object. This means │ │ │ │ │ + * that within our callback function, we can access the properties and │ │ │ │ │ + * methods of the Bounds object through the "this" variable. So our │ │ │ │ │ + * callback could execute something like: │ │ │ │ │ + * : leftStr = "Left: " + this.left; │ │ │ │ │ + * │ │ │ │ │ + * or │ │ │ │ │ + * │ │ │ │ │ + * : centerStr = "Center: " + this.getCenterLonLat(); │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} Name of the event to register │ │ │ │ │ + * obj - {Object} The object to bind the context to for the callback#. │ │ │ │ │ + * If no object is specified, default is the Events's 'object' property. │ │ │ │ │ + * func - {Function} The callback function. If no callback is │ │ │ │ │ + * specified, this function does nothing. │ │ │ │ │ + * priority - {Boolean|Object} If true, adds the new listener to the │ │ │ │ │ + * *front* of the events queue instead of to the end. │ │ │ │ │ + * │ │ │ │ │ + * Valid options for priority: │ │ │ │ │ + * extension - {Boolean} If true, then the event will be registered as │ │ │ │ │ + * extension event. Extension events are handled before all other │ │ │ │ │ + * events. │ │ │ │ │ + */ │ │ │ │ │ + register: function(type, obj, func, priority) { │ │ │ │ │ + if (type in OpenLayers.Events && !this.extensions[type]) { │ │ │ │ │ + this.extensions[type] = new OpenLayers.Events[type](this); │ │ │ │ │ + } │ │ │ │ │ + if (func != null) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = this.object; │ │ │ │ │ + } │ │ │ │ │ + var listeners = this.listeners[type]; │ │ │ │ │ + if (!listeners) { │ │ │ │ │ + listeners = []; │ │ │ │ │ + this.listeners[type] = listeners; │ │ │ │ │ + this.extensionCount[type] = 0; │ │ │ │ │ + } │ │ │ │ │ + var listener = { │ │ │ │ │ + obj: obj, │ │ │ │ │ + func: func │ │ │ │ │ + }; │ │ │ │ │ + if (priority) { │ │ │ │ │ + listeners.splice(this.extensionCount[type], 0, listener); │ │ │ │ │ + if (typeof priority === "object" && priority.extension) { │ │ │ │ │ + this.extensionCount[type]++; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + listeners.push(listener); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: registerPriority │ │ │ │ │ + * Same as register() but adds the new listener to the *front* of the │ │ │ │ │ + * events queue instead of to the end. │ │ │ │ │ + * │ │ │ │ │ + * TODO: get rid of this in 3.0 - Decide whether listeners should be │ │ │ │ │ + * called in the order they were registered or in reverse order. │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} Name of the event to register │ │ │ │ │ + * obj - {Object} The object to bind the context to for the callback#. │ │ │ │ │ + * If no object is specified, default is the Events's │ │ │ │ │ + * 'object' property. │ │ │ │ │ + * func - {Function} The callback function. If no callback is │ │ │ │ │ + * specified, this function does nothing. │ │ │ │ │ + */ │ │ │ │ │ + registerPriority: function(type, obj, func) { │ │ │ │ │ + this.register(type, obj, func, true); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: un │ │ │ │ │ + * Convenience method for unregistering listeners with a common scope. │ │ │ │ │ + * Internally, this method calls as shown in the examples │ │ │ │ │ + * below. │ │ │ │ │ + * │ │ │ │ │ + * Example use: │ │ │ │ │ + * (code) │ │ │ │ │ + * // unregister a single listener for the "loadstart" event │ │ │ │ │ + * events.un({"loadstart": loadStartListener}); │ │ │ │ │ + * │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.unregister("loadstart", undefined, loadStartListener); │ │ │ │ │ + * │ │ │ │ │ + * // unregister multiple listeners with the same `this` object │ │ │ │ │ + * events.un({ │ │ │ │ │ + * "loadstart": loadStartListener, │ │ │ │ │ + * "loadend": loadEndListener, │ │ │ │ │ + * scope: object │ │ │ │ │ + * }); │ │ │ │ │ + * │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.unregister("loadstart", object, loadStartListener); │ │ │ │ │ + * events.unregister("loadend", object, loadEndListener); │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + un: function(object) { │ │ │ │ │ + for (var type in object) { │ │ │ │ │ + if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ + this.unregister(type, object.scope, object[type]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: unregister │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ + * obj - {Object} If none specified, defaults to this.object │ │ │ │ │ + * func - {Function} │ │ │ │ │ + */ │ │ │ │ │ + unregister: function(type, obj, func) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = this.object; │ │ │ │ │ + } │ │ │ │ │ + var listeners = this.listeners[type]; │ │ │ │ │ + if (listeners != null) { │ │ │ │ │ + for (var i = 0, len = listeners.length; i < len; i++) { │ │ │ │ │ + if (listeners[i].obj == obj && listeners[i].func == func) { │ │ │ │ │ + listeners.splice(i, 1); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: remove │ │ │ │ │ + * Remove all listeners for a given event type. If type is not registered, │ │ │ │ │ + * does nothing. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ + */ │ │ │ │ │ + remove: function(type) { │ │ │ │ │ + if (this.listeners[type] != null) { │ │ │ │ │ + this.listeners[type] = []; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: triggerEvent │ │ │ │ │ + * Trigger a specified registered event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ + * evt - {Event || Object} will be passed to the listeners. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The last listener return. If a listener returns false, the │ │ │ │ │ + * chain of listeners will stop getting called. │ │ │ │ │ + */ │ │ │ │ │ + triggerEvent: function(type, evt) { │ │ │ │ │ + var listeners = this.listeners[type]; │ │ │ │ │ + │ │ │ │ │ + // fast path │ │ │ │ │ + if (!listeners || listeners.length == 0) { │ │ │ │ │ + return undefined; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // prep evt object with object & div references │ │ │ │ │ + if (evt == null) { │ │ │ │ │ + evt = {}; │ │ │ │ │ + } │ │ │ │ │ + evt.object = this.object; │ │ │ │ │ + evt.element = this.element; │ │ │ │ │ + if (!evt.type) { │ │ │ │ │ + evt.type = type; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // execute all callbacks registered for specified type │ │ │ │ │ + // get a clone of the listeners array to │ │ │ │ │ + // allow for splicing during callbacks │ │ │ │ │ + listeners = listeners.slice(); │ │ │ │ │ + var continueChain; │ │ │ │ │ + for (var i = 0, len = listeners.length; i < len; i++) { │ │ │ │ │ + var callback = listeners[i]; │ │ │ │ │ + // bind the context to callback.obj │ │ │ │ │ + continueChain = callback.func.apply(callback.obj, [evt]); │ │ │ │ │ + │ │ │ │ │ + if ((continueChain != undefined) && (continueChain == false)) { │ │ │ │ │ + // if callback returns false, execute no more callbacks. │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // don't fall through to other DOM elements │ │ │ │ │ + if (!this.fallThrough) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ + } │ │ │ │ │ + return continueChain; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleBrowserEvent │ │ │ │ │ + * Basically just a wrapper to the triggerEvent() function, but takes │ │ │ │ │ + * care to set a property 'xy' on the event with the current mouse │ │ │ │ │ + * position. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + handleBrowserEvent: function(evt) { │ │ │ │ │ + var type = evt.type, │ │ │ │ │ + listeners = this.listeners[type]; │ │ │ │ │ + if (!listeners || listeners.length == 0) { │ │ │ │ │ + // noone's listening, bail out │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + // add clientX & clientY to all events - corresponds to average x, y │ │ │ │ │ + var touches = evt.touches; │ │ │ │ │ + if (touches && touches[0]) { │ │ │ │ │ + var x = 0; │ │ │ │ │ + var y = 0; │ │ │ │ │ + var num = touches.length; │ │ │ │ │ + var touch; │ │ │ │ │ + for (var i = 0; i < num; ++i) { │ │ │ │ │ + touch = this.getTouchClientXY(touches[i]); │ │ │ │ │ + x += touch.clientX; │ │ │ │ │ + y += touch.clientY; │ │ │ │ │ + } │ │ │ │ │ + evt.clientX = x / num; │ │ │ │ │ + evt.clientY = y / num; │ │ │ │ │ + } │ │ │ │ │ + if (this.includeXY) { │ │ │ │ │ + evt.xy = this.getMousePosition(evt); │ │ │ │ │ + } │ │ │ │ │ + this.triggerEvent(type, evt); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getTouchClientXY │ │ │ │ │ + * WebKit has a few bugs for clientX/clientY. This method detects them │ │ │ │ │ + * and calculate the correct values. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Touch} a Touch object from a TouchEvent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object with only clientX and clientY properties with the │ │ │ │ │ + * calculated values. │ │ │ │ │ + */ │ │ │ │ │ + getTouchClientXY: function(evt) { │ │ │ │ │ + // olMochWin is to override window, used for testing │ │ │ │ │ + var win = window.olMockWin || window, │ │ │ │ │ + winPageX = win.pageXOffset, │ │ │ │ │ + winPageY = win.pageYOffset, │ │ │ │ │ + x = evt.clientX, │ │ │ │ │ + y = evt.clientY; │ │ │ │ │ + │ │ │ │ │ + if (evt.pageY === 0 && Math.floor(y) > Math.floor(evt.pageY) || │ │ │ │ │ + evt.pageX === 0 && Math.floor(x) > Math.floor(evt.pageX)) { │ │ │ │ │ + // iOS4 include scroll offset in clientX/Y │ │ │ │ │ + x = x - winPageX; │ │ │ │ │ + y = y - winPageY; │ │ │ │ │ + } else if (y < (evt.pageY - winPageY) || x < (evt.pageX - winPageX)) { │ │ │ │ │ + // Some Android browsers have totally bogus values for clientX/Y │ │ │ │ │ + // when scrolling/zooming a page │ │ │ │ │ + x = evt.pageX - winPageX; │ │ │ │ │ + y = evt.pageY - winPageY; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + evt.olClientX = x; │ │ │ │ │ + evt.olClientY = y; │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + clientX: x, │ │ │ │ │ + clientY: y │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clearMouseCache │ │ │ │ │ + * Clear cached data about the mouse position. This should be called any │ │ │ │ │ + * time the element that events are registered on changes position │ │ │ │ │ + * within the page. │ │ │ │ │ + */ │ │ │ │ │ + clearMouseCache: function() { │ │ │ │ │ + this.element.scrolls = null; │ │ │ │ │ + this.element.lefttop = null; │ │ │ │ │ + this.element.offsets = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getMousePosition │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The current xy coordinate of the mouse, adjusted │ │ │ │ │ + * for offsets │ │ │ │ │ + */ │ │ │ │ │ + getMousePosition: function(evt) { │ │ │ │ │ + if (!this.includeXY) { │ │ │ │ │ + this.clearMouseCache(); │ │ │ │ │ + } else if (!this.element.hasScrollEvent) { │ │ │ │ │ + OpenLayers.Event.observe(window, "scroll", this.clearMouseListener); │ │ │ │ │ + this.element.hasScrollEvent = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (!this.element.scrolls) { │ │ │ │ │ + var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ + this.element.scrolls = [ │ │ │ │ │ + window.pageXOffset || viewportElement.scrollLeft, │ │ │ │ │ + window.pageYOffset || viewportElement.scrollTop │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (!this.element.lefttop) { │ │ │ │ │ + this.element.lefttop = [ │ │ │ │ │ + (document.documentElement.clientLeft || 0), │ │ │ │ │ + (document.documentElement.clientTop || 0) │ │ │ │ │ + ]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (!this.element.offsets) { │ │ │ │ │ + this.element.offsets = OpenLayers.Util.pagePosition(this.element); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return new OpenLayers.Pixel( │ │ │ │ │ + (evt.clientX + this.element.scrolls[0]) - this.element.offsets[0] - │ │ │ │ │ + this.element.lefttop[0], │ │ │ │ │ + (evt.clientY + this.element.scrolls[1]) - this.element.offsets[1] - │ │ │ │ │ + this.element.lefttop[1] │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addMsTouchListener │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ + */ │ │ │ │ │ + addMsTouchListener: function(element, type, handler) { │ │ │ │ │ + var eventHandler = this.eventHandler; │ │ │ │ │ + var touches = this._msTouches; │ │ │ │ │ + │ │ │ │ │ + function msHandler(evt) { │ │ │ │ │ + handler(OpenLayers.Util.applyDefaults({ │ │ │ │ │ + stopPropagation: function() { │ │ │ │ │ + for (var i = touches.length - 1; i >= 0; --i) { │ │ │ │ │ + touches[i].stopPropagation(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + preventDefault: function() { │ │ │ │ │ + for (var i = touches.length - 1; i >= 0; --i) { │ │ │ │ │ + touches[i].preventDefault(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + type: type │ │ │ │ │ + }, evt)); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + switch (type) { │ │ │ │ │ + case 'touchstart': │ │ │ │ │ + return this.addMsTouchListenerStart(element, type, msHandler); │ │ │ │ │ + case 'touchend': │ │ │ │ │ + return this.addMsTouchListenerEnd(element, type, msHandler); │ │ │ │ │ + case 'touchmove': │ │ │ │ │ + return this.addMsTouchListenerMove(element, type, msHandler); │ │ │ │ │ + default: │ │ │ │ │ + throw 'Unknown touch event type'; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addMsTouchListenerStart │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ + */ │ │ │ │ │ + addMsTouchListenerStart: function(element, type, handler) { │ │ │ │ │ + var touches = this._msTouches; │ │ │ │ │ + │ │ │ │ │ + var cb = function(e) { │ │ │ │ │ + │ │ │ │ │ + var alreadyInArray = false; │ │ │ │ │ + for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ + if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ + alreadyInArray = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!alreadyInArray) { │ │ │ │ │ + touches.push(e); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + e.touches = touches.slice(); │ │ │ │ │ + handler(e); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.observe(element, 'MSPointerDown', cb); │ │ │ │ │ + │ │ │ │ │ + // Need to also listen for end events to keep the _msTouches list │ │ │ │ │ + // accurate │ │ │ │ │ + var internalCb = function(e) { │ │ │ │ │ + for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ + if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ + touches.splice(i, 1); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Event.observe(element, 'MSPointerUp', internalCb); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addMsTouchListenerMove │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ + */ │ │ │ │ │ + addMsTouchListenerMove: function(element, type, handler) { │ │ │ │ │ + var touches = this._msTouches; │ │ │ │ │ + var cb = function(e) { │ │ │ │ │ + │ │ │ │ │ + //Don't fire touch moves when mouse isn't down │ │ │ │ │ + if (e.pointerType == e.MSPOINTER_TYPE_MOUSE && e.buttons == 0) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (touches.length == 1 && touches[0].pageX == e.pageX && │ │ │ │ │ + touches[0].pageY == e.pageY) { │ │ │ │ │ + // don't trigger event when pointer has not moved │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ + if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ + touches[i] = e; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + e.touches = touches.slice(); │ │ │ │ │ + handler(e); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.observe(element, 'MSPointerMove', cb); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addMsTouchListenerEnd │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ + */ │ │ │ │ │ + addMsTouchListenerEnd: function(element, type, handler) { │ │ │ │ │ + var touches = this._msTouches; │ │ │ │ │ + │ │ │ │ │ + var cb = function(e) { │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, ii = touches.length; i < ii; ++i) { │ │ │ │ │ + if (touches[i].pointerId == e.pointerId) { │ │ │ │ │ + touches.splice(i, 1); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + e.touches = touches.slice(); │ │ │ │ │ + handler(e); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.observe(element, 'MSPointerUp', cb); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Events" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // 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 │ │ │ │ │ @@ -24106,1752 +20655,5085 @@ │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.WPSProcess.ChainLink" │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + OpenLayers/Symbolizer.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Format/OWSCommon/v1_1_0.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * Read WPS DescribeProcess responses. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer │ │ │ │ │ + * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ */ │ │ │ │ │ -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", │ │ │ │ │ +OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - */ │ │ │ │ │ - defaultPrefix: "wps", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ - */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zIndex │ │ │ │ │ + * {Number} The zIndex determines the rendering order for a symbolizer. │ │ │ │ │ + * Symbolizers with larger zIndex values are rendered over symbolizers │ │ │ │ │ + * with smaller zIndex values. Default is 0. │ │ │ │ │ + */ │ │ │ │ │ + zIndex: 0, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * A new symbolizer. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Parse a WPS DescribeProcess and return an object with its information. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - if (data && data.nodeType == 9) { │ │ │ │ │ - data = data.documentElement; │ │ │ │ │ - } │ │ │ │ │ - var info = {}; │ │ │ │ │ - this.readNode(data, info); │ │ │ │ │ - return info; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a copy of this symbolizer. │ │ │ │ │ + * │ │ │ │ │ + * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + var Type = eval(this.CLASS_NAME); │ │ │ │ │ + return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.Symbolizer" │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/WPSClient.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/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/WPSProcess.js │ │ │ │ │ - * @requires OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.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. │ │ │ │ │ + * 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.WPSClient = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Projection = 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. │ │ │ │ │ + * Property: proj │ │ │ │ │ + * {Object} Proj4js.Proj instance. │ │ │ │ │ */ │ │ │ │ │ - servers: null, │ │ │ │ │ + proj: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} The default WPS version to use if none is configured. Default │ │ │ │ │ - * is '1.0.0'. │ │ │ │ │ + * Property: projCode │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - version: '1.0.0', │ │ │ │ │ + projCode: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lazy │ │ │ │ │ - * {Boolean} Should the DescribeProcess be deferred until a process is │ │ │ │ │ - * fully configured? Default is false. │ │ │ │ │ + * Property: titleRegEx │ │ │ │ │ + * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ */ │ │ │ │ │ - lazy: false, │ │ │ │ │ + titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} │ │ │ │ │ + * Constructor: OpenLayers.Projection │ │ │ │ │ + * This class offers several methods for interacting with a wrapped │ │ │ │ │ + * pro4js projection object. │ │ │ │ │ * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * describeprocess - Fires when the process description is available. │ │ │ │ │ - * Listeners receive an object with a 'raw' property holding the raw │ │ │ │ │ - * DescribeProcess response, and an 'identifier' property holding the │ │ │ │ │ - * process identifier of the described process. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + initialize: function(projCode, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.projCode = projCode; │ │ │ │ │ + if (typeof Proj4js == "object") { │ │ │ │ │ + this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.WPSClient │ │ │ │ │ + * APIMethod: getCode │ │ │ │ │ + * Get the string SRS code. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Avaliable options: │ │ │ │ │ - * servers - {Object} Mandatory. Service metadata, keyed by a local │ │ │ │ │ - * identifier. Can either be a string with the service url or an │ │ │ │ │ - * object literal with additional metadata: │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The units abbreviation. │ │ │ │ │ + */ │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + return this.proj ? this.proj.units : null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Convert projection to string (getCode wrapper). │ │ │ │ │ * │ │ │ │ │ - * (code) │ │ │ │ │ - * servers: { │ │ │ │ │ - * local: '/geoserver/wps' │ │ │ │ │ - * }, { │ │ │ │ │ - * opengeo: { │ │ │ │ │ - * url: 'http://demo.opengeo.org/geoserver/wps', │ │ │ │ │ - * version: '1.0.0' │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * lazy - {Boolean} Optional. Set to true if DescribeProcess should not be │ │ │ │ │ - * requested until a process is fully configured. Default is false. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The two projections are equivalent. │ │ │ │ │ */ │ │ │ │ │ - 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]; │ │ │ │ │ + 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/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 = {}; │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: execute │ │ │ │ │ - * Shortcut to execute a process with a single function call. This is │ │ │ │ │ - * equivalent to using and then calling execute on the │ │ │ │ │ - * process. │ │ │ │ │ + * 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: │ │ │ │ │ - * options - {Object} Options for the execute operation. │ │ │ │ │ + * prefixedDom - {String} The property to convert │ │ │ │ │ * │ │ │ │ │ - * 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: │ │ │ │ │ + * {String} The CSS property │ │ │ │ │ */ │ │ │ │ │ - execute: function(options) { │ │ │ │ │ - var process = this.getProcess(options.server, options.process); │ │ │ │ │ - process.execute({ │ │ │ │ │ - inputs: options.inputs, │ │ │ │ │ - success: options.success, │ │ │ │ │ - scope: options.scope │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + function domToCss(prefixedDom) { │ │ │ │ │ + if (!prefixedDom) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + return prefixedDom. │ │ │ │ │ + replace(/([A-Z])/g, function(c) { │ │ │ │ │ + return "-" + c.toLowerCase(); │ │ │ │ │ + }). │ │ │ │ │ + replace(/^ms-/, "-ms-"); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getProcess │ │ │ │ │ - * Creates an . │ │ │ │ │ + * APIMethod: css │ │ │ │ │ + * Detect which property is used for a CSS property │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * serverID - {String} Local identifier from the servers that this instance │ │ │ │ │ - * was constructed with. │ │ │ │ │ - * processID - {String} Process identifier known to the server. │ │ │ │ │ + * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ */ │ │ │ │ │ - getProcess: function(serverID, processID) { │ │ │ │ │ - var process = new OpenLayers.WPSProcess({ │ │ │ │ │ - client: this, │ │ │ │ │ - server: serverID, │ │ │ │ │ - identifier: processID │ │ │ │ │ - }); │ │ │ │ │ - if (!this.lazy) { │ │ │ │ │ - process.describe(); │ │ │ │ │ + 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 process; │ │ │ │ │ - }, │ │ │ │ │ + return cssCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: describeProcess │ │ │ │ │ + * APIMethod: js │ │ │ │ │ + * Detect which property is used for a JS property/method │ │ │ │ │ * │ │ │ │ │ * 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 │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - window.setTimeout(function() { │ │ │ │ │ - callback.call(scope, server.processDescription[processID]); │ │ │ │ │ - }, 0); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + return jsCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - this.servers = null; │ │ │ │ │ - }, │ │ │ │ │ + function style(property) { │ │ │ │ │ + return js(divStyle, property); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ + return { │ │ │ │ │ + css: css, │ │ │ │ │ + js: js, │ │ │ │ │ + style: style, │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ + // used for testing │ │ │ │ │ + cssCache: cssCache, │ │ │ │ │ + jsCache: jsCache │ │ │ │ │ + }; │ │ │ │ │ +}()); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/StyleMap.js │ │ │ │ │ + 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/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.StyleMap │ │ │ │ │ + * 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.StyleMap = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Animation = (function(window) { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: styles │ │ │ │ │ - * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ - * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ + * Property: isNative │ │ │ │ │ + * {Boolean} true if a native requestAnimationFrame function is available │ │ │ │ │ */ │ │ │ │ │ - styles: null, │ │ │ │ │ + var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ + var isNative = !!(requestAnimationFrame); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - extendDefault: true, │ │ │ │ │ + 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 = {}; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.StyleMap │ │ │ │ │ - * │ │ │ │ │ + * Function: start │ │ │ │ │ + * Executes a method with in series for some │ │ │ │ │ + * duration. │ │ │ │ │ + * │ │ │ │ │ * 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 │ │ │ │ │ + * 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 │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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]; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ + }; │ │ │ │ │ + requestFrame(loops[id], element); │ │ │ │ │ + return id; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Function: stop │ │ │ │ │ + * Terminates an animation loop started with . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {Number} Identifier returned from . │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var key in this.styles) { │ │ │ │ │ - this.styles[key].destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.styles = null; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createSymbolizer │ │ │ │ │ - * Creates the symbolizer for a feature for a render intent. │ │ │ │ │ + * APIMethod: start │ │ │ │ │ + * Plays the Tween, and calls the callback method on each step │ │ │ │ │ * │ │ │ │ │ * 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 │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - createSymbolizer: function(feature, intent) { │ │ │ │ │ - if (!feature) { │ │ │ │ │ - feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - if (!this.styles[intent]) { │ │ │ │ │ - intent = "default"; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - feature.renderIntent = intent; │ │ │ │ │ - var defaultSymbolizer = {}; │ │ │ │ │ - if (this.extendDefault && intent != "default") { │ │ │ │ │ - defaultSymbolizer = this.styles["default"].createSymbolizer(feature); │ │ │ │ │ + │ │ │ │ │ + if (this.callbacks && this.callbacks.done) { │ │ │ │ │ + this.callbacks.done.call(this, this.finish); │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Util.extend(defaultSymbolizer, │ │ │ │ │ - this.styles[intent].createSymbolizer(feature)); │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + this.playing = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: play │ │ │ │ │ + * Calls the appropriate easing method │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }) │ │ │ │ │ - })); │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ - this.styles[renderIntent].addRules(rules); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ + /** │ │ │ │ │ + * Create empty functions for all easing methods. │ │ │ │ │ + */ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tween" │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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. */ │ │ │ │ │ │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing │ │ │ │ │ + * │ │ │ │ │ + * Credits: │ │ │ │ │ + * Easing Equations by Robert Penner, │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing = { │ │ │ │ │ + /** │ │ │ │ │ + * Create empty functions for all easing methods. │ │ │ │ │ + */ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Map.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ + * 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" │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer │ │ │ │ │ + * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Easing.Expo = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: id │ │ │ │ │ - * {String} │ │ │ │ │ + * Function: easeIn │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeOut │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - name: null, │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + /** │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - div: null, │ │ │ │ │ + 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 = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: opacity │ │ │ │ │ - * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ - * is 1. │ │ │ │ │ + * Function: easeIn │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - opacity: 1, │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * (t /= d) * t + b; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ - * See #987 for more info. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - alwaysInRange: null, │ │ │ │ │ + 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/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: RESOLUTION_PROPERTIES │ │ │ │ │ - * {Array} The properties that are used for calculating resolutions │ │ │ │ │ - * information. │ │ │ │ │ + * Constant: Z_INDEX_BASE │ │ │ │ │ + * {Object} Base z-indexes for different classes of thing │ │ │ │ │ */ │ │ │ │ │ - RESOLUTION_PROPERTIES: [ │ │ │ │ │ - 'scales', 'resolutions', │ │ │ │ │ - 'maxScale', 'minScale', │ │ │ │ │ - 'maxResolution', 'minResolution', │ │ │ │ │ - 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ - ], │ │ │ │ │ + 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) │ │ │ │ │ - * layer.events.register(type, obj, listener); │ │ │ │ │ + * 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 layer.events.object. │ │ │ │ │ - * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ + * 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: │ │ │ │ │ - * 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 │ │ │ │ │ + * 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. │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: map │ │ │ │ │ - * {} This variable is set when the layer is added to │ │ │ │ │ - * the map, via the accessor function setMap(). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ + allOverlays: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ - * individually by all subclasses. Default is 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. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: alpha │ │ │ │ │ - * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ + * Property: dragging │ │ │ │ │ + * {Boolean} The map is currently being dragged. │ │ │ │ │ */ │ │ │ │ │ - alpha: false, │ │ │ │ │ + dragging: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ - * true. │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} Size of the main div (this.div) │ │ │ │ │ */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: visibility │ │ │ │ │ - * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ + * Property: viewPortDiv │ │ │ │ │ + * {HTMLDivElement} The element that represents the map viewport │ │ │ │ │ */ │ │ │ │ │ - visibility: true, │ │ │ │ │ + viewPortDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: attribution │ │ │ │ │ - * {String} Attribution string, displayed when an │ │ │ │ │ - * has been added to the map. │ │ │ │ │ + * Property: layerContainerOrigin │ │ │ │ │ + * {} The lonlat at which the later container was │ │ │ │ │ + * re-initialized (on-zoom) │ │ │ │ │ */ │ │ │ │ │ - attribution: null, │ │ │ │ │ + layerContainerOrigin: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: inRange │ │ │ │ │ - * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ - * range. This is set in whenever the zoom │ │ │ │ │ - * changes. │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerContainerDiv │ │ │ │ │ + * {HTMLDivElement} The element that contains the layers. │ │ │ │ │ */ │ │ │ │ │ - inRange: false, │ │ │ │ │ + layerContainerDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Propery: imageSize │ │ │ │ │ - * {} For layers with a gutter, the image is larger than │ │ │ │ │ - * the tile by twice the gutter in each dimension. │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} Ordered list of layers in the map │ │ │ │ │ */ │ │ │ │ │ - imageSize: null, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ - // OPTIONS │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: controls │ │ │ │ │ + * {Array()} List of controls associated with the map. │ │ │ │ │ + * │ │ │ │ │ + * If not provided in the map options at construction, the map will │ │ │ │ │ + * by default be given the following controls if present in the build: │ │ │ │ │ + * - or │ │ │ │ │ + * - or │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ + controls: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: popups │ │ │ │ │ + * {Array()} List of popups associated with the map │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + popups: 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. │ │ │ │ │ + * APIProperty: baseLayer │ │ │ │ │ + * {} The currently selected base layer. This determines │ │ │ │ │ + * min/max zoom level, projection, etc. │ │ │ │ │ */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ + baseLayer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: gutter │ │ │ │ │ - * {Integer} Determines the width (in pixels) of the gutter around image │ │ │ │ │ - * tiles to ignore. By setting this property to a non-zero value, │ │ │ │ │ - * images will be requested that are wider and taller than the tile │ │ │ │ │ - * size by a value of 2 x gutter. This allows artifacts of rendering │ │ │ │ │ - * at tile edges to be ignored. Set a gutter value that is equal to │ │ │ │ │ - * half the size of the widest symbol that needs to be displayed. │ │ │ │ │ - * Defaults to zero. Non-tiled layers always have zero gutter. │ │ │ │ │ + * Property: center │ │ │ │ │ + * {} The current center of the map │ │ │ │ │ */ │ │ │ │ │ - gutter: 0, │ │ │ │ │ + center: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} The resolution of the map. │ │ │ │ │ + */ │ │ │ │ │ + resolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoom │ │ │ │ │ + * {Integer} The current zoom level of the map │ │ │ │ │ + */ │ │ │ │ │ + zoom: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: panRatio │ │ │ │ │ + * {Float} The ratio of the current extent within │ │ │ │ │ + * which panning will tween. │ │ │ │ │ + */ │ │ │ │ │ + panRatio: 1.5, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: options │ │ │ │ │ + * {Object} The options object passed to the class constructor. Read-only. │ │ │ │ │ + */ │ │ │ │ │ + options: null, │ │ │ │ │ + │ │ │ │ │ + // Options │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tileSize │ │ │ │ │ + * {} Set in the map options to override the default tile │ │ │ │ │ + * size for this map. │ │ │ │ │ + */ │ │ │ │ │ + tileSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: projection │ │ │ │ │ - * {} 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. │ │ │ │ │ - * │ │ │ │ │ + * {String} Set in the map options to specify the default projection │ │ │ │ │ + * for layers added to this map. When using a projection other than EPSG:4326 │ │ │ │ │ + * (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), │ │ │ │ │ + * also set maxExtent, maxResolution or resolutions. Default is "EPSG:4326". │ │ │ │ │ + * Note that the projection of the map is usually determined │ │ │ │ │ + * by that of the current baseLayer (see and ). │ │ │ │ │ */ │ │ │ │ │ - projection: null, │ │ │ │ │ + projection: "EPSG:4326", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * 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. │ │ │ │ │ + * {String} The map units. Possible values are 'degrees' (or 'dd'), 'm', │ │ │ │ │ + * 'ft', 'km', 'mi', 'inches'. Normally taken from the projection. │ │ │ │ │ * Only required if both map and layers do not define a projection, │ │ │ │ │ - * or if they define a projection which does not define units. │ │ │ │ │ + * or if they define a projection which does not define units │ │ │ │ │ */ │ │ │ │ │ units: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: scales │ │ │ │ │ - * {Array} An array of map scales in descending order. The values in the │ │ │ │ │ - * array correspond to the map scale denominator. Note that these │ │ │ │ │ - * values only make sense if the display (monitor) resolution of the │ │ │ │ │ - * client is correctly guessed by whomever is configuring the │ │ │ │ │ - * application. In addition, the units property must also be set. │ │ │ │ │ - * Use instead wherever possible. │ │ │ │ │ + * APIProperty: resolutions │ │ │ │ │ + * {Array(Float)} A list of map resolutions (map units per pixel) in │ │ │ │ │ + * descending order. If this is not set in the layer constructor, it │ │ │ │ │ + * will be set based on other resolution related properties │ │ │ │ │ + * (maxExtent, maxResolution, maxScale, etc.). │ │ │ │ │ */ │ │ │ │ │ - scales: null, │ │ │ │ │ + resolutions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: resolutions │ │ │ │ │ - * {Array} A list of map resolutions (map units per pixel) in descending │ │ │ │ │ - * order. If this is not set in the layer constructor, it will be set │ │ │ │ │ - * based on other resolution related properties (maxExtent, │ │ │ │ │ - * maxResolution, maxScale, etc.). │ │ │ │ │ + * APIProperty: maxResolution │ │ │ │ │ + * {Float} Required if you are not displaying the whole world on a tile │ │ │ │ │ + * with the size specified in . │ │ │ │ │ */ │ │ │ │ │ - resolutions: null, │ │ │ │ │ + maxResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minResolution │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + maxScale: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minScale: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: maxExtent │ │ │ │ │ * {|Array} If provided as an array, the array │ │ │ │ │ * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The maximum extent for the 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. │ │ │ │ │ + * The maximum extent for the map. │ │ │ │ │ + * Default depends on projection; if this is one of those defined in OpenLayers.Projection.defaults │ │ │ │ │ + * (EPSG:4326 or web mercator), maxExtent will be set to the value defined there; │ │ │ │ │ + * else, defaults to null. │ │ │ │ │ + * To restrict user panning and zooming of the map, use instead. │ │ │ │ │ + * The value for will change calculations for tile URLs. │ │ │ │ │ */ │ │ │ │ │ maxExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: minExtent │ │ │ │ │ * {|Array} If provided as an array, the array │ │ │ │ │ * should consist of four values (left, bottom, right, top). │ │ │ │ │ - * The minimum extent for the layer. Defaults to null. │ │ │ │ │ + * The minimum extent for the map. Defaults to null. │ │ │ │ │ */ │ │ │ │ │ minExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxResolution │ │ │ │ │ - * {Float} Default max is 360 deg / 256 px, which corresponds to │ │ │ │ │ - * zoom level 0 on gmaps. Specify a different value in the layer │ │ │ │ │ - * options if you are not using the default │ │ │ │ │ - * and displaying the whole world. │ │ │ │ │ + * APIProperty: restrictedExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * Limit map navigation to this extent where possible. │ │ │ │ │ + * If a non-null restrictedExtent is set, panning will be restricted │ │ │ │ │ + * to the given bounds. In addition, zooming to a resolution that │ │ │ │ │ + * displays more than the restricted extent will center the map │ │ │ │ │ + * on the restricted extent. If you wish to limit the zoom level │ │ │ │ │ + * or resolution, use maxResolution. │ │ │ │ │ */ │ │ │ │ │ - maxResolution: null, │ │ │ │ │ + restrictedExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} Number of zoom levels for the map. Defaults to 16. Set a │ │ │ │ │ + * different value in the map options if needed. │ │ │ │ │ */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ + numZoomLevels: 16, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} │ │ │ │ │ + * APIProperty: theme │ │ │ │ │ + * {String} Relative path to a CSS file from which to load theme styles. │ │ │ │ │ + * Specify null in the map options (e.g. {theme: null}) if you │ │ │ │ │ + * want to get cascading style declarations - by putting links to │ │ │ │ │ + * stylesheets or style declarations directly in your page. │ │ │ │ │ */ │ │ │ │ │ - numZoomLevels: null, │ │ │ │ │ + theme: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayProjection │ │ │ │ │ + * {} Requires proj4js support for projections other │ │ │ │ │ + * than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by │ │ │ │ │ + * several controls to display data to user. If this property is set, │ │ │ │ │ + * it will be set on any control which has a null displayProjection │ │ │ │ │ + * property at the time the control is added to the map. │ │ │ │ │ */ │ │ │ │ │ - minScale: null, │ │ │ │ │ + displayProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ + * APIProperty: tileManager │ │ │ │ │ + * {|Object} By default, and if the build contains │ │ │ │ │ + * TileManager.js, the map will use the TileManager to queue image requests │ │ │ │ │ + * and to cache tile image elements. To create a map without a TileManager │ │ │ │ │ + * configure the map with tileManager: null. To create a TileManager with │ │ │ │ │ + * non-default options, supply the options instead or alternatively supply │ │ │ │ │ + * an instance of {}. │ │ │ │ │ */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayOutsideMaxExtent │ │ │ │ │ - * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ - * extent for this layer. Defaults to false. │ │ │ │ │ + * APIProperty: fallThrough │ │ │ │ │ + * {Boolean} Should OpenLayers allow events on the map to fall through to │ │ │ │ │ + * other elements on the page, or should it swallow them? (#457) │ │ │ │ │ + * Default is to swallow. │ │ │ │ │ */ │ │ │ │ │ - displayOutsideMaxExtent: false, │ │ │ │ │ + fallThrough: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: wrapDateLine │ │ │ │ │ - * {Boolean} Wraps the world at the international dateline, so the map can │ │ │ │ │ - * be panned infinitely in longitudinal direction. Only use this on the │ │ │ │ │ - * base layer, and only if the layer's maxExtent equals the world bounds. │ │ │ │ │ - * #487 for more info. │ │ │ │ │ + * APIProperty: autoUpdateSize │ │ │ │ │ + * {Boolean} Should OpenLayers automatically update the size of the map │ │ │ │ │ + * when the resize event is fired. Default is true. │ │ │ │ │ */ │ │ │ │ │ - wrapDateLine: false, │ │ │ │ │ + autoUpdateSize: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: metadata │ │ │ │ │ - * {Object} This object can be used to store additional information on a │ │ │ │ │ - * layer object. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - metadata: null, │ │ │ │ │ + eventListeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The layer name │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * Property: panTween │ │ │ │ │ + * {} Animated panning tween object, see panTo() │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - │ │ │ │ │ - this.metadata = {}; │ │ │ │ │ + panTween: null, │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: panMethod │ │ │ │ │ + * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ + * OpenLayers.Easing.Expo.easeOut. Setting this to 'null' turns off │ │ │ │ │ + * animated panning. │ │ │ │ │ + */ │ │ │ │ │ + panMethod: OpenLayers.Easing.Expo.easeOut, │ │ │ │ │ │ │ │ │ │ - this.name = name; │ │ │ │ │ + /** │ │ │ │ │ + * Property: panDuration │ │ │ │ │ + * {Integer} The number of steps to be passed to the │ │ │ │ │ + * OpenLayers.Tween.start() method when the map is │ │ │ │ │ + * panned. │ │ │ │ │ + * Default is 50. │ │ │ │ │ + */ │ │ │ │ │ + panDuration: 50, │ │ │ │ │ │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomTween │ │ │ │ │ + * {} Animated zooming tween object, see zoomTo() │ │ │ │ │ + */ │ │ │ │ │ + zoomTween: null, │ │ │ │ │ │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomMethod │ │ │ │ │ + * {Function} The Easing function to be used for tweening. Default is │ │ │ │ │ + * OpenLayers.Easing.Quad.easeOut. Setting this to 'null' turns off │ │ │ │ │ + * animated zooming. │ │ │ │ │ + */ │ │ │ │ │ + zoomMethod: OpenLayers.Easing.Quad.easeOut, │ │ │ │ │ │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ - this.div.style.width = "100%"; │ │ │ │ │ - this.div.style.height = "100%"; │ │ │ │ │ - this.div.dir = "ltr"; │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomDuration │ │ │ │ │ + * {Integer} The number of steps to be passed to the │ │ │ │ │ + * OpenLayers.Tween.start() method when the map is zoomed. │ │ │ │ │ + * Default is 20. │ │ │ │ │ + */ │ │ │ │ │ + zoomDuration: 20, │ │ │ │ │ │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: paddingForPopups │ │ │ │ │ + * {} Outside margin of the popup. Used to prevent │ │ │ │ │ + * the popup from getting too close to the map border. │ │ │ │ │ + */ │ │ │ │ │ + paddingForPopups: null, │ │ │ │ │ │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerContainerOriginPx │ │ │ │ │ + * {Object} Cached object representing the layer container origin (in pixels). │ │ │ │ │ + */ │ │ │ │ │ + layerContainerOriginPx: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: minPx │ │ │ │ │ + * {Object} An object with a 'x' and 'y' values that is the lower │ │ │ │ │ + * left of maxExtent in viewport pixel space. │ │ │ │ │ + * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ + * is valid. It is also used in the getLonLatFromViewPortPx function │ │ │ │ │ + * of Layer. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + minPx: null, │ │ │ │ │ │ │ │ │ │ - if (this.events) { │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - this.events = null; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: maxPx │ │ │ │ │ + * {Object} An object with a 'x' and 'y' values that is the top │ │ │ │ │ + * right of maxExtent in viewport pixel space. │ │ │ │ │ + * Used to verify in moveByPx that the new location we're moving to │ │ │ │ │ + * is valid. │ │ │ │ │ + */ │ │ │ │ │ + maxPx: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ + * Constructor: OpenLayers.Map │ │ │ │ │ + * Constructor for a new OpenLayers.Map instance. There are two possible │ │ │ │ │ + * ways to call the map constructor. See the examples below. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {} The layer to be cloned │ │ │ │ │ + * div - {DOMElement|String} The element or id of an element in your page │ │ │ │ │ + * that will contain the map. May be omitted if the
option is │ │ │ │ │ + * provided or if you intend to call the method later. │ │ │ │ │ + * options - {Object} Optional object with properties to tag onto the map. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ + * Valid options (in addition to the listed API properties): │ │ │ │ │ + * center - {|Array} The default initial center of the map. │ │ │ │ │ + * If provided as array, the first value is the x coordinate, │ │ │ │ │ + * and the 2nd value is the y coordinate. │ │ │ │ │ + * Only specify if is provided. │ │ │ │ │ + * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ + * and the querystring contains coordinates, center will be set │ │ │ │ │ + * by that, and this option will be ignored. │ │ │ │ │ + * zoom - {Number} The initial zoom level for the map. Only specify if │ │ │ │ │ + * is provided. │ │ │ │ │ + * Note that if an ArgParser/Permalink control is present, │ │ │ │ │ + * and the querystring contains a zoom level, zoom will be set │ │ │ │ │ + * by that, and this option will be ignored. │ │ │ │ │ + * extent - {|Array} The initial extent of the map. │ │ │ │ │ + * If provided as an array, the array should consist of │ │ │ │ │ + * four values (left, bottom, right, top). │ │ │ │ │ + * Only specify if
and are not provided. │ │ │ │ │ + * │ │ │ │ │ + * Examples: │ │ │ │ │ + * (code) │ │ │ │ │ + * // create a map with default options in an element with the id "map1" │ │ │ │ │ + * var map = new OpenLayers.Map("map1"); │ │ │ │ │ + * │ │ │ │ │ + * // create a map with non-default options in an element with id "map2" │ │ │ │ │ + * var options = { │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000), │ │ │ │ │ + * center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095) │ │ │ │ │ + * }; │ │ │ │ │ + * var map = new OpenLayers.Map("map2", options); │ │ │ │ │ + * │ │ │ │ │ + * // map with non-default options - same as above but with a single argument, │ │ │ │ │ + * // a restricted extent, and using arrays for bounds and center │ │ │ │ │ + * var map = new OpenLayers.Map({ │ │ │ │ │ + * div: "map_id", │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146], │ │ │ │ │ + * restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962], │ │ │ │ │ + * center: [-12356463.476333, 5621521.4854095] │ │ │ │ │ + * }); │ │ │ │ │ + * │ │ │ │ │ + * // create a map without a reference to a container - call render later │ │ │ │ │ + * var map = new OpenLayers.Map({ │ │ │ │ │ + * projection: "EPSG:3857", │ │ │ │ │ + * maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000) │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + initialize: function(div, options) { │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ + // If only one argument is provided, check if it is an object. │ │ │ │ │ + if (arguments.length === 1 && typeof div === "object") { │ │ │ │ │ + options = div; │ │ │ │ │ + div = options && options.div; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // catch any randomly tagged-on properties │ │ │ │ │ - OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ + // Simple-type defaults are set in class definition. │ │ │ │ │ + // Now set complex-type defaults │ │ │ │ │ + this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH, │ │ │ │ │ + OpenLayers.Map.TILE_HEIGHT); │ │ │ │ │ │ │ │ │ │ - // a cloned layer should never have its map property set │ │ │ │ │ - // because it has not been added to a map yet. │ │ │ │ │ - obj.map = null; │ │ │ │ │ + this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15); │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + this.theme = OpenLayers._getScriptLocation() + │ │ │ │ │ + 'theme/default/style.css'; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getOptions │ │ │ │ │ - * Extracts an object from the layer with the properties that were set as │ │ │ │ │ - * options, but updates them with the values currently set on the │ │ │ │ │ - * instance. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} the of the layer, representing the current state. │ │ │ │ │ - */ │ │ │ │ │ - getOptions: function() { │ │ │ │ │ - var options = {}; │ │ │ │ │ - for (var o in this.options) { │ │ │ │ │ - options[o] = this[o]; │ │ │ │ │ - } │ │ │ │ │ - return options; │ │ │ │ │ - }, │ │ │ │ │ + // backup original options │ │ │ │ │ + this.options = OpenLayers.Util.extend({}, options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setName │ │ │ │ │ - * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ - * on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newName - {String} The new name. │ │ │ │ │ - */ │ │ │ │ │ - setName: function(newName) { │ │ │ │ │ - if (newName != this.name) { │ │ │ │ │ - this.name = newName; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "name" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + // now override default options │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + │ │ │ │ │ + var projCode = this.projection instanceof OpenLayers.Projection ? │ │ │ │ │ + this.projection.projCode : this.projection; │ │ │ │ │ + OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]); │ │ │ │ │ + │ │ │ │ │ + // allow extents and center to be arrays │ │ │ │ │ + if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.maxExtent = new OpenLayers.Bounds(this.maxExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.minExtent && !(this.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.minExtent = new OpenLayers.Bounds(this.minExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.restrictedExtent && !(this.restrictedExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + this.restrictedExtent = new OpenLayers.Bounds(this.restrictedExtent); │ │ │ │ │ + } │ │ │ │ │ + if (this.center && !(this.center instanceof OpenLayers.LonLat)) { │ │ │ │ │ + this.center = new OpenLayers.LonLat(this.center); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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) { │ │ │ │ │ + // initialize layers array │ │ │ │ │ + this.layers = []; │ │ │ │ │ │ │ │ │ │ - if (this.options == null) { │ │ │ │ │ - this.options = {}; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID("OpenLayers.Map_"); │ │ │ │ │ + │ │ │ │ │ + this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ + if (!this.div) { │ │ │ │ │ + this.div = document.createElement("div"); │ │ │ │ │ + this.div.style.height = "1px"; │ │ │ │ │ + this.div.style.width = "1px"; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ + │ │ │ │ │ + // the viewPortDiv is the outermost div we modify │ │ │ │ │ + var id = this.id + "_OpenLayers_ViewPort"; │ │ │ │ │ + this.viewPortDiv = OpenLayers.Util.createDiv(id, null, null, null, │ │ │ │ │ + "relative", null, │ │ │ │ │ + "hidden"); │ │ │ │ │ + this.viewPortDiv.style.width = "100%"; │ │ │ │ │ + this.viewPortDiv.style.height = "100%"; │ │ │ │ │ + this.viewPortDiv.className = "olMapViewport"; │ │ │ │ │ + this.div.appendChild(this.viewPortDiv); │ │ │ │ │ + │ │ │ │ │ + this.events = new OpenLayers.Events( │ │ │ │ │ + this, this.viewPortDiv, null, this.fallThrough, { │ │ │ │ │ + includeXY: true │ │ │ │ │ } │ │ │ │ │ - if (newOptions.minExtent && !(newOptions.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ - newOptions.minExtent = new OpenLayers.Bounds(newOptions.minExtent); │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + if (OpenLayers.TileManager && this.tileManager !== null) { │ │ │ │ │ + if (!(this.tileManager instanceof OpenLayers.TileManager)) { │ │ │ │ │ + this.tileManager = new OpenLayers.TileManager(this.tileManager); │ │ │ │ │ } │ │ │ │ │ + this.tileManager.addMap(this); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // update our copy for clone │ │ │ │ │ - OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ + // the layerContainerDiv is the one that holds all the layers │ │ │ │ │ + id = this.id + "_OpenLayers_Container"; │ │ │ │ │ + this.layerContainerDiv = OpenLayers.Util.createDiv(id); │ │ │ │ │ + this.layerContainerDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] - 1; │ │ │ │ │ + this.layerContainerOriginPx = { │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }; │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ │ │ │ │ │ - // add new options to this │ │ │ │ │ - OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ + this.viewPortDiv.appendChild(this.layerContainerDiv); │ │ │ │ │ │ │ │ │ │ - // 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(); │ │ │ │ │ + this.updateSize(); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // 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) { │ │ │ │ │ + if (this.autoUpdateSize === true) { │ │ │ │ │ + // updateSize on catching the window's resize │ │ │ │ │ + // Note that this is ok, as updateSize() does nothing if the │ │ │ │ │ + // map's size has not actually changed. │ │ │ │ │ + this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize, │ │ │ │ │ + this); │ │ │ │ │ + OpenLayers.Event.observe(window, 'resize', │ │ │ │ │ + this.updateSizeDestroy); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + // only append link stylesheet if the theme property is set │ │ │ │ │ + if (this.theme) { │ │ │ │ │ + // check existing links for equivalent url │ │ │ │ │ + var addNode = true; │ │ │ │ │ + var nodes = document.getElementsByTagName('link'); │ │ │ │ │ + for (var i = 0, len = nodes.length; i < len; ++i) { │ │ │ │ │ + if (OpenLayers.Util.isEquivalentUrl(nodes.item(i).href, │ │ │ │ │ + this.theme)) { │ │ │ │ │ + addNode = false; │ │ │ │ │ break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + // only add a new node if one with an equivalent url hasn't already │ │ │ │ │ + // been added │ │ │ │ │ + if (addNode) { │ │ │ │ │ + var cssNode = document.createElement('link'); │ │ │ │ │ + cssNode.setAttribute('rel', 'stylesheet'); │ │ │ │ │ + cssNode.setAttribute('type', 'text/css'); │ │ │ │ │ + cssNode.setAttribute('href', this.theme); │ │ │ │ │ + document.getElementsByTagName('head')[0].appendChild(cssNode); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: onMapResize │ │ │ │ │ - * This function can be implemented by subclasses │ │ │ │ │ - */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - //this function can be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ + if (this.controls == null) { // default controls │ │ │ │ │ + this.controls = []; │ │ │ │ │ + if (OpenLayers.Control != null) { // running full or lite? │ │ │ │ │ + // Navigation or TouchNavigation depending on what is in build │ │ │ │ │ + if (OpenLayers.Control.Navigation) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Navigation()); │ │ │ │ │ + } else if (OpenLayers.Control.TouchNavigation) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.TouchNavigation()); │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.Zoom) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Zoom()); │ │ │ │ │ + } else if (OpenLayers.Control.PanZoom) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.PanZoom()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ - */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - var redrawn = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ + if (OpenLayers.Control.ArgParser) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.ArgParser()); │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.Attribution) { │ │ │ │ │ + this.controls.push(new OpenLayers.Control.Attribution()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // min/max Range may have changed │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + this.addControlToMap(this.controls[i]); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // map's center might not yet be set │ │ │ │ │ - var extent = this.getExtent(); │ │ │ │ │ + this.popups = []; │ │ │ │ │ │ │ │ │ │ - if (extent && this.inRange && this.visibility) { │ │ │ │ │ - var zoomChanged = true; │ │ │ │ │ - this.moveTo(extent, zoomChanged, false); │ │ │ │ │ - this.events.triggerEvent("moveend", { │ │ │ │ │ - "zoomChanged": zoomChanged │ │ │ │ │ - }); │ │ │ │ │ - redrawn = true; │ │ │ │ │ + this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + // always call map.destroy() │ │ │ │ │ + OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); │ │ │ │ │ + │ │ │ │ │ + // add any initial layers │ │ │ │ │ + if (options && options.layers) { │ │ │ │ │ + /** │ │ │ │ │ + * If you have set options.center, the map center property will be │ │ │ │ │ + * set at this point. However, since setCenter has not been called, │ │ │ │ │ + * addLayers gets confused. So we delete the map center in this │ │ │ │ │ + * case. Because the check below uses options.center, it will │ │ │ │ │ + * be properly set below. │ │ │ │ │ + */ │ │ │ │ │ + delete this.center; │ │ │ │ │ + delete this.zoom; │ │ │ │ │ + this.addLayers(options.layers); │ │ │ │ │ + // set center (and optionally zoom) │ │ │ │ │ + if (options.center && !this.getCenter()) { │ │ │ │ │ + // zoom can be undefined here │ │ │ │ │ + this.setCenter(options.center, options.zoom); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return redrawn; │ │ │ │ │ + │ │ │ │ │ + if (this.panMethod) { │ │ │ │ │ + this.panTween = new OpenLayers.Tween(this.panMethod); │ │ │ │ │ + } │ │ │ │ │ + if (this.zoomMethod && this.applyTransform.transform) { │ │ │ │ │ + this.zoomTween = new OpenLayers.Tween(this.zoomMethod); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getViewport │ │ │ │ │ + * Get the DOMElement representing the view port. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + getViewport: function() { │ │ │ │ │ + return this.viewPortDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ + * APIMethod: render │ │ │ │ │ + * Render the map to a specified container. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ - * do some init work in that case. │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * div - {String|DOMElement} The container that the map should be rendered │ │ │ │ │ + * to. If different than the current container, the map viewport │ │ │ │ │ + * will be moved from the current to the new container. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - var display = this.visibility; │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - display = display && this.inRange; │ │ │ │ │ - } │ │ │ │ │ - this.display(display); │ │ │ │ │ + render: function(div) { │ │ │ │ │ + this.div = OpenLayers.Util.getElement(div); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, 'olMap'); │ │ │ │ │ + this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ + this.div.appendChild(this.viewPortDiv); │ │ │ │ │ + this.updateSize(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: unloadDestroy │ │ │ │ │ + * Function that is called to destroy the map on page unload. stored here │ │ │ │ │ + * so that if map is manually destroyed, we can unregister this. │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) {}, │ │ │ │ │ + unloadDestroy: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 - {} │ │ │ │ │ + * Method: updateSizeDestroy │ │ │ │ │ + * When the map is destroyed, we need to stop listening to updateSize │ │ │ │ │ + * events: this method stores the function we need to unregister in │ │ │ │ │ + * non-IE browsers. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - if (this.map == null) { │ │ │ │ │ + updateSizeDestroy: null, │ │ │ │ │ │ │ │ │ │ - this.map = map; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this map. │ │ │ │ │ + * Note that if you are using an application which removes a container │ │ │ │ │ + * of the map from the DOM, you need to ensure that you destroy the │ │ │ │ │ + * map *before* this happens; otherwise, the page unload handler │ │ │ │ │ + * will fail because the DOM elements that map.destroy() wants │ │ │ │ │ + * to clean up will be gone. (See │ │ │ │ │ + * http://trac.osgeo.org/openlayers/ticket/2277 for more information). │ │ │ │ │ + * This will apply to GeoExt and also to other applications which │ │ │ │ │ + * modify the DOM of the container of the OpenLayers Map. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // if unloadDestroy is null, we've already been destroyed │ │ │ │ │ + if (!this.unloadDestroy) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ + // make sure panning doesn't continue after destruction │ │ │ │ │ + if (this.panTween) { │ │ │ │ │ + this.panTween.stop(); │ │ │ │ │ + this.panTween = null; │ │ │ │ │ + } │ │ │ │ │ + // make sure zooming doesn't continue after destruction │ │ │ │ │ + if (this.zoomTween) { │ │ │ │ │ + this.zoomTween.stop(); │ │ │ │ │ + this.zoomTween = null; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.projection = this.projection || this.map.projection; │ │ │ │ │ - if (typeof this.projection == "string") { │ │ │ │ │ - this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ - } │ │ │ │ │ + // map has been destroyed. dont do it again! │ │ │ │ │ + OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); │ │ │ │ │ + this.unloadDestroy = null; │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ + if (this.updateSizeDestroy) { │ │ │ │ │ + OpenLayers.Event.stopObserving(window, 'resize', │ │ │ │ │ + this.updateSizeDestroy); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.initResolutions(); │ │ │ │ │ + this.paddingForPopups = null; │ │ │ │ │ │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ - this.div.style.display = show ? "" : "none"; │ │ │ │ │ + if (this.controls != null) { │ │ │ │ │ + for (var i = this.controls.length - 1; i >= 0; --i) { │ │ │ │ │ + this.controls[i].destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.controls = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.layers != null) { │ │ │ │ │ + for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ + //pass 'false' to destroy so that map wont try to set a new │ │ │ │ │ + // baselayer after each baselayer is removed │ │ │ │ │ + this.layers[i].destroy(false); │ │ │ │ │ } │ │ │ │ │ + this.layers = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.viewPortDiv && this.viewPortDiv.parentNode) { │ │ │ │ │ + this.viewPortDiv.parentNode.removeChild(this.viewPortDiv); │ │ │ │ │ + } │ │ │ │ │ + this.viewPortDiv = null; │ │ │ │ │ │ │ │ │ │ - // deal with gutters │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ + if (this.tileManager) { │ │ │ │ │ + this.tileManager.removeMap(this); │ │ │ │ │ + this.tileManager = null; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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() {}, │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + │ │ │ │ │ + this.options = 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. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setOptions │ │ │ │ │ + * Change the map options │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * options - {Object} Hashtable of options to tag to the map │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - //to be overridden by subclasses │ │ │ │ │ + setOptions: function(options) { │ │ │ │ │ + var updatePxExtent = this.minPx && │ │ │ │ │ + options.restrictedExtent != this.restrictedExtent; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + // force recalculation of minPx and maxPx │ │ │ │ │ + updatePxExtent && this.moveTo(this.getCachedCenter(), this.zoom, { │ │ │ │ │ + forceZoomChange: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getImageSize │ │ │ │ │ + * APIMethod: getTileSize │ │ │ │ │ + * Get the tile size for the map │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} optional tile bounds, can be used │ │ │ │ │ - * by subclasses that have to deal with different tile sizes at the │ │ │ │ │ - * layer extent edges (e.g. Zoomify) │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The size that the image should be, taking into │ │ │ │ │ - * account gutters. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getImageSize: function(bounds) { │ │ │ │ │ - return (this.imageSize || this.tileSize); │ │ │ │ │ + getTileSize: function() { │ │ │ │ │ + return this.tileSize; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ - * or use by Tile.Image. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getBy │ │ │ │ │ + * Get a list of objects given a property and a match item. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + * array - {String} A property on the map whose value is an array. │ │ │ │ │ + * property - {String} A property on each item of the given array. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(map[array][i][property]) evaluates to true, the item will │ │ │ │ │ + * be included in the array returned. If no items are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} An array of items where the given property matches the given │ │ │ │ │ + * criteria. │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + getBy: function(array, property, match) { │ │ │ │ │ + var test = (typeof match.test == "function"); │ │ │ │ │ + var found = OpenLayers.Array.filter(this[array], function(item) { │ │ │ │ │ + return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ + }); │ │ │ │ │ + return found; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getVisibility │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getLayersBy │ │ │ │ │ + * Get a list of layers with properties matching the given criteria. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} A layer property to be matched. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ + * included in the array returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ + * {Array()} A list of layers matching the given criteria. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - getVisibility: function() { │ │ │ │ │ - return this.visibility; │ │ │ │ │ + getLayersBy: function(property, match) { │ │ │ │ │ + return this.getBy("layers", property, match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayersByName │ │ │ │ │ + * Get a list of layers with names matching the given name. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * visibility - {Boolean} Whether or not to display the layer (if in range) │ │ │ │ │ + * match - {String | Object} A layer name. The name can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * name.test(layer.name) evaluates to true, the layer will be included │ │ │ │ │ + * in the list of layers returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of layers matching the given name. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - 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"); │ │ │ │ │ - } │ │ │ │ │ + getLayersByName: function(match) { │ │ │ │ │ + return this.getLayersBy("name", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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.. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayersByClass │ │ │ │ │ + * Get a list of layers of a given class (CLASS_NAME). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * match - {String | Object} A layer class name. The match can also be a │ │ │ │ │ + * regular expression literal or object. In addition, it can be any │ │ │ │ │ + * object with a method named test. For reqular expressions or other, │ │ │ │ │ + * if type.test(layer.CLASS_NAME) evaluates to true, the layer will │ │ │ │ │ + * be included in the list of layers returned. If no layers are │ │ │ │ │ + * found, an empty array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of layers matching the given class. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - if (display != (this.div.style.display != "none")) { │ │ │ │ │ - this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ - } │ │ │ │ │ + getLayersByClass: function(match) { │ │ │ │ │ + return this.getLayersBy("CLASS_NAME", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: calculateInRange │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getControlsBy │ │ │ │ │ + * Get a list of controls with properties matching the given criteria. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} A control property to be matched. │ │ │ │ │ + * match - {String | Object} A string to match. Can also be a regular │ │ │ │ │ + * expression literal or object. In addition, it can be any object │ │ │ │ │ + * with a method named test. For reqular expressions or other, if │ │ │ │ │ + * match.test(layer[property]) evaluates to true, the layer will be │ │ │ │ │ + * included in the array returned. If no layers are found, an empty │ │ │ │ │ + * array is returned. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {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. │ │ │ │ │ + * {Array()} A list of controls matching the given │ │ │ │ │ + * criteria. An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getControlsBy: function(property, match) { │ │ │ │ │ + return this.getBy("controls", property, match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setIsBaseLayer │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getControlsByClass │ │ │ │ │ + * Get a list of controls of a given class (CLASS_NAME). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * isBaseLayer - {Boolean} │ │ │ │ │ + * match - {String | Object} A control class name. The match can also be a │ │ │ │ │ + * regular expression literal or object. In addition, it can be any │ │ │ │ │ + * object with a method named test. For reqular expressions or other, │ │ │ │ │ + * if type.test(control.CLASS_NAME) evaluates to true, the control will │ │ │ │ │ + * be included in the list of controls returned. If no controls are │ │ │ │ │ + * found, an empty array is returned. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} A list of controls matching the given class. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ */ │ │ │ │ │ - setIsBaseLayer: function(isBaseLayer) { │ │ │ │ │ - if (isBaseLayer != this.isBaseLayer) { │ │ │ │ │ - this.isBaseLayer = isBaseLayer; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ - layer: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getControlsByClass: function(match) { │ │ │ │ │ + return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /********************************************************/ │ │ │ │ │ /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ + /* Layer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Layers to and from the Map */ │ │ │ │ │ /* */ │ │ │ │ │ /********************************************************/ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayer │ │ │ │ │ + * Get a layer based on its id │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {String} A layer id │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The Layer with the corresponding id from the map's │ │ │ │ │ + * layer collection, or null if not found. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getLayer: function(id) { │ │ │ │ │ + var foundLayer = null; │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer.id == id) { │ │ │ │ │ + foundLayer = layer; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (this.options.alwaysInRange == null) { │ │ │ │ │ - this.alwaysInRange = alwaysInRange; │ │ │ │ │ - } │ │ │ │ │ + return foundLayer; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // if we don't have resolutions then attempt to derive them from scales │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: setLayerZIndex │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * zIdx - {int} │ │ │ │ │ + */ │ │ │ │ │ + setLayerZIndex: function(layer, zIdx) { │ │ │ │ │ + layer.setZIndex( │ │ │ │ │ + this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] + │ │ │ │ │ + zIdx * 5); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + /** │ │ │ │ │ + * Method: resetLayersZIndex │ │ │ │ │ + * Reset each layer's z-index based on layer's array index │ │ │ │ │ + */ │ │ │ │ │ + resetLayersZIndex: function() { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + this.setLayerZIndex(layer, i); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addLayer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the layer has been added to the map. │ │ │ │ │ + */ │ │ │ │ │ + addLayer: function(layer) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + if (this.layers[i] == layer) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // 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.events.triggerEvent("preaddlayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }) === false) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - if (this.options.maxScale) { │ │ │ │ │ - minResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ - this.options.maxScale, this.units); │ │ │ │ │ + if (this.allOverlays) { │ │ │ │ │ + layer.isBaseLayer = false; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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]; │ │ │ │ │ - } │ │ │ │ │ + layer.div.className = "olLayerDiv"; │ │ │ │ │ + layer.div.style.overflow = ""; │ │ │ │ │ + this.setLayerZIndex(layer, this.layers.length); │ │ │ │ │ │ │ │ │ │ - // 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]; │ │ │ │ │ - } │ │ │ │ │ + if (layer.isFixed) { │ │ │ │ │ + this.viewPortDiv.appendChild(layer.div); │ │ │ │ │ + } else { │ │ │ │ │ + this.layerContainerDiv.appendChild(layer.div); │ │ │ │ │ } │ │ │ │ │ + this.layers.push(layer); │ │ │ │ │ + layer.setMap(this); │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ + if (layer.isBaseLayer || (this.allOverlays && !this.baseLayer)) { │ │ │ │ │ + if (this.baseLayer == null) { │ │ │ │ │ + // set the first baselaye we add as the baselayer │ │ │ │ │ + this.setBaseLayer(layer); │ │ │ │ │ + } else { │ │ │ │ │ + layer.setVisibility(false); │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ + } else { │ │ │ │ │ + layer.redraw(); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("addlayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.events.triggerEvent("added", { │ │ │ │ │ + map: this, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.afterAdd(); │ │ │ │ │ + │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resolutionsFromScales │ │ │ │ │ - * Derive resolutions from scales. │ │ │ │ │ + * APIMethod: addLayers │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * scales - {Array(Number)} Scales │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {Array(Number)} Resolutions │ │ │ │ │ + * layers - {Array()} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + addLayers: function(layers) { │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + this.addLayer(layers[i]); │ │ │ │ │ } │ │ │ │ │ - return resolutions; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateResolutions │ │ │ │ │ - * Calculate resolutions based on the provided properties. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removeLayer │ │ │ │ │ + * Removes a layer from the map by removing its visual element (the │ │ │ │ │ + * layer.div property), then removing it from the map's internal list │ │ │ │ │ + * of layers, setting the layer's map property to null. │ │ │ │ │ + * │ │ │ │ │ + * a "removelayer" event is triggered. │ │ │ │ │ + * │ │ │ │ │ + * very worthy of mention is that simply removing a layer from a map │ │ │ │ │ + * will not cause the removal of any popups which may have been created │ │ │ │ │ + * by the layer. this is due to the fact that it was decided at some │ │ │ │ │ + * point that popups would not belong to layers. thus there is no way │ │ │ │ │ + * for us to know here to which layer the popup belongs. │ │ │ │ │ + * │ │ │ │ │ + * A simple solution to this is simply to call destroy() on the layer. │ │ │ │ │ + * the default OpenLayers.Layer class's destroy() function │ │ │ │ │ + * automatically takes care to remove itself from whatever map it has │ │ │ │ │ + * been attached to. │ │ │ │ │ + * │ │ │ │ │ + * The correct solution is for the layer itself to register an │ │ │ │ │ + * event-handler on "removelayer" and when it is called, if it │ │ │ │ │ + * recognizes itself as the layer being removed, then it cycles through │ │ │ │ │ + * its own personal list of popups, removing them from the map. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * props - {Object} Properties │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array({Number})} Array of resolutions. │ │ │ │ │ + * layer - {} │ │ │ │ │ + * setNewBaseLayer - {Boolean} Default is true │ │ │ │ │ */ │ │ │ │ │ - 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")) { │ │ │ │ │ + removeLayer: function(layer, setNewBaseLayer) { │ │ │ │ │ + if (this.events.triggerEvent("preremovelayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }) === false) { │ │ │ │ │ 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)) │ │ │ │ │ - ); │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - var i; │ │ │ │ │ - if (typeof maxResolution === "number") { │ │ │ │ │ - for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ - resolutions[i] = maxResolution / Math.pow(base, i); │ │ │ │ │ - } │ │ │ │ │ + if (layer.isFixed) { │ │ │ │ │ + this.viewPortDiv.removeChild(layer.div); │ │ │ │ │ } else { │ │ │ │ │ - for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ - resolutions[numZoomLevels - 1 - i] = │ │ │ │ │ - minResolution * Math.pow(base, i); │ │ │ │ │ + this.layerContainerDiv.removeChild(layer.div); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.removeItem(this.layers, layer); │ │ │ │ │ + layer.removeMap(this); │ │ │ │ │ + layer.map = null; │ │ │ │ │ + │ │ │ │ │ + // if we removed the base layer, need to set a new one │ │ │ │ │ + if (this.baseLayer == layer) { │ │ │ │ │ + this.baseLayer = null; │ │ │ │ │ + if (setNewBaseLayer) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var iLayer = this.layers[i]; │ │ │ │ │ + if (iLayer.isBaseLayer || this.allOverlays) { │ │ │ │ │ + this.setBaseLayer(iLayer); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - return resolutions; │ │ │ │ │ + this.resetLayersZIndex(); │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("removelayer", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + layer.events.triggerEvent("removed", { │ │ │ │ │ + map: this, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ + * APIMethod: getNumLayers │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ - * resolutions array, indexed by current zoom level. │ │ │ │ │ + * {Int} The number of layers attached to the map. │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var zoom = this.map.getZoom(); │ │ │ │ │ - return this.getResolutionForZoom(zoom); │ │ │ │ │ + getNumLayers: function() { │ │ │ │ │ + return this.layers.length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ - */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ - // means it will user map's current center & resolution │ │ │ │ │ - // │ │ │ │ │ - return this.map.calculateBounds(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForExtent │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getLayerIndex │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * layer - {} │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * {Integer} The current (zero-based) index of the given layer in the map's │ │ │ │ │ + * layer stack. Returns -1 if the layer isn't on the map. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + getLayerIndex: function(layer) { │ │ │ │ │ + return OpenLayers.Util.indexOf(this.layers, layer); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ - * This function is to be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getDataExtent: function() { │ │ │ │ │ - //to be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setLayerIndex │ │ │ │ │ + * Move the given layer to the specified (zero-based) index in the layer │ │ │ │ │ + * list, changing its z-index in the map display. Use │ │ │ │ │ + * map.getLayerIndex() to find out the current index of a layer. Note │ │ │ │ │ + * that this cannot (or at least should not) be effectively used to │ │ │ │ │ + * raise base layers above overlays. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ + * layer - {} │ │ │ │ │ + * idx - {int} │ │ │ │ │ + */ │ │ │ │ │ + setLayerIndex: function(layer, idx) { │ │ │ │ │ + var base = this.getLayerIndex(layer); │ │ │ │ │ + if (idx < 0) { │ │ │ │ │ + idx = 0; │ │ │ │ │ + } else if (idx > this.layers.length) { │ │ │ │ │ + idx = this.layers.length; │ │ │ │ │ + } │ │ │ │ │ + if (base != idx) { │ │ │ │ │ + this.layers.splice(base, 1); │ │ │ │ │ + this.layers.splice(idx, 0, layer); │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + this.setLayerZIndex(this.layers[i], i); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: layer, │ │ │ │ │ + property: "order" │ │ │ │ │ + }); │ │ │ │ │ + if (this.allOverlays) { │ │ │ │ │ + if (idx === 0) { │ │ │ │ │ + this.setBaseLayer(layer); │ │ │ │ │ + } else if (this.baseLayer !== this.layers[0]) { │ │ │ │ │ + this.setBaseLayer(this.layers[0]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: raiseLayer │ │ │ │ │ + * Change the index of the given layer by delta. If delta is positive, │ │ │ │ │ + * the layer is moved up the map's layer stack; if delta is negative, │ │ │ │ │ + * the layer is moved down. Again, note that this cannot (or at least │ │ │ │ │ + * should not) be effectively used to raise base layers above overlays. │ │ │ │ │ + * │ │ │ │ │ + * Paremeters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * delta - {int} │ │ │ │ │ + */ │ │ │ │ │ + raiseLayer: function(layer, delta) { │ │ │ │ │ + var idx = this.getLayerIndex(layer) + delta; │ │ │ │ │ + this.setLayerIndex(layer, idx); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setBaseLayer │ │ │ │ │ + * Allows user to specify one of the currently-loaded layers as the Map's │ │ │ │ │ + * new base layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newBaseLayer - {} │ │ │ │ │ + */ │ │ │ │ │ + setBaseLayer: function(newBaseLayer) { │ │ │ │ │ + │ │ │ │ │ + if (newBaseLayer != this.baseLayer) { │ │ │ │ │ + │ │ │ │ │ + // ensure newBaseLayer is already loaded │ │ │ │ │ + if (OpenLayers.Util.indexOf(this.layers, newBaseLayer) != -1) { │ │ │ │ │ + │ │ │ │ │ + // preserve center and scale when changing base layers │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ + var newResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.getScale(), newBaseLayer.units │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + // make the old base layer invisible │ │ │ │ │ + if (this.baseLayer != null && !this.allOverlays) { │ │ │ │ │ + this.baseLayer.setVisibility(false); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // set new baselayer │ │ │ │ │ + this.baseLayer = newBaseLayer; │ │ │ │ │ + │ │ │ │ │ + if (!this.allOverlays || this.baseLayer.visibility) { │ │ │ │ │ + this.baseLayer.setVisibility(true); │ │ │ │ │ + // Layer may previously have been visible but not in range. │ │ │ │ │ + // In this case we need to redraw it to make it visible. │ │ │ │ │ + if (this.baseLayer.inRange === false) { │ │ │ │ │ + this.baseLayer.redraw(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // recenter the map │ │ │ │ │ + if (center != null) { │ │ │ │ │ + // new zoom level derived from old scale │ │ │ │ │ + var newZoom = this.getZoomForResolution( │ │ │ │ │ + newResolution || this.resolution, true │ │ │ │ │ + ); │ │ │ │ │ + // zoom and force zoom change │ │ │ │ │ + this.setCenter(center, newZoom, false, true); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this.baseLayer │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Control Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Controls to and from the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addControl │ │ │ │ │ + * Add the passed over control to the map. Optionally │ │ │ │ │ + * position the control at the given pixel. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} │ │ │ │ │ + * px - {} │ │ │ │ │ + */ │ │ │ │ │ + addControl: function(control, px) { │ │ │ │ │ + this.controls.push(control); │ │ │ │ │ + this.addControlToMap(control, px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addControls │ │ │ │ │ + * Add all of the passed over controls to the map. │ │ │ │ │ + * You can pass over an optional second array │ │ │ │ │ + * with pixel-objects to position the controls. │ │ │ │ │ + * The indices of the two arrays should match and │ │ │ │ │ + * you can add null as pixel for those controls │ │ │ │ │ + * you want to be autopositioned. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * controls - {Array()} │ │ │ │ │ + * pixels - {Array()} │ │ │ │ │ + */ │ │ │ │ │ + addControls: function(controls, pixels) { │ │ │ │ │ + var pxs = (arguments.length === 1) ? [] : pixels; │ │ │ │ │ + for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ + var ctrl = controls[i]; │ │ │ │ │ + var px = (pxs[i]) ? pxs[i] : null; │ │ │ │ │ + this.addControl(ctrl, px); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addControlToMap │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * │ │ │ │ │ + * control - {} │ │ │ │ │ + * px - {} │ │ │ │ │ + */ │ │ │ │ │ + addControlToMap: function(control, px) { │ │ │ │ │ + // If a control doesn't have a div at this point, it belongs in the │ │ │ │ │ + // viewport. │ │ │ │ │ + control.outsideViewport = (control.div != null); │ │ │ │ │ + │ │ │ │ │ + // If the map has a displayProjection, and the control doesn't, set │ │ │ │ │ + // the display projection. │ │ │ │ │ + if (this.displayProjection && !control.displayProjection) { │ │ │ │ │ + control.displayProjection = this.displayProjection; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + control.setMap(this); │ │ │ │ │ + var div = control.draw(px); │ │ │ │ │ + if (div) { │ │ │ │ │ + if (!control.outsideViewport) { │ │ │ │ │ + div.style.zIndex = this.Z_INDEX_BASE['Control'] + │ │ │ │ │ + this.controls.length; │ │ │ │ │ + this.viewPortDiv.appendChild(div); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (control.autoActivate) { │ │ │ │ │ + control.activate(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getControl │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {String} ID of the control to return. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The control from the map's list of controls │ │ │ │ │ + * which has a matching 'id'. If none found, │ │ │ │ │ + * returns null. │ │ │ │ │ + */ │ │ │ │ │ + getControl: function(id) { │ │ │ │ │ + var returnControl = null; │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + var control = this.controls[i]; │ │ │ │ │ + if (control.id == id) { │ │ │ │ │ + returnControl = control; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return returnControl; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removeControl │ │ │ │ │ + * Remove a control from the map. Removes the control both from the map │ │ │ │ │ + * object's internal array of controls, as well as from the map's │ │ │ │ │ + * viewPort (assuming the control was not added outsideViewport) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} The control to remove. │ │ │ │ │ + */ │ │ │ │ │ + removeControl: function(control) { │ │ │ │ │ + //make sure control is non-null and actually part of our map │ │ │ │ │ + if ((control) && (control == this.getControl(control.id))) { │ │ │ │ │ + if (control.div && (control.div.parentNode == this.viewPortDiv)) { │ │ │ │ │ + this.viewPortDiv.removeChild(control.div); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.removeItem(this.controls, control); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Popup Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with adding and */ │ │ │ │ │ + /* removing Popups to and from the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addPopup │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * popup - {} │ │ │ │ │ + * exclusive - {Boolean} If true, closes all other popups first │ │ │ │ │ + */ │ │ │ │ │ + addPopup: function(popup, exclusive) { │ │ │ │ │ + │ │ │ │ │ + if (exclusive) { │ │ │ │ │ + //remove all other popups from screen │ │ │ │ │ + for (var i = this.popups.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removePopup(this.popups[i]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + popup.map = this; │ │ │ │ │ + this.popups.push(popup); │ │ │ │ │ + var popupDiv = popup.draw(); │ │ │ │ │ + if (popupDiv) { │ │ │ │ │ + popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + │ │ │ │ │ + this.popups.length; │ │ │ │ │ + this.layerContainerDiv.appendChild(popupDiv); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removePopup │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * popup - {} │ │ │ │ │ + */ │ │ │ │ │ + removePopup: function(popup) { │ │ │ │ │ + OpenLayers.Util.removeItem(this.popups, popup); │ │ │ │ │ + if (popup.div) { │ │ │ │ │ + try { │ │ │ │ │ + this.layerContainerDiv.removeChild(popup.div); │ │ │ │ │ + } catch (e) {} // Popups sometimes apparently get disconnected │ │ │ │ │ + // from the layerContainerDiv, and cause complaints. │ │ │ │ │ + } │ │ │ │ │ + popup.map = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Container Div Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions deal with the access to */ │ │ │ │ │ + /* and maintenance of the size of the container div */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getSize │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An object that represents the │ │ │ │ │ + * size, in pixels, of the div into which OpenLayers │ │ │ │ │ + * has been loaded. │ │ │ │ │ + * Note - A clone() of this locally cached variable is │ │ │ │ │ + * returned, so as not to allow users to modify it. │ │ │ │ │ + */ │ │ │ │ │ + getSize: function() { │ │ │ │ │ + var size = null; │ │ │ │ │ + if (this.size != null) { │ │ │ │ │ + size = this.size.clone(); │ │ │ │ │ + } │ │ │ │ │ + return size; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: updateSize │ │ │ │ │ + * This function should be called by any external code which dynamically │ │ │ │ │ + * changes the size of the map div (because mozilla wont let us catch │ │ │ │ │ + * the "onresize" for an element) │ │ │ │ │ + */ │ │ │ │ │ + updateSize: function() { │ │ │ │ │ + // the div might have moved on the page, also │ │ │ │ │ + var newSize = this.getCurrentSize(); │ │ │ │ │ + if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) { │ │ │ │ │ + this.events.clearMouseCache(); │ │ │ │ │ + var oldSize = this.getSize(); │ │ │ │ │ + if (oldSize == null) { │ │ │ │ │ + this.size = oldSize = newSize; │ │ │ │ │ + } │ │ │ │ │ + if (!newSize.equals(oldSize)) { │ │ │ │ │ + │ │ │ │ │ + // store the new size │ │ │ │ │ + this.size = newSize; │ │ │ │ │ + │ │ │ │ │ + //notify layers of mapresize │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + this.layers[i].onMapResize(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ + │ │ │ │ │ + if (this.baseLayer != null && center != null) { │ │ │ │ │ + var zoom = this.getZoom(); │ │ │ │ │ + this.zoom = null; │ │ │ │ │ + this.setCenter(center, zoom); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("updatesize"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getCurrentSize │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A new object with the dimensions │ │ │ │ │ + * of the map div │ │ │ │ │ + */ │ │ │ │ │ + getCurrentSize: function() { │ │ │ │ │ + │ │ │ │ │ + var size = new OpenLayers.Size(this.div.clientWidth, │ │ │ │ │ + this.div.clientHeight); │ │ │ │ │ + │ │ │ │ │ + if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ + size.w = this.div.offsetWidth; │ │ │ │ │ + size.h = this.div.offsetHeight; │ │ │ │ │ + } │ │ │ │ │ + if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) { │ │ │ │ │ + size.w = parseInt(this.div.style.width); │ │ │ │ │ + size.h = parseInt(this.div.style.height); │ │ │ │ │ + } │ │ │ │ │ + return size; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * center - {} Default is this.getCenter() │ │ │ │ │ + * resolution - {float} Default is this.getResolution() │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A bounds based on resolution, center, and │ │ │ │ │ + * current mapsize. │ │ │ │ │ + */ │ │ │ │ │ + calculateBounds: function(center, resolution) { │ │ │ │ │ + │ │ │ │ │ + var extent = null; │ │ │ │ │ + │ │ │ │ │ + if (center == null) { │ │ │ │ │ + center = this.getCachedCenter(); │ │ │ │ │ + } │ │ │ │ │ + if (resolution == null) { │ │ │ │ │ + resolution = this.getResolution(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if ((center != null) && (resolution != null)) { │ │ │ │ │ + var halfWDeg = (this.size.w * resolution) / 2; │ │ │ │ │ + var halfHDeg = (this.size.h * resolution) / 2; │ │ │ │ │ + │ │ │ │ │ + extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ + center.lat - halfHDeg, │ │ │ │ │ + center.lon + halfWDeg, │ │ │ │ │ + center.lat + halfHDeg); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return extent; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Zoom, Center, Pan Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions handle the validation, */ │ │ │ │ │ + /* getting and setting of the Zoom Level and Center */ │ │ │ │ │ + /* as well as the panning of the Map */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getCenter │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getCenter: function() { │ │ │ │ │ + var center = null; │ │ │ │ │ + var cachedCenter = this.getCachedCenter(); │ │ │ │ │ + if (cachedCenter) { │ │ │ │ │ + center = cachedCenter.clone(); │ │ │ │ │ + } │ │ │ │ │ + return center; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getCachedCenter │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getCachedCenter: function() { │ │ │ │ │ + if (!this.center && this.size) { │ │ │ │ │ + this.center = this.getLonLatFromViewPortPx({ │ │ │ │ │ + x: this.size.w / 2, │ │ │ │ │ + y: this.size.h / 2 │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + return this.center; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getZoom │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ + getZoom: function() { │ │ │ │ │ + return this.zoom; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: pan │ │ │ │ │ + * Allows user to pan by a value of screen pixels │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * dx - {Integer} │ │ │ │ │ + * dy - {Integer} │ │ │ │ │ + * options - {Object} Options to configure panning: │ │ │ │ │ + * - *animate* {Boolean} Use panTo instead of setCenter. Default is true. │ │ │ │ │ + * - *dragging* {Boolean} Call setCenter with dragging true. Default is │ │ │ │ │ + * false. │ │ │ │ │ + */ │ │ │ │ │ + pan: function(dx, dy, options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults(options, { │ │ │ │ │ + animate: true, │ │ │ │ │ + dragging: false │ │ │ │ │ + }); │ │ │ │ │ + if (options.dragging) { │ │ │ │ │ + if (dx != 0 || dy != 0) { │ │ │ │ │ + this.moveByPx(dx, dy); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // getCenter │ │ │ │ │ + var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter()); │ │ │ │ │ + │ │ │ │ │ + // adjust │ │ │ │ │ + var newCenterPx = centerPx.add(dx, dy); │ │ │ │ │ + │ │ │ │ │ + if (this.dragging || !newCenterPx.equals(centerPx)) { │ │ │ │ │ + var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); │ │ │ │ │ + if (options.animate) { │ │ │ │ │ + this.panTo(newCenterLonLat); │ │ │ │ │ + } else { │ │ │ │ │ + this.moveTo(newCenterLonLat); │ │ │ │ │ + if (this.dragging) { │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.events.triggerEvent("moveend"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: panTo │ │ │ │ │ + * Allows user to pan to a new lonlat │ │ │ │ │ + * If the new lonlat is in the current extent the map will slide smoothly │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + */ │ │ │ │ │ + panTo: function(lonlat) { │ │ │ │ │ + if (this.panTween && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ + │ │ │ │ │ + // center will not change, don't do nothing │ │ │ │ │ + if (lonlat.equals(center)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var from = this.getPixelFromLonLat(center); │ │ │ │ │ + var to = this.getPixelFromLonLat(lonlat); │ │ │ │ │ + var vector = { │ │ │ │ │ + x: to.x - from.x, │ │ │ │ │ + y: to.y - from.y │ │ │ │ │ + }; │ │ │ │ │ + var last = { │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + this.panTween.start({ │ │ │ │ │ + x: 0, │ │ │ │ │ + y: 0 │ │ │ │ │ + }, vector, this.panDuration, { │ │ │ │ │ + callbacks: { │ │ │ │ │ + eachStep: OpenLayers.Function.bind(function(px) { │ │ │ │ │ + var x = px.x - last.x, │ │ │ │ │ + y = px.y - last.y; │ │ │ │ │ + this.moveByPx(x, y); │ │ │ │ │ + last.x = Math.round(px.x); │ │ │ │ │ + last.y = Math.round(px.y); │ │ │ │ │ + }, this), │ │ │ │ │ + done: OpenLayers.Function.bind(function(px) { │ │ │ │ │ + this.moveTo(lonlat); │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.events.triggerEvent("moveend"); │ │ │ │ │ + }, this) │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + this.setCenter(lonlat); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setCenter │ │ │ │ │ + * Set the map center (and optionally, the zoom level). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {|Array} The new center location. │ │ │ │ │ + * If provided as array, the first value is the x coordinate, │ │ │ │ │ + * and the 2nd value is the y coordinate. │ │ │ │ │ + * zoom - {Integer} Optional zoom level. │ │ │ │ │ + * dragging - {Boolean} Specifies whether or not to trigger │ │ │ │ │ + * movestart/end events │ │ │ │ │ + * forceZoomChange - {Boolean} Specifies whether or not to trigger zoom │ │ │ │ │ + * change events (needed on baseLayer change) │ │ │ │ │ + * │ │ │ │ │ + * TBD: reconsider forceZoomChange in 3.0 │ │ │ │ │ + */ │ │ │ │ │ + setCenter: function(lonlat, zoom, dragging, forceZoomChange) { │ │ │ │ │ + if (this.panTween) { │ │ │ │ │ + this.panTween.stop(); │ │ │ │ │ + } │ │ │ │ │ + if (this.zoomTween) { │ │ │ │ │ + this.zoomTween.stop(); │ │ │ │ │ + } │ │ │ │ │ + this.moveTo(lonlat, zoom, { │ │ │ │ │ + 'dragging': dragging, │ │ │ │ │ + 'forceZoomChange': forceZoomChange │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Drag the map by pixels. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * dx - {Number} │ │ │ │ │ + * dy - {Number} │ │ │ │ │ + */ │ │ │ │ │ + moveByPx: function(dx, dy) { │ │ │ │ │ + var hw = this.size.w / 2; │ │ │ │ │ + var hh = this.size.h / 2; │ │ │ │ │ + var x = hw + dx; │ │ │ │ │ + var y = hh + dy; │ │ │ │ │ + var wrapDateLine = this.baseLayer.wrapDateLine; │ │ │ │ │ + var xRestriction = 0; │ │ │ │ │ + var yRestriction = 0; │ │ │ │ │ + if (this.restrictedExtent) { │ │ │ │ │ + xRestriction = hw; │ │ │ │ │ + yRestriction = hh; │ │ │ │ │ + // wrapping the date line makes no sense for restricted extents │ │ │ │ │ + wrapDateLine = false; │ │ │ │ │ + } │ │ │ │ │ + dx = wrapDateLine || │ │ │ │ │ + x <= this.maxPx.x - xRestriction && │ │ │ │ │ + x >= this.minPx.x + xRestriction ? Math.round(dx) : 0; │ │ │ │ │ + dy = y <= this.maxPx.y - yRestriction && │ │ │ │ │ + y >= this.minPx.y + yRestriction ? Math.round(dy) : 0; │ │ │ │ │ + if (dx || dy) { │ │ │ │ │ + if (!this.dragging) { │ │ │ │ │ + this.dragging = true; │ │ │ │ │ + this.events.triggerEvent("movestart"); │ │ │ │ │ + } │ │ │ │ │ + this.center = null; │ │ │ │ │ + if (dx) { │ │ │ │ │ + this.layerContainerOriginPx.x -= dx; │ │ │ │ │ + this.minPx.x -= dx; │ │ │ │ │ + this.maxPx.x -= dx; │ │ │ │ │ + } │ │ │ │ │ + if (dy) { │ │ │ │ │ + this.layerContainerOriginPx.y -= dy; │ │ │ │ │ + this.minPx.y -= dy; │ │ │ │ │ + this.maxPx.y -= dy; │ │ │ │ │ + } │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ + var layer, i, len; │ │ │ │ │ + for (i = 0, len = this.layers.length; i < len; ++i) { │ │ │ │ │ + layer = this.layers[i]; │ │ │ │ │ + if (layer.visibility && │ │ │ │ │ + (layer === this.baseLayer || layer.inRange)) { │ │ │ │ │ + layer.moveByPx(dx, dy); │ │ │ │ │ + layer.events.triggerEvent("move"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("move"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: adjustZoom │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Number} The zoom level to adjust │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} Adjusted zoom level that shows a map not wider than its │ │ │ │ │ + * 's maxExtent. │ │ │ │ │ + */ │ │ │ │ │ + adjustZoom: function(zoom) { │ │ │ │ │ + if (this.baseLayer && this.baseLayer.wrapDateLine) { │ │ │ │ │ + var resolution, resolutions = this.baseLayer.resolutions, │ │ │ │ │ + maxResolution = this.getMaxExtent().getWidth() / this.size.w; │ │ │ │ │ + if (this.getResolutionForZoom(zoom) > maxResolution) { │ │ │ │ │ + if (this.fractionalZoom) { │ │ │ │ │ + zoom = this.getZoomForResolution(maxResolution); │ │ │ │ │ + } else { │ │ │ │ │ + for (var i = zoom | 0, ii = resolutions.length; i < ii; ++i) { │ │ │ │ │ + if (resolutions[i] <= maxResolution) { │ │ │ │ │ + zoom = i; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getMinZoom │ │ │ │ │ + * Returns the minimum zoom level for the current map view. If the base │ │ │ │ │ + * layer is configured with set to true, this will be the │ │ │ │ │ + * first zoom level that shows no more than one world width in the current │ │ │ │ │ + * map viewport. Components that rely on this value (e.g. zoom sliders) │ │ │ │ │ + * should also listen to the map's "updatesize" event and call this method │ │ │ │ │ + * in the "updatesize" listener. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} Minimum zoom level that shows a map not wider than its │ │ │ │ │ + * 's maxExtent. This is an Integer value, unless the map is │ │ │ │ │ + * configured with set to true. │ │ │ │ │ + */ │ │ │ │ │ + getMinZoom: function() { │ │ │ │ │ + return this.adjustZoom(0); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * zoom - {Integer} │ │ │ │ │ + * options - {Object} │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(lonlat, zoom, options) { │ │ │ │ │ + if (lonlat != null && !(lonlat instanceof OpenLayers.LonLat)) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lonlat); │ │ │ │ │ + } │ │ │ │ │ + if (!options) { │ │ │ │ │ + options = {}; │ │ │ │ │ + } │ │ │ │ │ + if (zoom != null) { │ │ │ │ │ + zoom = parseFloat(zoom); │ │ │ │ │ + if (!this.fractionalZoom) { │ │ │ │ │ + zoom = Math.round(zoom); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var requestedZoom = zoom; │ │ │ │ │ + zoom = this.adjustZoom(zoom); │ │ │ │ │ + if (zoom !== requestedZoom) { │ │ │ │ │ + // zoom was adjusted, so keep old lonlat to avoid panning │ │ │ │ │ + lonlat = this.getCenter(); │ │ │ │ │ + } │ │ │ │ │ + // dragging is false by default │ │ │ │ │ + var dragging = options.dragging || this.dragging; │ │ │ │ │ + // forceZoomChange is false by default │ │ │ │ │ + var forceZoomChange = options.forceZoomChange; │ │ │ │ │ + │ │ │ │ │ + if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) { │ │ │ │ │ + lonlat = this.maxExtent.getCenterLonLat(); │ │ │ │ │ + this.center = lonlat.clone(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.restrictedExtent != null) { │ │ │ │ │ + // In 3.0, decide if we want to change interpretation of maxExtent. │ │ │ │ │ + if (lonlat == null) { │ │ │ │ │ + lonlat = this.center; │ │ │ │ │ + } │ │ │ │ │ + if (zoom == null) { │ │ │ │ │ + zoom = this.getZoom(); │ │ │ │ │ + } │ │ │ │ │ + var resolution = this.getResolutionForZoom(zoom); │ │ │ │ │ + var extent = this.calculateBounds(lonlat, resolution); │ │ │ │ │ + if (!this.restrictedExtent.containsBounds(extent)) { │ │ │ │ │ + var maxCenter = this.restrictedExtent.getCenterLonLat(); │ │ │ │ │ + if (extent.getWidth() > this.restrictedExtent.getWidth()) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(maxCenter.lon, lonlat.lat); │ │ │ │ │ + } else if (extent.left < this.restrictedExtent.left) { │ │ │ │ │ + lonlat = lonlat.add(this.restrictedExtent.left - │ │ │ │ │ + extent.left, 0); │ │ │ │ │ + } else if (extent.right > this.restrictedExtent.right) { │ │ │ │ │ + lonlat = lonlat.add(this.restrictedExtent.right - │ │ │ │ │ + extent.right, 0); │ │ │ │ │ + } │ │ │ │ │ + if (extent.getHeight() > this.restrictedExtent.getHeight()) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lonlat.lon, maxCenter.lat); │ │ │ │ │ + } else if (extent.bottom < this.restrictedExtent.bottom) { │ │ │ │ │ + lonlat = lonlat.add(0, this.restrictedExtent.bottom - │ │ │ │ │ + extent.bottom); │ │ │ │ │ + } else if (extent.top > this.restrictedExtent.top) { │ │ │ │ │ + lonlat = lonlat.add(0, this.restrictedExtent.top - │ │ │ │ │ + extent.top); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var zoomChanged = forceZoomChange || ( │ │ │ │ │ + (this.isValidZoomLevel(zoom)) && │ │ │ │ │ + (zoom != this.getZoom())); │ │ │ │ │ + │ │ │ │ │ + var centerChanged = (this.isValidLonLat(lonlat)) && │ │ │ │ │ + (!lonlat.equals(this.center)); │ │ │ │ │ + │ │ │ │ │ + // if neither center nor zoom will change, no need to do anything │ │ │ │ │ + if (zoomChanged || centerChanged || dragging) { │ │ │ │ │ + dragging || this.events.triggerEvent("movestart", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + if (centerChanged) { │ │ │ │ │ + if (!zoomChanged && this.center) { │ │ │ │ │ + // if zoom hasnt changed, just slide layerContainer │ │ │ │ │ + // (must be done before setting this.center to new value) │ │ │ │ │ + this.centerLayerContainer(lonlat); │ │ │ │ │ + } │ │ │ │ │ + this.center = lonlat.clone(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var res = zoomChanged ? │ │ │ │ │ + this.getResolutionForZoom(zoom) : this.getResolution(); │ │ │ │ │ + // (re)set the layerContainerDiv's location │ │ │ │ │ + if (zoomChanged || this.layerContainerOrigin == null) { │ │ │ │ │ + this.layerContainerOrigin = this.getCachedCenter(); │ │ │ │ │ + this.layerContainerOriginPx.x = 0; │ │ │ │ │ + this.layerContainerOriginPx.y = 0; │ │ │ │ │ + this.applyTransform(); │ │ │ │ │ + var maxExtent = this.getMaxExtent({ │ │ │ │ │ + restricted: true │ │ │ │ │ + }); │ │ │ │ │ + var maxExtentCenter = maxExtent.getCenterLonLat(); │ │ │ │ │ + var lonDelta = this.center.lon - maxExtentCenter.lon; │ │ │ │ │ + var latDelta = maxExtentCenter.lat - this.center.lat; │ │ │ │ │ + var extentWidth = Math.round(maxExtent.getWidth() / res); │ │ │ │ │ + var extentHeight = Math.round(maxExtent.getHeight() / res); │ │ │ │ │ + this.minPx = { │ │ │ │ │ + x: (this.size.w - extentWidth) / 2 - lonDelta / res, │ │ │ │ │ + y: (this.size.h - extentHeight) / 2 - latDelta / res │ │ │ │ │ + }; │ │ │ │ │ + this.maxPx = { │ │ │ │ │ + x: this.minPx.x + Math.round(maxExtent.getWidth() / res), │ │ │ │ │ + y: this.minPx.y + Math.round(maxExtent.getHeight() / res) │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (zoomChanged) { │ │ │ │ │ + this.zoom = zoom; │ │ │ │ │ + this.resolution = res; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var bounds = this.getExtent(); │ │ │ │ │ + │ │ │ │ │ + //send the move call to the baselayer and all the overlays │ │ │ │ │ + │ │ │ │ │ + if (this.baseLayer.visibility) { │ │ │ │ │ + this.baseLayer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ + options.dragging || this.baseLayer.events.triggerEvent( │ │ │ │ │ + "moveend", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + bounds = this.baseLayer.getExtent(); │ │ │ │ │ + │ │ │ │ │ + for (var i = this.layers.length - 1; i >= 0; --i) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer !== this.baseLayer && !layer.isBaseLayer) { │ │ │ │ │ + var inRange = layer.calculateInRange(); │ │ │ │ │ + if (layer.inRange != inRange) { │ │ │ │ │ + // the inRange property has changed. If the layer is │ │ │ │ │ + // no longer in range, we turn it off right away. If │ │ │ │ │ + // the layer is no longer out of range, the moveTo │ │ │ │ │ + // call below will turn on the layer. │ │ │ │ │ + layer.inRange = inRange; │ │ │ │ │ + if (!inRange) { │ │ │ │ │ + layer.display(false); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: layer, │ │ │ │ │ + property: "visibility" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (inRange && layer.visibility) { │ │ │ │ │ + layer.moveTo(bounds, zoomChanged, options.dragging); │ │ │ │ │ + options.dragging || layer.events.triggerEvent( │ │ │ │ │ + "moveend", { │ │ │ │ │ + zoomChanged: zoomChanged │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.events.triggerEvent("move"); │ │ │ │ │ + dragging || this.events.triggerEvent("moveend"); │ │ │ │ │ + │ │ │ │ │ + if (zoomChanged) { │ │ │ │ │ + //redraw popups │ │ │ │ │ + for (var i = 0, len = this.popups.length; i < len; i++) { │ │ │ │ │ + this.popups[i].updatePosition(); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("zoomend"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: centerLayerContainer │ │ │ │ │ + * This function takes care to recenter the layerContainerDiv. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + */ │ │ │ │ │ + centerLayerContainer: function(lonlat) { │ │ │ │ │ + var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin); │ │ │ │ │ + var newPx = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + │ │ │ │ │ + if ((originPx != null) && (newPx != null)) { │ │ │ │ │ + var oldLeft = this.layerContainerOriginPx.x; │ │ │ │ │ + var oldTop = this.layerContainerOriginPx.y; │ │ │ │ │ + var newLeft = Math.round(originPx.x - newPx.x); │ │ │ │ │ + var newTop = Math.round(originPx.y - newPx.y); │ │ │ │ │ + this.applyTransform( │ │ │ │ │ + (this.layerContainerOriginPx.x = newLeft), │ │ │ │ │ + (this.layerContainerOriginPx.y = newTop)); │ │ │ │ │ + var dx = oldLeft - newLeft; │ │ │ │ │ + var dy = oldTop - newTop; │ │ │ │ │ + this.minPx.x -= dx; │ │ │ │ │ + this.maxPx.x -= dx; │ │ │ │ │ + this.minPx.y -= dy; │ │ │ │ │ + this.maxPx.y -= dy; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: isValidZoomLevel │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoomLevel - {Integer} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the zoom level passed in is non-null and │ │ │ │ │ + * within the min/max range of zoom levels. │ │ │ │ │ + */ │ │ │ │ │ + isValidZoomLevel: function(zoomLevel) { │ │ │ │ │ + return ((zoomLevel != null) && │ │ │ │ │ + (zoomLevel >= 0) && │ │ │ │ │ + (zoomLevel < this.getNumZoomLevels())); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: isValidLonLat │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the lonlat passed in is non-null and within │ │ │ │ │ + * the maxExtent bounds │ │ │ │ │ + */ │ │ │ │ │ + isValidLonLat: function(lonlat) { │ │ │ │ │ + var valid = false; │ │ │ │ │ + if (lonlat != null) { │ │ │ │ │ + var maxExtent = this.getMaxExtent(); │ │ │ │ │ + var worldBounds = this.baseLayer.wrapDateLine && maxExtent; │ │ │ │ │ + valid = maxExtent.containsLonLat(lonlat, { │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + return valid; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Layer Options */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Accessor functions to Layer Options parameters */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getProjection │ │ │ │ │ + * This method returns a string representing the projection. In │ │ │ │ │ + * the case of projection support, this will be the srsCode which │ │ │ │ │ + * is loaded -- otherwise it will simply be the string value that │ │ │ │ │ + * was passed to the projection at startup. │ │ │ │ │ + * │ │ │ │ │ + * FIXME: In 3.0, we will remove getProjectionObject, and instead │ │ │ │ │ + * return a Projection object from this function. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The Projection string from the base layer or null. │ │ │ │ │ + */ │ │ │ │ │ + getProjection: function() { │ │ │ │ │ + var projection = this.getProjectionObject(); │ │ │ │ │ + return projection ? projection.getCode() : null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getProjectionObject │ │ │ │ │ + * Returns the projection obect from the baselayer. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The Projection of the base layer. │ │ │ │ │ + */ │ │ │ │ │ + getProjectionObject: function() { │ │ │ │ │ + var projection = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + projection = this.baseLayer.projection; │ │ │ │ │ + } │ │ │ │ │ + return projection; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getMaxResolution │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The Map's Maximum Resolution │ │ │ │ │ + */ │ │ │ │ │ + getMaxResolution: function() { │ │ │ │ │ + var maxResolution = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + maxResolution = this.baseLayer.maxResolution; │ │ │ │ │ + } │ │ │ │ │ + return maxResolution; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getMaxExtent │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Allowed Options: │ │ │ │ │ + * restricted - {Boolean} If true, returns restricted extent (if it is │ │ │ │ │ + * available.) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The maxExtent property as set on the current │ │ │ │ │ + * baselayer, unless the 'restricted' option is set, in which case │ │ │ │ │ + * the 'restrictedExtent' option from the map is returned (if it │ │ │ │ │ + * is set). │ │ │ │ │ + */ │ │ │ │ │ + getMaxExtent: function(options) { │ │ │ │ │ + var maxExtent = null; │ │ │ │ │ + if (options && options.restricted && this.restrictedExtent) { │ │ │ │ │ + maxExtent = this.restrictedExtent; │ │ │ │ │ + } else if (this.baseLayer != null) { │ │ │ │ │ + maxExtent = this.baseLayer.maxExtent; │ │ │ │ │ + } │ │ │ │ │ + return maxExtent; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getNumZoomLevels │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The total number of zoom levels that can be displayed by the │ │ │ │ │ + * current baseLayer. │ │ │ │ │ + */ │ │ │ │ │ + getNumZoomLevels: function() { │ │ │ │ │ + var numZoomLevels = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + numZoomLevels = this.baseLayer.numZoomLevels; │ │ │ │ │ + } │ │ │ │ │ + return numZoomLevels; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Baselayer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions, all publicly exposed */ │ │ │ │ │ + /* in the API?, are all merely wrappers to the */ │ │ │ │ │ + /* the same calls on whatever layer is set as */ │ │ │ │ │ + /* the current base layer */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + var extent = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + extent = this.baseLayer.getExtent(); │ │ │ │ │ + } │ │ │ │ │ + return extent; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getResolution │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current resolution of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + var resolution = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + resolution = this.baseLayer.getResolution(); │ │ │ │ │ + } else if (this.allOverlays === true && this.layers.length > 0) { │ │ │ │ │ + // while adding the 1st layer to the map in allOverlays mode, │ │ │ │ │ + // this.baseLayer is not set yet when we need the resolution │ │ │ │ │ + // for calculateInRange. │ │ │ │ │ + resolution = this.layers[0].getResolution(); │ │ │ │ │ + } │ │ │ │ │ + return resolution; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getUnits │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current units of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + var units = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + units = this.baseLayer.units; │ │ │ │ │ + } │ │ │ │ │ + return units; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getScale │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current scale denominator of the map. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getScale: function() { │ │ │ │ │ + var scale = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + var units = this.baseLayer.units; │ │ │ │ │ + scale = OpenLayers.Util.getScaleFromResolution(res, units); │ │ │ │ │ + } │ │ │ │ │ + return scale; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getZoomForExtent │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} A suitable zoom level for the specified bounds. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getZoomForExtent: function(bounds, closest) { │ │ │ │ │ + var zoom = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + zoom = this.baseLayer.getZoomForExtent(bounds, closest); │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. If no baselayer │ │ │ │ │ + * is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getResolutionForZoom: function(zoom) { │ │ │ │ │ + var resolution = null; │ │ │ │ │ + if (this.baseLayer) { │ │ │ │ │ + resolution = this.baseLayer.getResolutionForZoom(zoom); │ │ │ │ │ + } │ │ │ │ │ + return resolution; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getZoomForResolution │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * resolution - {Float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ + * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ + * resolution is actually smaller than we would have desired (if this │ │ │ │ │ + * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ + * the returned zoom index might not actually contain the entire │ │ │ │ │ + * extent specified... but it'll be close). │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} A suitable zoom level for the specified resolution. │ │ │ │ │ + * If no baselayer is set, returns null. │ │ │ │ │ + */ │ │ │ │ │ + getZoomForResolution: function(resolution, closest) { │ │ │ │ │ + var zoom = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + zoom = this.baseLayer.getZoomForResolution(resolution, closest); │ │ │ │ │ + } │ │ │ │ │ + return zoom; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Zooming Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions, all publicly exposed */ │ │ │ │ │ + /* in the API, are all merely wrappers to the */ │ │ │ │ │ + /* the setCenter() function */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomTo │ │ │ │ │ + * Zoom to a specific zoom level. Zooming will be animated unless the map │ │ │ │ │ + * is configured with {zoomMethod: null}. To zoom without animation, use │ │ │ │ │ + * without a lonlat argument. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Integer} │ │ │ │ │ + */ │ │ │ │ │ + zoomTo: function(zoom, xy) { │ │ │ │ │ + // non-API arguments: │ │ │ │ │ + // xy - {} optional zoom origin │ │ │ │ │ + │ │ │ │ │ + var map = this; │ │ │ │ │ + if (map.isValidZoomLevel(zoom)) { │ │ │ │ │ + if (map.baseLayer.wrapDateLine) { │ │ │ │ │ + zoom = map.adjustZoom(zoom); │ │ │ │ │ + } │ │ │ │ │ + if (map.zoomTween) { │ │ │ │ │ + var currentRes = map.getResolution(), │ │ │ │ │ + targetRes = map.getResolutionForZoom(zoom), │ │ │ │ │ + start = { │ │ │ │ │ + scale: 1 │ │ │ │ │ + }, │ │ │ │ │ + end = { │ │ │ │ │ + scale: currentRes / targetRes │ │ │ │ │ + }; │ │ │ │ │ + if (map.zoomTween.playing && map.zoomTween.duration < 3 * map.zoomDuration) { │ │ │ │ │ + // update the end scale, and reuse the running zoomTween │ │ │ │ │ + map.zoomTween.finish = { │ │ │ │ │ + scale: map.zoomTween.finish.scale * end.scale │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + if (!xy) { │ │ │ │ │ + var size = map.getSize(); │ │ │ │ │ + xy = { │ │ │ │ │ + x: size.w / 2, │ │ │ │ │ + y: size.h / 2 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + map.zoomTween.start(start, end, map.zoomDuration, { │ │ │ │ │ + minFrameRate: 50, // don't spend much time zooming │ │ │ │ │ + callbacks: { │ │ │ │ │ + eachStep: function(data) { │ │ │ │ │ + var containerOrigin = map.layerContainerOriginPx, │ │ │ │ │ + scale = data.scale, │ │ │ │ │ + dx = ((scale - 1) * (containerOrigin.x - xy.x)) | 0, │ │ │ │ │ + dy = ((scale - 1) * (containerOrigin.y - xy.y)) | 0; │ │ │ │ │ + map.applyTransform(containerOrigin.x + dx, containerOrigin.y + dy, scale); │ │ │ │ │ + }, │ │ │ │ │ + done: function(data) { │ │ │ │ │ + map.applyTransform(); │ │ │ │ │ + var resolution = map.getResolution() / data.scale, │ │ │ │ │ + zoom = map.getZoomForResolution(resolution, true) │ │ │ │ │ + map.moveTo(map.getZoomTargetCenter(xy, resolution), zoom, true); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var center = xy ? │ │ │ │ │ + map.getZoomTargetCenter(xy, map.getResolutionForZoom(zoom)) : │ │ │ │ │ + null; │ │ │ │ │ + map.setCenter(center, zoom); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomIn │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + zoomIn: function() { │ │ │ │ │ + this.zoomTo(this.getZoom() + 1); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomOut │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + zoomOut: function() { │ │ │ │ │ + this.zoomTo(this.getZoom() - 1); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomToExtent │ │ │ │ │ + * Zoom to the passed in bounds, recenter │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + zoomToExtent: function(bounds, closest) { │ │ │ │ │ + if (!(bounds instanceof OpenLayers.Bounds)) { │ │ │ │ │ + bounds = new OpenLayers.Bounds(bounds); │ │ │ │ │ + } │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + if (this.baseLayer.wrapDateLine) { │ │ │ │ │ + var maxExtent = this.getMaxExtent(); │ │ │ │ │ + │ │ │ │ │ + //fix straddling bounds (in the case of a bbox that straddles the │ │ │ │ │ + // dateline, it's left and right boundaries will appear backwards. │ │ │ │ │ + // we fix this by allowing a right value that is greater than the │ │ │ │ │ + // max value at the dateline -- this allows us to pass a valid │ │ │ │ │ + // bounds to calculate zoom) │ │ │ │ │ + // │ │ │ │ │ + bounds = bounds.clone(); │ │ │ │ │ + while (bounds.right < bounds.left) { │ │ │ │ │ + bounds.right += maxExtent.getWidth(); │ │ │ │ │ + } │ │ │ │ │ + //if the bounds was straddling (see above), then the center point │ │ │ │ │ + // we got from it was wrong. So we take our new bounds and ask it │ │ │ │ │ + // for the center. │ │ │ │ │ + // │ │ │ │ │ + center = bounds.getCenterLonLat().wrapDateLine(maxExtent); │ │ │ │ │ + } │ │ │ │ │ + this.setCenter(center, this.getZoomForExtent(bounds, closest)); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomToMaxExtent │ │ │ │ │ + * Zoom to the full extent and recenter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Allowed Options: │ │ │ │ │ + * restricted - {Boolean} True to zoom to restricted extent if it is │ │ │ │ │ + * set. Defaults to true. │ │ │ │ │ + */ │ │ │ │ │ + zoomToMaxExtent: function(options) { │ │ │ │ │ + //restricted is true by default │ │ │ │ │ + var restricted = (options) ? options.restricted : true; │ │ │ │ │ + │ │ │ │ │ + var maxExtent = this.getMaxExtent({ │ │ │ │ │ + 'restricted': restricted │ │ │ │ │ + }); │ │ │ │ │ + this.zoomToExtent(maxExtent); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: zoomToScale │ │ │ │ │ + * Zoom to a specified scale │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scale - {float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified scale. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + zoomToScale: function(scale, closest) { │ │ │ │ │ + var res = OpenLayers.Util.getResolutionFromScale(scale, │ │ │ │ │ + this.baseLayer.units); │ │ │ │ │ + │ │ │ │ │ + var halfWDeg = (this.size.w * res) / 2; │ │ │ │ │ + var halfHDeg = (this.size.h * res) / 2; │ │ │ │ │ + var center = this.getCachedCenter(); │ │ │ │ │ + │ │ │ │ │ + var extent = new OpenLayers.Bounds(center.lon - halfWDeg, │ │ │ │ │ + center.lat - halfHDeg, │ │ │ │ │ + center.lon + halfWDeg, │ │ │ │ │ + center.lat + halfHDeg); │ │ │ │ │ + this.zoomToExtent(extent, closest); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Translation Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /* The following functions translate between */ │ │ │ │ │ + /* LonLat, LayerPx, and ViewPortPx */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: LonLat <-> ViewPortPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getLonLatFromViewPortPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ + * an object with a 'x' │ │ │ │ │ + * and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ + * port , translated into lon/lat │ │ │ │ │ + * by the current base layer. │ │ │ │ │ + */ │ │ │ │ │ + getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var lonlat = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ + } │ │ │ │ │ + return lonlat; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ + * , translated into view port │ │ │ │ │ + * pixels by the current base layer. │ │ │ │ │ + */ │ │ │ │ │ + getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ + var px = null; │ │ │ │ │ + if (this.baseLayer != null) { │ │ │ │ │ + px = this.baseLayer.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + } │ │ │ │ │ + return px; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getZoomTargetCenter │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} The zoom origin pixel location on the screen │ │ │ │ │ + * resolution - {Float} The resolution we want to get the center for │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The location of the map center after the │ │ │ │ │ + * transformation described by the origin xy and the target resolution. │ │ │ │ │ + */ │ │ │ │ │ + getZoomTargetCenter: function(xy, resolution) { │ │ │ │ │ + var lonlat = null, │ │ │ │ │ + size = this.getSize(), │ │ │ │ │ + deltaX = size.w / 2 - xy.x, │ │ │ │ │ + deltaY = xy.y - size.h / 2, │ │ │ │ │ + zoomPoint = this.getLonLatFromPixel(xy); │ │ │ │ │ + if (zoomPoint) { │ │ │ │ │ + lonlat = new OpenLayers.LonLat( │ │ │ │ │ + zoomPoint.lon + deltaX * resolution, │ │ │ │ │ + zoomPoint.lat + deltaY * resolution │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return lonlat; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // CONVENIENCE TRANSLATION FUNCTIONS FOR API │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLonLatFromPixel │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} An OpenLayers.Pixel or an object with │ │ │ │ │ + * a 'x' and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.LonLat corresponding to the given │ │ │ │ │ + * OpenLayers.Pixel, translated into lon/lat by the │ │ │ │ │ + * current base layer │ │ │ │ │ + */ │ │ │ │ │ + getLonLatFromPixel: function(px) { │ │ │ │ │ + return this.getLonLatFromViewPortPx(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getPixelFromLonLat │ │ │ │ │ + * Returns a pixel location given a map location. The map location is │ │ │ │ │ + * translated to an integer pixel location (in viewport pixel │ │ │ │ │ + * coordinates) by the current base layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} A map location. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.Pixel corresponding to the │ │ │ │ │ + * translated into view port pixels by the current │ │ │ │ │ + * base layer. │ │ │ │ │ + */ │ │ │ │ │ + getPixelFromLonLat: function(lonlat) { │ │ │ │ │ + var px = this.getViewPortPxFromLonLat(lonlat); │ │ │ │ │ + px.x = Math.round(px.x); │ │ │ │ │ + px.y = Math.round(px.y); │ │ │ │ │ + return px; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeodesicPixelSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} The pixel to get the geodesic length for. If │ │ │ │ │ + * not provided, the center pixel of the map viewport will be used. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The geodesic size of the pixel in kilometers. │ │ │ │ │ + */ │ │ │ │ │ + getGeodesicPixelSize: function(px) { │ │ │ │ │ + var lonlat = px ? this.getLonLatFromPixel(px) : ( │ │ │ │ │ + this.getCachedCenter() || new OpenLayers.LonLat(0, 0)); │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + var left = lonlat.add(-res / 2, 0); │ │ │ │ │ + var right = lonlat.add(res / 2, 0); │ │ │ │ │ + var bottom = lonlat.add(0, -res / 2); │ │ │ │ │ + var top = lonlat.add(0, res / 2); │ │ │ │ │ + var dest = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + var source = this.getProjectionObject() || dest; │ │ │ │ │ + if (!source.equals(dest)) { │ │ │ │ │ + left.transform(source, dest); │ │ │ │ │ + right.transform(source, dest); │ │ │ │ │ + bottom.transform(source, dest); │ │ │ │ │ + top.transform(source, dest); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return new OpenLayers.Size( │ │ │ │ │ + OpenLayers.Util.distVincenty(left, right), │ │ │ │ │ + OpenLayers.Util.distVincenty(bottom, top) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: ViewPortPx <-> LayerPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getViewPortPxFromLayerPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layerPx - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Layer Pixel translated into ViewPort Pixel │ │ │ │ │ + * coordinates │ │ │ │ │ + */ │ │ │ │ │ + getViewPortPxFromLayerPx: function(layerPx) { │ │ │ │ │ + var viewPortPx = null; │ │ │ │ │ + if (layerPx != null) { │ │ │ │ │ + var dX = this.layerContainerOriginPx.x; │ │ │ │ │ + var dY = this.layerContainerOriginPx.y; │ │ │ │ │ + viewPortPx = layerPx.add(dX, dY); │ │ │ │ │ + } │ │ │ │ │ + return viewPortPx; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayerPxFromViewPortPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} ViewPort Pixel translated into Layer Pixel │ │ │ │ │ + * coordinates │ │ │ │ │ + */ │ │ │ │ │ + getLayerPxFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var layerPx = null; │ │ │ │ │ + if (viewPortPx != null) { │ │ │ │ │ + var dX = -this.layerContainerOriginPx.x; │ │ │ │ │ + var dY = -this.layerContainerOriginPx.y; │ │ │ │ │ + layerPx = viewPortPx.add(dX, dY); │ │ │ │ │ + if (isNaN(layerPx.x) || isNaN(layerPx.y)) { │ │ │ │ │ + layerPx = null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return layerPx; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + // │ │ │ │ │ + // TRANSLATION: LonLat <-> LayerPx │ │ │ │ │ + // │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getLonLatFromLayerPx │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getLonLatFromLayerPx: function(px) { │ │ │ │ │ + //adjust for displacement of layerContainerDiv │ │ │ │ │ + px = this.getViewPortPxFromLayerPx(px); │ │ │ │ │ + return this.getLonLatFromViewPortPx(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getLayerPxFromLonLat │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} lonlat │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ + * , translated into layer pixels │ │ │ │ │ + * by the current base layer │ │ │ │ │ + */ │ │ │ │ │ + getLayerPxFromLonLat: function(lonlat) { │ │ │ │ │ + //adjust for displacement of layerContainerDiv │ │ │ │ │ + var px = this.getPixelFromLonLat(lonlat); │ │ │ │ │ + return this.getLayerPxFromViewPortPx(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: applyTransform │ │ │ │ │ + * Applies the given transform to the . This method has │ │ │ │ │ + * a 2-stage fallback from translate3d/scale3d via translate/scale to plain │ │ │ │ │ + * style.left/style.top, in which case no scaling is supported. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Number} x parameter for the translation. Defaults to the x value of │ │ │ │ │ + * the map's │ │ │ │ │ + * y - {Number} y parameter for the translation. Defaults to the y value of │ │ │ │ │ + * the map's │ │ │ │ │ + * scale - {Number} scale. Defaults to 1 if not provided. │ │ │ │ │ + */ │ │ │ │ │ + applyTransform: function(x, y, scale) { │ │ │ │ │ + scale = scale || 1; │ │ │ │ │ + var origin = this.layerContainerOriginPx, │ │ │ │ │ + needTransform = scale !== 1; │ │ │ │ │ + x = x || origin.x; │ │ │ │ │ + y = y || origin.y; │ │ │ │ │ + │ │ │ │ │ + var style = this.layerContainerDiv.style, │ │ │ │ │ + transform = this.applyTransform.transform, │ │ │ │ │ + template = this.applyTransform.template; │ │ │ │ │ + │ │ │ │ │ + if (transform === undefined) { │ │ │ │ │ + transform = OpenLayers.Util.vendorPrefix.style('transform'); │ │ │ │ │ + this.applyTransform.transform = transform; │ │ │ │ │ + if (transform) { │ │ │ │ │ + // Try translate3d, but only if the viewPortDiv has a transform │ │ │ │ │ + // defined in a stylesheet │ │ │ │ │ + var computedStyle = OpenLayers.Element.getStyle(this.viewPortDiv, │ │ │ │ │ + OpenLayers.Util.vendorPrefix.css('transform')); │ │ │ │ │ + if (!computedStyle || computedStyle !== 'none') { │ │ │ │ │ + template = ['translate3d(', ',0) ', 'scale3d(', ',1)']; │ │ │ │ │ + style[transform] = [template[0], '0,0', template[1]].join(''); │ │ │ │ │ + } │ │ │ │ │ + // If no transform is defined in the stylesheet or translate3d │ │ │ │ │ + // does not stick, use translate and scale │ │ │ │ │ + if (!template || !~style[transform].indexOf(template[0])) { │ │ │ │ │ + template = ['translate(', ') ', 'scale(', ')']; │ │ │ │ │ + } │ │ │ │ │ + this.applyTransform.template = template; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // If we do 3d transforms, we always want to use them. If we do 2d │ │ │ │ │ + // transforms, we only use them when we need to. │ │ │ │ │ + if (transform !== null && (template[0] === 'translate3d(' || needTransform === true)) { │ │ │ │ │ + // Our 2d transforms are combined with style.left and style.top, so │ │ │ │ │ + // adjust x and y values and set the origin as left and top │ │ │ │ │ + if (needTransform === true && template[0] === 'translate(') { │ │ │ │ │ + x -= origin.x; │ │ │ │ │ + y -= origin.y; │ │ │ │ │ + style.left = origin.x + 'px'; │ │ │ │ │ + style.top = origin.y + 'px'; │ │ │ │ │ + } │ │ │ │ │ + style[transform] = [ │ │ │ │ │ + template[0], x, 'px,', y, 'px', template[1], │ │ │ │ │ + template[2], scale, ',', scale, template[3] │ │ │ │ │ + ].join(''); │ │ │ │ │ + } else { │ │ │ │ │ + style.left = x + 'px'; │ │ │ │ │ + style.top = y + 'px'; │ │ │ │ │ + // We previously might have had needTransform, so remove transform │ │ │ │ │ + if (transform !== null) { │ │ │ │ │ + style[transform] = ''; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Map" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: TILE_WIDTH │ │ │ │ │ + * {Integer} 256 Default tile width (unless otherwise specified) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: TILE_HEIGHT │ │ │ │ │ + * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Layer.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Map.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Layer │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: id │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + name: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + div: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: opacity │ │ │ │ │ + * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ + * is 1. │ │ │ │ │ + */ │ │ │ │ │ + opacity: 1, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: alwaysInRange │ │ │ │ │ + * {Boolean} If a layer's display should not be scale-based, this should │ │ │ │ │ + * be set to true. This will cause the layer, as an overlay, to always │ │ │ │ │ + * be 'active', by always returning true from the calculateInRange() │ │ │ │ │ + * function. │ │ │ │ │ + * │ │ │ │ │ + * If not explicitly specified for a layer, its value will be │ │ │ │ │ + * determined on startup in initResolutions() based on whether or not │ │ │ │ │ + * any scale-specific properties have been set as options on the │ │ │ │ │ + * layer. If no scale-specific options have been set on the layer, we │ │ │ │ │ + * assume that it should always be in range. │ │ │ │ │ + * │ │ │ │ │ + * See #987 for more info. │ │ │ │ │ + */ │ │ │ │ │ + alwaysInRange: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ + * {Array} The properties that are used for calculating resolutions │ │ │ │ │ + * information. │ │ │ │ │ + */ │ │ │ │ │ + RESOLUTION_PROPERTIES: [ │ │ │ │ │ + 'scales', 'resolutions', │ │ │ │ │ + 'maxScale', 'minScale', │ │ │ │ │ + 'maxResolution', 'minResolution', │ │ │ │ │ + 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ + ], │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to layer.events.object. │ │ │ │ │ + * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ + * │ │ │ │ │ + * Supported map event types: │ │ │ │ │ + * loadstart - Triggered when layer loading starts. When using a Vector │ │ │ │ │ + * layer with a Fixed or BBOX strategy, the event object includes │ │ │ │ │ + * a *filter* property holding the OpenLayers.Filter used when │ │ │ │ │ + * calling read on the protocol. │ │ │ │ │ + * loadend - Triggered when layer loading ends. When using a Vector layer │ │ │ │ │ + * with a Fixed or BBOX strategy, the event object includes a │ │ │ │ │ + * *response* property holding an OpenLayers.Protocol.Response object. │ │ │ │ │ + * visibilitychanged - Triggered when the layer's visibility property is │ │ │ │ │ + * changed, e.g. by turning the layer on or off in the layer switcher. │ │ │ │ │ + * Note that the actual visibility of the layer can also change if it │ │ │ │ │ + * gets out of range (see ). If you also want to catch │ │ │ │ │ + * these cases, register for the map's 'changelayer' event instead. │ │ │ │ │ + * move - Triggered when layer moves (triggered with every mousemove │ │ │ │ │ + * during a drag). │ │ │ │ │ + * moveend - Triggered when layer is done moving, object passed as │ │ │ │ │ + * argument has a zoomChanged boolean property which tells that the │ │ │ │ │ + * zoom has changed. │ │ │ │ │ + * added - Triggered after the layer is added to a map. Listeners will │ │ │ │ │ + * receive an object with a *map* property referencing the map and a │ │ │ │ │ + * *layer* property referencing the layer. │ │ │ │ │ + * removed - Triggered after the layer is removed from the map. Listeners │ │ │ │ │ + * will receive an object with a *map* property referencing the map and │ │ │ │ │ + * a *layer* property referencing the layer. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: map │ │ │ │ │ + * {} This variable is set when the layer is added to │ │ │ │ │ + * the map, via the accessor function setMap(). │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ + * individually by all subclasses. Default is false │ │ │ │ │ + */ │ │ │ │ │ + isBaseLayer: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: alpha │ │ │ │ │ + * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + alpha: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ + * true. │ │ │ │ │ + */ │ │ │ │ │ + displayInLayerSwitcher: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: visibility │ │ │ │ │ + * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + visibility: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: attribution │ │ │ │ │ + * {String} Attribution string, displayed when an │ │ │ │ │ + * has been added to the map. │ │ │ │ │ + */ │ │ │ │ │ + attribution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: inRange │ │ │ │ │ + * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ + * range. This is set in whenever the zoom │ │ │ │ │ + * changes. │ │ │ │ │ + */ │ │ │ │ │ + inRange: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Propery: imageSize │ │ │ │ │ + * {} For layers with a gutter, the image is larger than │ │ │ │ │ + * the tile by twice the gutter in each dimension. │ │ │ │ │ + */ │ │ │ │ │ + imageSize: null, │ │ │ │ │ + │ │ │ │ │ + // OPTIONS │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} An optional object whose properties will be set on the layer. │ │ │ │ │ + * Any of the layer properties can be set as a property of the options │ │ │ │ │ + * object and sent to the constructor when the layer is created. │ │ │ │ │ + */ │ │ │ │ │ + options: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ + */ │ │ │ │ │ + eventListeners: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: gutter │ │ │ │ │ + * {Integer} Determines the width (in pixels) of the gutter around image │ │ │ │ │ + * tiles to ignore. By setting this property to a non-zero value, │ │ │ │ │ + * images will be requested that are wider and taller than the tile │ │ │ │ │ + * size by a value of 2 x gutter. This allows artifacts of rendering │ │ │ │ │ + * at tile edges to be ignored. Set a gutter value that is equal to │ │ │ │ │ + * half the size of the widest symbol that needs to be displayed. │ │ │ │ │ + * Defaults to zero. Non-tiled layers always have zero gutter. │ │ │ │ │ + */ │ │ │ │ │ + gutter: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: projection │ │ │ │ │ + * {} or {} Specifies the projection of the layer. │ │ │ │ │ + * Can be set in the layer options. If not specified in the layer options, │ │ │ │ │ + * it is set to the default projection specified in the map, │ │ │ │ │ + * when the layer is added to the map. │ │ │ │ │ + * Projection along with default maxExtent and resolutions │ │ │ │ │ + * are set automatically with commercial baselayers in EPSG:3857, │ │ │ │ │ + * such as Google, Bing and OpenStreetMap, and do not need to be specified. │ │ │ │ │ + * Otherwise, if specifying projection, also set maxExtent, │ │ │ │ │ + * maxResolution or resolutions as appropriate. │ │ │ │ │ + * When using vector layers with strategies, layer projection should be set │ │ │ │ │ + * to the projection of the source data if that is different from the map default. │ │ │ │ │ + * │ │ │ │ │ + * Can be either a string or an object; │ │ │ │ │ + * if a string is passed, will be converted to an object when │ │ │ │ │ + * the layer is added to the map. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + projection: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: units │ │ │ │ │ + * {String} The layer map units. Defaults to null. Possible values │ │ │ │ │ + * are 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'. │ │ │ │ │ + * Normally taken from the projection. │ │ │ │ │ + * Only required if both map and layers do not define a projection, │ │ │ │ │ + * or if they define a projection which does not define units. │ │ │ │ │ + */ │ │ │ │ │ + units: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: scales │ │ │ │ │ + * {Array} An array of map scales in descending order. The values in the │ │ │ │ │ + * array correspond to the map scale denominator. Note that these │ │ │ │ │ + * values only make sense if the display (monitor) resolution of the │ │ │ │ │ + * client is correctly guessed by whomever is configuring the │ │ │ │ │ + * application. In addition, the units property must also be set. │ │ │ │ │ + * Use instead wherever possible. │ │ │ │ │ + */ │ │ │ │ │ + scales: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: resolutions │ │ │ │ │ + * {Array} A list of map resolutions (map units per pixel) in descending │ │ │ │ │ + * order. If this is not set in the layer constructor, it will be set │ │ │ │ │ + * based on other resolution related properties (maxExtent, │ │ │ │ │ + * maxResolution, maxScale, etc.). │ │ │ │ │ + */ │ │ │ │ │ + resolutions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The maximum extent for the layer. Defaults to null. │ │ │ │ │ + * │ │ │ │ │ + * The center of these bounds will not stray outside │ │ │ │ │ + * of the viewport extent during panning. In addition, if │ │ │ │ │ + * is set to false, data will not be │ │ │ │ │ + * requested that falls completely outside of these bounds. │ │ │ │ │ + */ │ │ │ │ │ + maxExtent: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minExtent │ │ │ │ │ + * {|Array} If provided as an array, the array │ │ │ │ │ + * should consist of four values (left, bottom, right, top). │ │ │ │ │ + * The minimum extent for the layer. Defaults to null. │ │ │ │ │ + */ │ │ │ │ │ + minExtent: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxResolution │ │ │ │ │ + * {Float} Default max is 360 deg / 256 px, which corresponds to │ │ │ │ │ + * zoom level 0 on gmaps. Specify a different value in the layer │ │ │ │ │ + * options if you are not using the default │ │ │ │ │ + * and displaying the whole world. │ │ │ │ │ + */ │ │ │ │ │ + maxResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minResolution │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minResolution: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} │ │ │ │ │ + */ │ │ │ │ │ + numZoomLevels: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + minScale: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ + */ │ │ │ │ │ + maxScale: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayOutsideMaxExtent │ │ │ │ │ + * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ + * extent for this layer. Defaults to false. │ │ │ │ │ + */ │ │ │ │ │ + displayOutsideMaxExtent: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: wrapDateLine │ │ │ │ │ + * {Boolean} Wraps the world at the international dateline, so the map can │ │ │ │ │ + * be panned infinitely in longitudinal direction. Only use this on the │ │ │ │ │ + * base layer, and only if the layer's maxExtent equals the world bounds. │ │ │ │ │ + * #487 for more info. │ │ │ │ │ + */ │ │ │ │ │ + wrapDateLine: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: metadata │ │ │ │ │ + * {Object} This object can be used to store additional information on a │ │ │ │ │ + * layer object. │ │ │ │ │ + */ │ │ │ │ │ + metadata: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} The layer name │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(name, options) { │ │ │ │ │ + │ │ │ │ │ + this.metadata = {}; │ │ │ │ │ + │ │ │ │ │ + options = OpenLayers.Util.extend({}, options); │ │ │ │ │ + // make sure we respect alwaysInRange if set on the prototype │ │ │ │ │ + if (this.alwaysInRange != null) { │ │ │ │ │ + options.alwaysInRange = this.alwaysInRange; │ │ │ │ │ + } │ │ │ │ │ + this.addOptions(options); │ │ │ │ │ + │ │ │ │ │ + this.name = name; │ │ │ │ │ + │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ + │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.style.width = "100%"; │ │ │ │ │ + this.div.style.height = "100%"; │ │ │ │ │ + this.div.dir = "ltr"; │ │ │ │ │ + │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Destroy is a destructor: this is to alleviate cyclic references which │ │ │ │ │ + * the Javascript garbage cleaner can not take care of on its own. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * setNewBaseLayer - {Boolean} Set a new base layer when this layer has │ │ │ │ │ + * been destroyed. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function(setNewBaseLayer) { │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ + } │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.removeLayer(this, setNewBaseLayer); │ │ │ │ │ + } │ │ │ │ │ + this.projection = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ + this.name = null; │ │ │ │ │ + this.div = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ + │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {} The layer to be cloned │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ + */ │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ + │ │ │ │ │ + // a cloned layer should never have its map property set │ │ │ │ │ + // because it has not been added to a map yet. │ │ │ │ │ + obj.map = null; │ │ │ │ │ + │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getOptions │ │ │ │ │ + * Extracts an object from the layer with the properties that were set as │ │ │ │ │ + * options, but updates them with the values currently set on the │ │ │ │ │ + * instance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} the of the layer, representing the current state. │ │ │ │ │ + */ │ │ │ │ │ + getOptions: function() { │ │ │ │ │ + var options = {}; │ │ │ │ │ + for (var o in this.options) { │ │ │ │ │ + options[o] = this[o]; │ │ │ │ │ + } │ │ │ │ │ + return options; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setName │ │ │ │ │ + * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ + * on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newName - {String} The new name. │ │ │ │ │ + */ │ │ │ │ │ + setName: function(newName) { │ │ │ │ │ + if (newName != this.name) { │ │ │ │ │ + this.name = newName; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "name" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newOptions - {Object} │ │ │ │ │ + * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ + * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ + * sure that it is displayed with a valid resolution, and a │ │ │ │ │ + * changebaselayer event will be triggered. │ │ │ │ │ + */ │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ + │ │ │ │ │ + if (this.options == null) { │ │ │ │ │ + this.options = {}; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (newOptions) { │ │ │ │ │ + // make sure this.projection references a projection object │ │ │ │ │ + if (typeof newOptions.projection == "string") { │ │ │ │ │ + newOptions.projection = new OpenLayers.Projection(newOptions.projection); │ │ │ │ │ + } │ │ │ │ │ + if (newOptions.projection) { │ │ │ │ │ + // get maxResolution, units and maxExtent from projection defaults if │ │ │ │ │ + // they are not defined already │ │ │ │ │ + OpenLayers.Util.applyDefaults(newOptions, │ │ │ │ │ + OpenLayers.Projection.defaults[newOptions.projection.getCode()]); │ │ │ │ │ + } │ │ │ │ │ + // allow array for extents │ │ │ │ │ + if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent); │ │ │ │ │ + } │ │ │ │ │ + if (newOptions.minExtent && !(newOptions.minExtent instanceof OpenLayers.Bounds)) { │ │ │ │ │ + newOptions.minExtent = new OpenLayers.Bounds(newOptions.minExtent); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // update our copy for clone │ │ │ │ │ + OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ + │ │ │ │ │ + // add new options to this │ │ │ │ │ + OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ + │ │ │ │ │ + // get the units from the projection, if we have a projection │ │ │ │ │ + // and it it has units │ │ │ │ │ + if (this.projection && this.projection.getUnits()) { │ │ │ │ │ + this.units = this.projection.getUnits(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // re-initialize resolutions if necessary, i.e. if any of the │ │ │ │ │ + // properties of the "properties" array defined below is set │ │ │ │ │ + // in the new options │ │ │ │ │ + if (this.map) { │ │ │ │ │ + // store current resolution so we can try to restore it later │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ + var properties = this.RESOLUTION_PROPERTIES.concat( │ │ │ │ │ + ["projection", "units", "minExtent", "maxExtent"] │ │ │ │ │ + ); │ │ │ │ │ + for (var o in newOptions) { │ │ │ │ │ + if (newOptions.hasOwnProperty(o) && │ │ │ │ │ + OpenLayers.Util.indexOf(properties, o) >= 0) { │ │ │ │ │ + │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ + if (reinitialize && this.map.baseLayer === this) { │ │ │ │ │ + // update map position, and restore previous resolution │ │ │ │ │ + this.map.setCenter(this.map.getCenter(), │ │ │ │ │ + this.map.getZoomForResolution(resolution), │ │ │ │ │ + false, true │ │ │ │ │ + ); │ │ │ │ │ + // trigger a changebaselayer event to make sure that │ │ │ │ │ + // all controls (especially │ │ │ │ │ + // OpenLayers.Control.PanZoomBar) get notified of the │ │ │ │ │ + // new options │ │ │ │ │ + this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: onMapResize │ │ │ │ │ + * This function can be implemented by subclasses │ │ │ │ │ + */ │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + //this function can be implemented by subclasses │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ + */ │ │ │ │ │ + redraw: function() { │ │ │ │ │ + var redrawn = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + │ │ │ │ │ + // min/max Range may have changed │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ + │ │ │ │ │ + // map's center might not yet be set │ │ │ │ │ + var extent = this.getExtent(); │ │ │ │ │ + │ │ │ │ │ + if (extent && this.inRange && this.visibility) { │ │ │ │ │ + var zoomChanged = true; │ │ │ │ │ + this.moveTo(extent, zoomChanged, false); │ │ │ │ │ + this.events.triggerEvent("moveend", { │ │ │ │ │ + "zoomChanged": zoomChanged │ │ │ │ │ + }); │ │ │ │ │ + redrawn = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return redrawn; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ + * do some init work in that case. │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ + var display = this.visibility; │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + display = display && this.inRange; │ │ │ │ │ + } │ │ │ │ │ + this.display(display); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ + * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ + */ │ │ │ │ │ + moveByPx: function(dx, dy) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the layer. This is done through an accessor │ │ │ │ │ + * so that subclasses can override this and take special action once │ │ │ │ │ + * they have their map variable set. │ │ │ │ │ + * │ │ │ │ │ + * Here we take care to bring over any of the necessary default │ │ │ │ │ + * properties from the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + if (this.map == null) { │ │ │ │ │ + │ │ │ │ │ + this.map = map; │ │ │ │ │ + │ │ │ │ │ + // grab some essential layer data from the map if it hasn't already │ │ │ │ │ + // been set │ │ │ │ │ + this.maxExtent = this.maxExtent || this.map.maxExtent; │ │ │ │ │ + this.minExtent = this.minExtent || this.map.minExtent; │ │ │ │ │ + │ │ │ │ │ + this.projection = this.projection || this.map.projection; │ │ │ │ │ + if (typeof this.projection == "string") { │ │ │ │ │ + this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // Check the projection to see if we can get units -- if not, refer │ │ │ │ │ + // to properties. │ │ │ │ │ + this.units = this.projection.getUnits() || │ │ │ │ │ + this.units || this.map.units; │ │ │ │ │ + │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ + │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ + var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ + this.div.style.display = show ? "" : "none"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // deal with gutters │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: afterAdd │ │ │ │ │ + * Called at the end of the map.addLayer sequence. At this point, the map │ │ │ │ │ + * will have a base layer. To be overridden by subclasses. │ │ │ │ │ + */ │ │ │ │ │ + afterAdd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removeMap │ │ │ │ │ + * Just as setMap() allows each layer the possibility to take a │ │ │ │ │ + * personalized action on being added to the map, removeMap() allows │ │ │ │ │ + * each layer to take a personalized action on being removed from it. │ │ │ │ │ + * For now, this will be mostly unused, except for the EventPane layer, │ │ │ │ │ + * which needs this hook so that it can remove the special invisible │ │ │ │ │ + * pane. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + //to be overridden by subclasses │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getImageSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} optional tile bounds, can be used │ │ │ │ │ + * by subclasses that have to deal with different tile sizes at the │ │ │ │ │ + * layer extent edges (e.g. Zoomify) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The size that the image should be, taking into │ │ │ │ │ + * account gutters. │ │ │ │ │ + */ │ │ │ │ │ + getImageSize: function(bounds) { │ │ │ │ │ + return (this.imageSize || this.tileSize); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setTileSize │ │ │ │ │ + * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ + * or use by Tile.Image. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {} │ │ │ │ │ + */ │ │ │ │ │ + setTileSize: function(size) { │ │ │ │ │ + var tileSize = (size) ? size : │ │ │ │ │ + ((this.tileSize) ? this.tileSize : │ │ │ │ │ + this.map.getTileSize()); │ │ │ │ │ + this.tileSize = tileSize; │ │ │ │ │ + if (this.gutter) { │ │ │ │ │ + // layers with gutters need non-null tile sizes │ │ │ │ │ + //if(tileSize == null) { │ │ │ │ │ + // OpenLayers.console.error("Error in layer.setMap() for " + │ │ │ │ │ + // this.name + ": layers with " + │ │ │ │ │ + // "gutters need non-null tile sizes"); │ │ │ │ │ + //} │ │ │ │ │ + this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter), │ │ │ │ │ + tileSize.h + (2 * this.gutter)); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getVisibility │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ + */ │ │ │ │ │ + getVisibility: function() { │ │ │ │ │ + return this.visibility; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setVisibility │ │ │ │ │ + * Set the visibility flag for the layer and hide/show & redraw │ │ │ │ │ + * accordingly. Fire event unless otherwise specified │ │ │ │ │ + * │ │ │ │ │ + * Note that visibility is no longer simply whether or not the layer's │ │ │ │ │ + * style.display is set to "block". Now we store a 'visibility' state │ │ │ │ │ + * property on the layer class, this allows us to remember whether or │ │ │ │ │ + * not we *desire* for a layer to be visible. In the case where the │ │ │ │ │ + * map's resolution is out of the layer's range, this desire may be │ │ │ │ │ + * subverted. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * visibility - {Boolean} Whether or not to display the layer (if in range) │ │ │ │ │ + */ │ │ │ │ │ + setVisibility: function(visibility) { │ │ │ │ │ + if (visibility != this.visibility) { │ │ │ │ │ + this.visibility = visibility; │ │ │ │ │ + this.display(visibility); │ │ │ │ │ + this.redraw(); │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "visibility" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("visibilitychanged"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: display │ │ │ │ │ + * Hide or show the Layer. This is designed to be used internally, and │ │ │ │ │ + * is not generally the way to enable or disable the layer. For that, │ │ │ │ │ + * use the setVisibility function instead.. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + if (display != (this.div.style.display != "none")) { │ │ │ │ │ + this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateInRange │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer is displayable at the current map's current │ │ │ │ │ + * resolution. Note that if 'alwaysInRange' is true for the layer, │ │ │ │ │ + * this function will always return true. │ │ │ │ │ + */ │ │ │ │ │ + calculateInRange: function() { │ │ │ │ │ + var inRange = false; │ │ │ │ │ + │ │ │ │ │ + if (this.alwaysInRange) { │ │ │ │ │ + inRange = true; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ + inRange = ((resolution >= this.minResolution) && │ │ │ │ │ + (resolution <= this.maxResolution)); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return inRange; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setIsBaseLayer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * isBaseLayer - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + setIsBaseLayer: function(isBaseLayer) { │ │ │ │ │ + if (isBaseLayer != this.isBaseLayer) { │ │ │ │ │ + this.isBaseLayer = isBaseLayer; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Baselayer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: initResolutions │ │ │ │ │ + * This method's responsibility is to set up the 'resolutions' array │ │ │ │ │ + * for the layer -- this array is what the layer will use to interface │ │ │ │ │ + * between the zoom levels of the map and the resolution display │ │ │ │ │ + * of the layer. │ │ │ │ │ + * │ │ │ │ │ + * The user has several options that determine how the array is set up. │ │ │ │ │ + * │ │ │ │ │ + * For a detailed explanation, see the following wiki from the │ │ │ │ │ + * openlayers.org homepage: │ │ │ │ │ + * http://trac.openlayers.org/wiki/SettingZoomLevels │ │ │ │ │ + */ │ │ │ │ │ + initResolutions: function() { │ │ │ │ │ + │ │ │ │ │ + // ok we want resolutions, here's our strategy: │ │ │ │ │ + // │ │ │ │ │ + // 1. if resolutions are defined in the layer config, use them │ │ │ │ │ + // 2. else, if scales are defined in the layer config then derive │ │ │ │ │ + // resolutions from these scales │ │ │ │ │ + // 3. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ + // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ + // layer config │ │ │ │ │ + // 4. if we still don't have resolutions, and if resolutions │ │ │ │ │ + // are defined in the same, use them │ │ │ │ │ + // 5. else, if scales are defined in the map then derive │ │ │ │ │ + // resolutions from these scales │ │ │ │ │ + // 6. else, attempt to calculate resolutions from maxResolution, │ │ │ │ │ + // minResolution, numZoomLevels, maxZoomLevel set in the │ │ │ │ │ + // map │ │ │ │ │ + // 7. hope for the best! │ │ │ │ │ + │ │ │ │ │ + var i, len, p; │ │ │ │ │ + var props = {}, │ │ │ │ │ + alwaysInRange = true; │ │ │ │ │ + │ │ │ │ │ + // get resolution data from layer config │ │ │ │ │ + // (we also set alwaysInRange in the layer as appropriate) │ │ │ │ │ + for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ + p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ + props[p] = this.options[p]; │ │ │ │ │ + if (alwaysInRange && this.options[p]) { │ │ │ │ │ + alwaysInRange = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.options.alwaysInRange == null) { │ │ │ │ │ + this.alwaysInRange = alwaysInRange; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if we don't have resolutions then attempt to derive them from scales │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if we couldn't calculate resolutions then we look at we have │ │ │ │ │ + // in the map │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + for (i = 0, len = this.RESOLUTION_PROPERTIES.length; i < len; i++) { │ │ │ │ │ + p = this.RESOLUTION_PROPERTIES[i]; │ │ │ │ │ + props[p] = this.options[p] != null ? │ │ │ │ │ + this.options[p] : this.map[p]; │ │ │ │ │ + } │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ + } │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // ok, we new need to set properties in the instance │ │ │ │ │ + │ │ │ │ │ + // get maxResolution from the config if it's defined there │ │ │ │ │ + var maxResolution; │ │ │ │ │ + if (this.options.maxResolution && │ │ │ │ │ + this.options.maxResolution !== "auto") { │ │ │ │ │ + maxResolution = this.options.maxResolution; │ │ │ │ │ + } │ │ │ │ │ + if (this.options.minScale) { │ │ │ │ │ + maxResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.options.minScale, this.units); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // get minResolution from the config if it's defined there │ │ │ │ │ + var minResolution; │ │ │ │ │ + if (this.options.minResolution && │ │ │ │ │ + this.options.minResolution !== "auto") { │ │ │ │ │ + minResolution = this.options.minResolution; │ │ │ │ │ + } │ │ │ │ │ + if (this.options.maxScale) { │ │ │ │ │ + minResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.options.maxScale, this.units); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (props.resolutions) { │ │ │ │ │ + │ │ │ │ │ + //sort resolutions array descendingly │ │ │ │ │ + props.resolutions.sort(function(a, b) { │ │ │ │ │ + return (b - a); │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + // if we still don't have a maxResolution get it from the │ │ │ │ │ + // resolutions array │ │ │ │ │ + if (!maxResolution) { │ │ │ │ │ + maxResolution = props.resolutions[0]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if we still don't have a minResolution get it from the │ │ │ │ │ + // resolutions array │ │ │ │ │ + if (!minResolution) { │ │ │ │ │ + var lastIdx = props.resolutions.length - 1; │ │ │ │ │ + minResolution = props.resolutions[lastIdx]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.resolutions = props.resolutions; │ │ │ │ │ + if (this.resolutions) { │ │ │ │ │ + len = this.resolutions.length; │ │ │ │ │ + this.scales = new Array(len); │ │ │ │ │ + for (i = 0; i < len; i++) { │ │ │ │ │ + this.scales[i] = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + this.resolutions[i], this.units); │ │ │ │ │ + } │ │ │ │ │ + this.numZoomLevels = len; │ │ │ │ │ + } │ │ │ │ │ + this.minResolution = minResolution; │ │ │ │ │ + if (minResolution) { │ │ │ │ │ + this.maxScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + minResolution, this.units); │ │ │ │ │ + } │ │ │ │ │ + this.maxResolution = maxResolution; │ │ │ │ │ + if (maxResolution) { │ │ │ │ │ + this.minScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ + maxResolution, this.units); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: resolutionsFromScales │ │ │ │ │ + * Derive resolutions from scales. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scales - {Array(Number)} Scales │ │ │ │ │ + * │ │ │ │ │ + * Returns │ │ │ │ │ + * {Array(Number)} Resolutions │ │ │ │ │ + */ │ │ │ │ │ + resolutionsFromScales: function(scales) { │ │ │ │ │ + if (scales == null) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + var resolutions, i, len; │ │ │ │ │ + len = scales.length; │ │ │ │ │ + resolutions = new Array(len); │ │ │ │ │ + for (i = 0; i < len; i++) { │ │ │ │ │ + resolutions[i] = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + scales[i], this.units); │ │ │ │ │ + } │ │ │ │ │ + return resolutions; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateResolutions │ │ │ │ │ + * Calculate resolutions based on the provided properties. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * props - {Object} Properties │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array({Number})} Array of resolutions. │ │ │ │ │ + */ │ │ │ │ │ + calculateResolutions: function(props) { │ │ │ │ │ + │ │ │ │ │ + var viewSize, wRes, hRes; │ │ │ │ │ + │ │ │ │ │ + // determine maxResolution │ │ │ │ │ + var maxResolution = props.maxResolution; │ │ │ │ │ + if (props.minScale != null) { │ │ │ │ │ + maxResolution = │ │ │ │ │ + OpenLayers.Util.getResolutionFromScale(props.minScale, │ │ │ │ │ + this.units); │ │ │ │ │ + } else if (maxResolution == "auto" && this.maxExtent != null) { │ │ │ │ │ + viewSize = this.map.getSize(); │ │ │ │ │ + wRes = this.maxExtent.getWidth() / viewSize.w; │ │ │ │ │ + hRes = this.maxExtent.getHeight() / viewSize.h; │ │ │ │ │ + maxResolution = Math.max(wRes, hRes); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // determine minResolution │ │ │ │ │ + var minResolution = props.minResolution; │ │ │ │ │ + if (props.maxScale != null) { │ │ │ │ │ + minResolution = │ │ │ │ │ + OpenLayers.Util.getResolutionFromScale(props.maxScale, │ │ │ │ │ + this.units); │ │ │ │ │ + } else if (props.minResolution == "auto" && this.minExtent != null) { │ │ │ │ │ + viewSize = this.map.getSize(); │ │ │ │ │ + wRes = this.minExtent.getWidth() / viewSize.w; │ │ │ │ │ + hRes = this.minExtent.getHeight() / viewSize.h; │ │ │ │ │ + minResolution = Math.max(wRes, hRes); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (typeof maxResolution !== "number" && │ │ │ │ │ + typeof minResolution !== "number" && │ │ │ │ │ + this.maxExtent != null) { │ │ │ │ │ + // maxResolution for default grid sets assumes that at zoom │ │ │ │ │ + // level zero, the whole world fits on one tile. │ │ │ │ │ + var tileSize = this.map.getTileSize(); │ │ │ │ │ + maxResolution = Math.max( │ │ │ │ │ + this.maxExtent.getWidth() / tileSize.w, │ │ │ │ │ + this.maxExtent.getHeight() / tileSize.h │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // determine numZoomLevels │ │ │ │ │ + var maxZoomLevel = props.maxZoomLevel; │ │ │ │ │ + var numZoomLevels = props.numZoomLevels; │ │ │ │ │ + if (typeof minResolution === "number" && │ │ │ │ │ + typeof maxResolution === "number" && numZoomLevels === undefined) { │ │ │ │ │ + var ratio = maxResolution / minResolution; │ │ │ │ │ + numZoomLevels = Math.floor(Math.log(ratio) / Math.log(2)) + 1; │ │ │ │ │ + } else if (numZoomLevels === undefined && maxZoomLevel != null) { │ │ │ │ │ + numZoomLevels = maxZoomLevel + 1; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // are we able to calculate resolutions? │ │ │ │ │ + if (typeof numZoomLevels !== "number" || numZoomLevels <= 0 || │ │ │ │ │ + (typeof maxResolution !== "number" && │ │ │ │ │ + typeof minResolution !== "number")) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // now we have numZoomLevels and at least one of maxResolution │ │ │ │ │ + // or minResolution, we can populate the resolutions array │ │ │ │ │ + │ │ │ │ │ + var resolutions = new Array(numZoomLevels); │ │ │ │ │ + var base = 2; │ │ │ │ │ + if (typeof minResolution == "number" && │ │ │ │ │ + typeof maxResolution == "number") { │ │ │ │ │ + // if maxResolution and minResolution are set, we calculate │ │ │ │ │ + // the base for exponential scaling that starts at │ │ │ │ │ + // maxResolution and ends at minResolution in numZoomLevels │ │ │ │ │ + // steps. │ │ │ │ │ + base = Math.pow( │ │ │ │ │ + (maxResolution / minResolution), │ │ │ │ │ + (1 / (numZoomLevels - 1)) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var i; │ │ │ │ │ + if (typeof maxResolution === "number") { │ │ │ │ │ + for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ + resolutions[i] = maxResolution / Math.pow(base, i); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + for (i = 0; i < numZoomLevels; i++) { │ │ │ │ │ + resolutions[numZoomLevels - 1 - i] = │ │ │ │ │ + minResolution * Math.pow(base, i); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return resolutions; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getResolution │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ + * resolutions array, indexed by current zoom level. │ │ │ │ │ + */ │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + var zoom = this.map.getZoom(); │ │ │ │ │ + return this.getResolutionForZoom(zoom); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ + */ │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ + // means it will user map's current center & resolution │ │ │ │ │ + // │ │ │ │ │ + return this.map.calculateBounds(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getZoomForExtent │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * extent - {} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ + * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ + * not exactly contain the entire extent. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ + * for the passed-in extent. We do this by calculating the ideal │ │ │ │ │ + * resolution for the given extent (based on the map size) and then │ │ │ │ │ + * calling getZoomForResolution(), passing along the 'closest' │ │ │ │ │ + * parameter. │ │ │ │ │ + */ │ │ │ │ │ + getZoomForExtent: function(extent, closest) { │ │ │ │ │ + var viewSize = this.map.getSize(); │ │ │ │ │ + var idealResolution = Math.max(extent.getWidth() / viewSize.w, │ │ │ │ │ + extent.getHeight() / viewSize.h); │ │ │ │ │ + │ │ │ │ │ + return this.getZoomForResolution(idealResolution, closest); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getDataExtent │ │ │ │ │ + * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ + * This function is to be implemented by subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getDataExtent: function() { │ │ │ │ │ + //to be implemented by subclasses │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ */ │ │ │ │ │ getResolutionForZoom: function(zoom) { │ │ │ │ │ zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1)); │ │ │ │ │ var resolution; │ │ │ │ │ if (this.map.fractionalZoom) { │ │ │ │ │ var low = Math.floor(zoom); │ │ │ │ │ var high = Math.ceil(zoom); │ │ │ │ │ @@ -26070,14 +25952,1262 @@ │ │ │ │ │ } │ │ │ │ │ return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Icon.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Icon │ │ │ │ │ + * │ │ │ │ │ + * The icon represents a graphical icon on the screen. Typically used in │ │ │ │ │ + * conjunction with a to represent markers on a screen. │ │ │ │ │ + * │ │ │ │ │ + * An icon has a url, size and position. It also contains an offset which │ │ │ │ │ + * allows the center point to be represented correctly. This can be │ │ │ │ │ + * provided either as a fixed offset or a function provided to calculate │ │ │ │ │ + * the desired offset. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} image url │ │ │ │ │ + */ │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ + */ │ │ │ │ │ + size: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: offset │ │ │ │ │ + * {|Object} distance in pixels to offset the │ │ │ │ │ + * image when being rendered. An OpenLayers.Pixel or an object │ │ │ │ │ + * with a 'x' and 'y' properties. │ │ │ │ │ + */ │ │ │ │ │ + offset: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: calculateOffset │ │ │ │ │ + * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ + */ │ │ │ │ │ + calculateOffset: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: imageDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + imageDiv: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: px │ │ │ │ │ + * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ + * with a 'x' and 'y' properties. │ │ │ │ │ + */ │ │ │ │ │ + px: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Icon │ │ │ │ │ + * Creates an icon, which is an image tag in a div. │ │ │ │ │ + * │ │ │ │ │ + * url - {String} │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or an │ │ │ │ │ + * object with a 'w' and 'h' │ │ │ │ │ + * properties. │ │ │ │ │ + * offset - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ + * object with a 'x' and 'y' │ │ │ │ │ + * properties. │ │ │ │ │ + * calculateOffset - {Function} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(url, size, offset, calculateOffset) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + this.size = size || { │ │ │ │ │ + w: 20, │ │ │ │ │ + h: 20 │ │ │ │ │ + }; │ │ │ │ │ + this.offset = offset || { │ │ │ │ │ + x: -(this.size.w / 2), │ │ │ │ │ + y: -(this.size.h / 2) │ │ │ │ │ + }; │ │ │ │ │ + this.calculateOffset = calculateOffset; │ │ │ │ │ + │ │ │ │ │ + var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ + this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Nullify references and remove event listeners to prevent circular │ │ │ │ │ + * references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // erase any drawn elements │ │ │ │ │ + this.erase(); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ + this.imageDiv.innerHTML = ""; │ │ │ │ │ + this.imageDiv = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A fresh copy of the icon. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Icon(this.url, │ │ │ │ │ + this.size, │ │ │ │ │ + this.offset, │ │ │ │ │ + this.calculateOffset); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ + */ │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + if (size != null) { │ │ │ │ │ + this.size = size; │ │ │ │ │ + } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * url - {String} │ │ │ │ │ + */ │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + if (url != null) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Move the div to the given pixel. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} An OpenLayers.Pixel or an │ │ │ │ │ + * object with a 'x' and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A new DOM Image of this icon set at the location passed-in │ │ │ │ │ + */ │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + this.size, │ │ │ │ │ + this.url, │ │ │ │ │ + "absolute"); │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + return this.imageDiv; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erase the underlying image element. │ │ │ │ │ + */ │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ + OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the icon's opacity │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * opacity - {float} │ │ │ │ │ + */ │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ + null, null, null, null, opacity); │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * move icon to passed in px. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + //if no px passed in, use stored location │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.px = px; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.imageDiv != null) { │ │ │ │ │ + if (this.px == null) { │ │ │ │ │ + this.display(false); │ │ │ │ │ + } else { │ │ │ │ │ + if (this.calculateOffset) { │ │ │ │ │ + this.offset = this.calculateOffset(this.size); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { │ │ │ │ │ + x: this.px.x + this.offset.x, │ │ │ │ │ + y: this.px.y + this.offset.y │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ + */ │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + // nodeType 11 for ie, whose nodes *always* have a parentNode │ │ │ │ │ + // (of type document fragment) │ │ │ │ │ + var isDrawn = (this.imageDiv && this.imageDiv.parentNode && │ │ │ │ │ + (this.imageDiv.parentNode.nodeType != 11)); │ │ │ │ │ + │ │ │ │ │ + return isDrawn; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Marker.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Icon.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Marker │ │ │ │ │ + * Instances of OpenLayers.Marker are a combination of a │ │ │ │ │ + * and an . │ │ │ │ │ + * │ │ │ │ │ + * Markers are generally added to a special layer called │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * var markers = new OpenLayers.Layer.Markers( "Markers" ); │ │ │ │ │ + * map.addLayer(markers); │ │ │ │ │ + * │ │ │ │ │ + * var size = new OpenLayers.Size(21,25); │ │ │ │ │ + * var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); │ │ │ │ │ + * var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset); │ │ │ │ │ + * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon)); │ │ │ │ │ + * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone())); │ │ │ │ │ + * │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Note that if you pass an icon into the Marker constructor, it will take │ │ │ │ │ + * that icon and use it. This means that you should not share icons between │ │ │ │ │ + * markers -- you use them once, but you should clone() for any additional │ │ │ │ │ + * markers using that same icon. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: icon │ │ │ │ │ + * {} The icon used by this marker. │ │ │ │ │ + */ │ │ │ │ │ + icon: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} location of object │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} the event handler. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} the map this marker is attached to │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Marker │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {} the position of this marker │ │ │ │ │ + * icon - {} the icon for this marker │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ + * Destroy the marker. You must first remove the marker from any │ │ │ │ │ + * layer which it has been added to, or you will get buggy behavior. │ │ │ │ │ + * (This can not be done within the marker since the marker does not │ │ │ │ │ + * know which layer it is attached to.) │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // erase any drawn features │ │ │ │ │ + this.erase(); │ │ │ │ │ + │ │ │ │ │ + this.map = null; │ │ │ │ │ + │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.destroy(); │ │ │ │ │ + this.icon = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Calls draw on the icon, and returns that output. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ + * location passed-in │ │ │ │ │ + */ │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + return this.icon.draw(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erases any drawn elements for this marker. │ │ │ │ │ + */ │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.erase(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Move the marker to the new location. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.icon != null)) { │ │ │ │ │ + this.icon.moveTo(px); │ │ │ │ │ + } │ │ │ │ │ + this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ + */ │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ + return isDrawn; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: onScreen │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ + */ │ │ │ │ │ + onScreen: function() { │ │ │ │ │ + │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var screenBounds = this.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ + } │ │ │ │ │ + return onScreen; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: inflate │ │ │ │ │ + * Englarges the markers icon by the specified ratio. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ + * will double the size). │ │ │ │ │ + */ │ │ │ │ │ + inflate: function(inflate) { │ │ │ │ │ + if (this.icon) { │ │ │ │ │ + this.icon.setSize({ │ │ │ │ │ + w: this.icon.size.w * inflate, │ │ │ │ │ + h: this.icon.size.h * inflate │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the opacity of the marker by changin the opacity of │ │ │ │ │ + * its icon │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ + */ │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + this.icon.setOpacity(opacity); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * Change URL of the Icon Image. │ │ │ │ │ + * │ │ │ │ │ + * url - {String} │ │ │ │ │ + */ │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + this.icon.setUrl(url); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ + * │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.icon.display(display); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Marker" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Function: defaultIcon │ │ │ │ │ + * Creates a default . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A default OpenLayers.Icon to use for a marker │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Marker.defaultIcon = function() { │ │ │ │ │ + return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"), { │ │ │ │ │ + w: 21, │ │ │ │ │ + h: 25 │ │ │ │ │ + }, { │ │ │ │ │ + x: -10.5, │ │ │ │ │ + y: -25 │ │ │ │ │ + }); │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/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/Format/WPSDescribeProcess.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ + * @requires OpenLayers/Format/OWSCommon/v1_1_0.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * Read WPS DescribeProcess responses. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.XML, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + wps: "http://www.opengis.net/wps/1.0.0", │ │ │ │ │ + ows: "http://www.opengis.net/ows/1.1", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + */ │ │ │ │ │ + defaultPrefix: "wps", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ + */ │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WPSDescribeProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Parse a WPS DescribeProcess and return an object with its information. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + read: function(data) { │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + if (data && data.nodeType == 9) { │ │ │ │ │ + data = data.documentElement; │ │ │ │ │ + } │ │ │ │ │ + var info = {}; │ │ │ │ │ + this.readNode(data, info); │ │ │ │ │ + return info; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: readers │ │ │ │ │ + * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ + * be applied when a namespaced node is found matching the function │ │ │ │ │ + * name. The function will be applied in the scope of this parser │ │ │ │ │ + * with two arguments: the node being read and a context object passed │ │ │ │ │ + * from the parent. │ │ │ │ │ + */ │ │ │ │ │ + readers: { │ │ │ │ │ + "wps": { │ │ │ │ │ + "ProcessDescriptions": function(node, obj) { │ │ │ │ │ + obj.processDescriptions = {}; │ │ │ │ │ + this.readChildNodes(node, obj.processDescriptions); │ │ │ │ │ + }, │ │ │ │ │ + "ProcessDescription": function(node, processDescriptions) { │ │ │ │ │ + var processVersion = this.getAttributeNS(node, this.namespaces.wps, "processVersion"); │ │ │ │ │ + var processDescription = { │ │ │ │ │ + processVersion: processVersion, │ │ │ │ │ + statusSupported: (node.getAttribute("statusSupported") === "true"), │ │ │ │ │ + storeSupported: (node.getAttribute("storeSupported") === "true") │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, processDescription); │ │ │ │ │ + processDescriptions[processDescription.identifier] = processDescription; │ │ │ │ │ + }, │ │ │ │ │ + "DataInputs": function(node, processDescription) { │ │ │ │ │ + processDescription.dataInputs = []; │ │ │ │ │ + this.readChildNodes(node, processDescription.dataInputs); │ │ │ │ │ + }, │ │ │ │ │ + "ProcessOutputs": function(node, processDescription) { │ │ │ │ │ + processDescription.processOutputs = []; │ │ │ │ │ + this.readChildNodes(node, processDescription.processOutputs); │ │ │ │ │ + }, │ │ │ │ │ + "Output": function(node, processOutputs) { │ │ │ │ │ + var output = {}; │ │ │ │ │ + this.readChildNodes(node, output); │ │ │ │ │ + processOutputs.push(output); │ │ │ │ │ + }, │ │ │ │ │ + "ComplexOutput": function(node, output) { │ │ │ │ │ + output.complexOutput = {}; │ │ │ │ │ + this.readChildNodes(node, output.complexOutput); │ │ │ │ │ + }, │ │ │ │ │ + "LiteralOutput": function(node, output) { │ │ │ │ │ + output.literalOutput = {}; │ │ │ │ │ + this.readChildNodes(node, output.literalOutput); │ │ │ │ │ + }, │ │ │ │ │ + "Input": function(node, dataInputs) { │ │ │ │ │ + var input = { │ │ │ │ │ + maxOccurs: parseInt(node.getAttribute("maxOccurs")), │ │ │ │ │ + minOccurs: parseInt(node.getAttribute("minOccurs")) │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, input); │ │ │ │ │ + dataInputs.push(input); │ │ │ │ │ + }, │ │ │ │ │ + "BoundingBoxData": function(node, input) { │ │ │ │ │ + input.boundingBoxData = {}; │ │ │ │ │ + this.readChildNodes(node, input.boundingBoxData); │ │ │ │ │ + }, │ │ │ │ │ + "CRS": function(node, obj) { │ │ │ │ │ + if (!obj.CRSs) { │ │ │ │ │ + obj.CRSs = {}; │ │ │ │ │ + } │ │ │ │ │ + obj.CRSs[this.getChildValue(node)] = true; │ │ │ │ │ + }, │ │ │ │ │ + "LiteralData": function(node, input) { │ │ │ │ │ + input.literalData = {}; │ │ │ │ │ + this.readChildNodes(node, input.literalData); │ │ │ │ │ + }, │ │ │ │ │ + "ComplexData": function(node, input) { │ │ │ │ │ + input.complexData = {}; │ │ │ │ │ + this.readChildNodes(node, input.complexData); │ │ │ │ │ + }, │ │ │ │ │ + "Default": function(node, complexData) { │ │ │ │ │ + complexData["default"] = {}; │ │ │ │ │ + this.readChildNodes(node, complexData["default"]); │ │ │ │ │ + }, │ │ │ │ │ + "Supported": function(node, complexData) { │ │ │ │ │ + complexData["supported"] = {}; │ │ │ │ │ + this.readChildNodes(node, complexData["supported"]); │ │ │ │ │ + }, │ │ │ │ │ + "Format": function(node, obj) { │ │ │ │ │ + var format = {}; │ │ │ │ │ + this.readChildNodes(node, format); │ │ │ │ │ + if (!obj.formats) { │ │ │ │ │ + obj.formats = {}; │ │ │ │ │ + } │ │ │ │ │ + obj.formats[format.mimeType] = true; │ │ │ │ │ + }, │ │ │ │ │ + "MimeType": function(node, format) { │ │ │ │ │ + format.mimeType = this.getChildValue(node); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"] │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess" │ │ │ │ │ + │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/WPSClient.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/WPSProcess.js │ │ │ │ │ + * @requires OpenLayers/Format/WPSDescribeProcess.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.WPSClient │ │ │ │ │ + * High level API for interaction with Web Processing Services (WPS). │ │ │ │ │ + * An instance is used to create │ │ │ │ │ + * instances for servers known to the WPSClient. The WPSClient also caches │ │ │ │ │ + * DescribeProcess responses to reduce the number of requests sent to servers │ │ │ │ │ + * when processes are created. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.WPSClient = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: servers │ │ │ │ │ + * {Object} Service metadata, keyed by a local identifier. │ │ │ │ │ + * │ │ │ │ │ + * Properties: │ │ │ │ │ + * url - {String} the url of the server │ │ │ │ │ + * version - {String} WPS version of the server │ │ │ │ │ + * processDescription - {Object} Cache of raw DescribeProcess │ │ │ │ │ + * responses, keyed by process identifier. │ │ │ │ │ + */ │ │ │ │ │ + servers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: version │ │ │ │ │ + * {String} The default WPS version to use if none is configured. Default │ │ │ │ │ + * is '1.0.0'. │ │ │ │ │ + */ │ │ │ │ │ + version: '1.0.0', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: lazy │ │ │ │ │ + * {Boolean} Should the DescribeProcess be deferred until a process is │ │ │ │ │ + * fully configured? Default is false. │ │ │ │ │ + */ │ │ │ │ │ + lazy: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: events │ │ │ │ │ + * {} │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * describeprocess - Fires when the process description is available. │ │ │ │ │ + * Listeners receive an object with a 'raw' property holding the raw │ │ │ │ │ + * DescribeProcess response, and an 'identifier' property holding the │ │ │ │ │ + * process identifier of the described process. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.WPSClient │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Object whose properties will be set on the instance. │ │ │ │ │ + * │ │ │ │ │ + * Avaliable options: │ │ │ │ │ + * servers - {Object} Mandatory. Service metadata, keyed by a local │ │ │ │ │ + * identifier. Can either be a string with the service url or an │ │ │ │ │ + * object literal with additional metadata: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * servers: { │ │ │ │ │ + * local: '/geoserver/wps' │ │ │ │ │ + * }, { │ │ │ │ │ + * opengeo: { │ │ │ │ │ + * url: 'http://demo.opengeo.org/geoserver/wps', │ │ │ │ │ + * version: '1.0.0' │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * lazy - {Boolean} Optional. Set to true if DescribeProcess should not be │ │ │ │ │ + * requested until a process is fully configured. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + this.servers = {}; │ │ │ │ │ + for (var s in options.servers) { │ │ │ │ │ + this.servers[s] = typeof options.servers[s] == 'string' ? { │ │ │ │ │ + url: options.servers[s], │ │ │ │ │ + version: this.version, │ │ │ │ │ + processDescription: {} │ │ │ │ │ + } : options.servers[s]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: execute │ │ │ │ │ + * Shortcut to execute a process with a single function call. This is │ │ │ │ │ + * equivalent to using and then calling execute on the │ │ │ │ │ + * process. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Options for the execute operation. │ │ │ │ │ + * │ │ │ │ │ + * Available options: │ │ │ │ │ + * server - {String} Mandatory. One of the local identifiers of the │ │ │ │ │ + * configured servers. │ │ │ │ │ + * process - {String} Mandatory. A process identifier known to the │ │ │ │ │ + * server. │ │ │ │ │ + * inputs - {Object} The inputs for the process, keyed by input identifier. │ │ │ │ │ + * For spatial data inputs, the value of an input is usually an │ │ │ │ │ + * , an or an array of │ │ │ │ │ + * geometries or features. │ │ │ │ │ + * output - {String} The identifier of an output to parse. Optional. If not │ │ │ │ │ + * provided, the first output will be parsed. │ │ │ │ │ + * success - {Function} Callback to call when the process is complete. │ │ │ │ │ + * This function is called with an outputs object as argument, which │ │ │ │ │ + * will have a property with the identifier of the requested output │ │ │ │ │ + * (e.g. 'result'). For processes that generate spatial output, the │ │ │ │ │ + * value will either be a single or an │ │ │ │ │ + * array of features. │ │ │ │ │ + * scope - {Object} Optional scope for the success callback. │ │ │ │ │ + */ │ │ │ │ │ + execute: function(options) { │ │ │ │ │ + var process = this.getProcess(options.server, options.process); │ │ │ │ │ + process.execute({ │ │ │ │ │ + inputs: options.inputs, │ │ │ │ │ + success: options.success, │ │ │ │ │ + scope: options.scope │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getProcess │ │ │ │ │ + * Creates an . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * serverID - {String} Local identifier from the servers that this instance │ │ │ │ │ + * was constructed with. │ │ │ │ │ + * processID - {String} Process identifier known to the server. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getProcess: function(serverID, processID) { │ │ │ │ │ + var process = new OpenLayers.WPSProcess({ │ │ │ │ │ + client: this, │ │ │ │ │ + server: serverID, │ │ │ │ │ + identifier: processID │ │ │ │ │ + }); │ │ │ │ │ + if (!this.lazy) { │ │ │ │ │ + process.describe(); │ │ │ │ │ + } │ │ │ │ │ + return process; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: describeProcess │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * serverID - {String} Identifier of the server │ │ │ │ │ + * processID - {String} Identifier of the requested process │ │ │ │ │ + * callback - {Function} Callback to call when the description is available │ │ │ │ │ + * scope - {Object} Optional execution scope for the callback function │ │ │ │ │ + */ │ │ │ │ │ + describeProcess: function(serverID, processID, callback, scope) { │ │ │ │ │ + var server = this.servers[serverID]; │ │ │ │ │ + if (!server.processDescription[processID]) { │ │ │ │ │ + if (!(processID in server.processDescription)) { │ │ │ │ │ + // set to null so we know a describeFeature request is pending │ │ │ │ │ + server.processDescription[processID] = null; │ │ │ │ │ + OpenLayers.Request.GET({ │ │ │ │ │ + url: server.url, │ │ │ │ │ + params: { │ │ │ │ │ + SERVICE: 'WPS', │ │ │ │ │ + VERSION: server.version, │ │ │ │ │ + REQUEST: 'DescribeProcess', │ │ │ │ │ + IDENTIFIER: processID │ │ │ │ │ + }, │ │ │ │ │ + success: function(response) { │ │ │ │ │ + server.processDescription[processID] = response.responseText; │ │ │ │ │ + this.events.triggerEvent('describeprocess', { │ │ │ │ │ + identifier: processID, │ │ │ │ │ + raw: response.responseText │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + // pending request │ │ │ │ │ + this.events.register('describeprocess', this, function describe(evt) { │ │ │ │ │ + if (evt.identifier === processID) { │ │ │ │ │ + this.events.unregister('describeprocess', this, describe); │ │ │ │ │ + callback.call(scope, evt.raw); │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + window.setTimeout(function() { │ │ │ │ │ + callback.call(scope, server.processDescription[processID]); │ │ │ │ │ + }, 0); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + this.servers = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/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. */ │ │ │ │ │ @@ -28957,1864 +30087,15 @@ │ │ │ │ │ this.tileCache = null; │ │ │ │ │ this.tileCacheIndex = null; │ │ │ │ │ this._destroyed = true; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Rule.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Rule │ │ │ │ │ - * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} name of this rule │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: title │ │ │ │ │ - * {String} Title of this rule (set if included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - title: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - description: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: context │ │ │ │ │ - * {Object} An optional object with properties that the rule should be │ │ │ │ │ - * evaluated against. If no context is specified, feature.attributes will │ │ │ │ │ - * be used. │ │ │ │ │ - */ │ │ │ │ │ - context: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} Optional filter for the rule. │ │ │ │ │ - */ │ │ │ │ │ - filter: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: elseFilter │ │ │ │ │ - * {Boolean} Determines whether this rule is only to be applied only if │ │ │ │ │ - * no other rules match (ElseFilter according to the SLD specification). │ │ │ │ │ - * Default is false. For instances of OpenLayers.Rule, if elseFilter is │ │ │ │ │ - * false, the rule will always apply. For subclasses, the else property is │ │ │ │ │ - * ignored. │ │ │ │ │ - */ │ │ │ │ │ - elseFilter: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: symbolizer │ │ │ │ │ - * {Object} Symbolizer or hash of symbolizers for this rule. If hash of │ │ │ │ │ - * symbolizers, keys are one or more of ["Point", "Line", "Polygon"]. The │ │ │ │ │ - * latter if useful if it is required to style e.g. vertices of a line │ │ │ │ │ - * with a point symbolizer. Note, however, that this is not implemented │ │ │ │ │ - * yet in OpenLayers, but it is the way how symbolizers are defined in │ │ │ │ │ - * SLD. │ │ │ │ │ - */ │ │ │ │ │ - symbolizer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: symbolizers │ │ │ │ │ - * {Array} Collection of symbolizers associated with this rule. If │ │ │ │ │ - * provided at construction, the symbolizers array has precedence │ │ │ │ │ - * over the deprecated symbolizer property. Note that multiple │ │ │ │ │ - * symbolizers are not currently supported by the vector renderers. │ │ │ │ │ - * Rules with multiple symbolizers are currently only useful for │ │ │ │ │ - * maintaining elements in an SLD document. │ │ │ │ │ - */ │ │ │ │ │ - symbolizers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minScaleDenominator │ │ │ │ │ - * {Number} or {String} minimum scale at which to draw the feature. │ │ │ │ │ - * In the case of a String, this can be a combination of text and │ │ │ │ │ - * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ - */ │ │ │ │ │ - minScaleDenominator: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxScaleDenominator │ │ │ │ │ - * {Number} or {String} maximum scale at which to draw the feature. │ │ │ │ │ - * In the case of a String, this can be a combination of text and │ │ │ │ │ - * propertyNames in the form "literal ${propertyName}" │ │ │ │ │ - */ │ │ │ │ │ - maxScaleDenominator: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Rule │ │ │ │ │ - * Creates a Rule. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.symbolizer = {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - delete this.symbolizer; │ │ │ │ │ - } │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i in this.symbolizer) { │ │ │ │ │ - this.symbolizer[i] = null; │ │ │ │ │ - } │ │ │ │ │ - this.symbolizer = null; │ │ │ │ │ - delete this.symbolizers; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * evaluates this rule for a specific feature │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} feature to apply the rule to. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the rule applies, false if it does not. │ │ │ │ │ - * This rule is the default rule and always returns true. │ │ │ │ │ - */ │ │ │ │ │ - evaluate: function(feature) { │ │ │ │ │ - var context = this.getContext(feature); │ │ │ │ │ - var applies = true; │ │ │ │ │ - │ │ │ │ │ - if (this.minScaleDenominator || this.maxScaleDenominator) { │ │ │ │ │ - var scale = feature.layer.map.getScale(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // check if within minScale/maxScale bounds │ │ │ │ │ - if (this.minScaleDenominator) { │ │ │ │ │ - applies = scale >= OpenLayers.Style.createLiteral( │ │ │ │ │ - this.minScaleDenominator, context); │ │ │ │ │ - } │ │ │ │ │ - if (applies && this.maxScaleDenominator) { │ │ │ │ │ - applies = scale < OpenLayers.Style.createLiteral( │ │ │ │ │ - this.maxScaleDenominator, context); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // check if optional filter applies │ │ │ │ │ - if (applies && this.filter) { │ │ │ │ │ - // feature id filters get the feature, others get the context │ │ │ │ │ - if (this.filter.CLASS_NAME == "OpenLayers.Filter.FeatureId") { │ │ │ │ │ - applies = this.filter.evaluate(feature); │ │ │ │ │ - } else { │ │ │ │ │ - applies = this.filter.evaluate(context); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return applies; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getContext │ │ │ │ │ - * Gets the context for evaluating this rule │ │ │ │ │ - * │ │ │ │ │ - * Paramters: │ │ │ │ │ - * feature - {} feature to take the context from if │ │ │ │ │ - * none is specified. │ │ │ │ │ - */ │ │ │ │ │ - getContext: function(feature) { │ │ │ │ │ - var context = this.context; │ │ │ │ │ - if (!context) { │ │ │ │ │ - context = feature.attributes || feature.data; │ │ │ │ │ - } │ │ │ │ │ - if (typeof this.context == "function") { │ │ │ │ │ - context = this.context(feature); │ │ │ │ │ - } │ │ │ │ │ - return context; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this rule. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this rule. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - // clone symbolizers │ │ │ │ │ - var len = this.symbolizers.length; │ │ │ │ │ - options.symbolizers = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - options.symbolizers[i] = this.symbolizers[i].clone(); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // clone symbolizer │ │ │ │ │ - options.symbolizer = {}; │ │ │ │ │ - var value, type; │ │ │ │ │ - for (var key in this.symbolizer) { │ │ │ │ │ - value = this.symbolizer[key]; │ │ │ │ │ - type = typeof value; │ │ │ │ │ - if (type === "object") { │ │ │ │ │ - options.symbolizer[key] = OpenLayers.Util.extend({}, value); │ │ │ │ │ - } else if (type === "string") { │ │ │ │ │ - options.symbolizer[key] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // clone filter │ │ │ │ │ - options.filter = this.filter && this.filter.clone(); │ │ │ │ │ - // clone context │ │ │ │ │ - options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ - return new OpenLayers.Rule(options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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({ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zIndex │ │ │ │ │ - * {Number} The zIndex determines the rendering order for a symbolizer. │ │ │ │ │ - * Symbolizers with larger zIndex values are rendered over symbolizers │ │ │ │ │ - * with smaller zIndex values. Default is 0. │ │ │ │ │ - */ │ │ │ │ │ - zIndex: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer │ │ │ │ │ - * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} An object containing properties to be set on the │ │ │ │ │ - * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ - * construction. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * A new symbolizer. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Util.extend(this, config); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a copy of this symbolizer. │ │ │ │ │ - * │ │ │ │ │ - * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var Type = eval(this.CLASS_NAME); │ │ │ │ │ - return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pointRadius │ │ │ │ │ - * {Number} Pixel point radius. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicWidth │ │ │ │ │ - * {Number} Pixel width for sizing an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicHeight │ │ │ │ │ - * {Number} Pixel height for sizing an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: graphicOpacity │ │ │ │ │ - * {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ - * │ │ │ │ │ - * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Point │ │ │ │ │ - * Create a symbolizer for rendering points. │ │ │ │ │ - * │ │ │ │ │ - * 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 point symbolizer. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Point" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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/Symbolizer.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Line │ │ │ │ │ - * A symbolizer used to render line features. │ │ │ │ │ - */ │ │ │ │ │ -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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Line │ │ │ │ │ - * Create a symbolizer for rendering lines. │ │ │ │ │ - * │ │ │ │ │ - * 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 line symbolizer. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer.Line" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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/Symbolizer.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Symbolizer.Polygon │ │ │ │ │ - * A symbolizer used to render line features. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Symbolizer.Polygon = 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - 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. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Symbolizer.Text │ │ │ │ │ - * Create a symbolizer for rendering text labels. │ │ │ │ │ - * │ │ │ │ │ - * 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 text symbolizer. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - 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. │ │ │ │ │ - * │ │ │ │ │ - * 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/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. │ │ │ │ │ - */ │ │ │ │ │ - layerName: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * 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 + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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(); │ │ │ │ │ - } │ │ │ │ │ - delete this.rules; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this style. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this style. │ │ │ │ │ - */ │ │ │ │ │ - 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()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return new OpenLayers.Style2(config); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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 │ │ │ │ │ - * ). │ │ │ │ │ - */ │ │ │ │ │ - featureDx: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Renderer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * containerID - {} │ │ │ │ │ - * options - {Object} options for this renderer. See sublcasses for │ │ │ │ │ - * supported options. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(containerID, options) { │ │ │ │ │ - this.container = OpenLayers.Util.getElement(containerID); │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.container = null; │ │ │ │ │ - this.extent = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.resolution = null; │ │ │ │ │ - this.map = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: supported │ │ │ │ │ - * This should be overridden by specific subclasses │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ - */ │ │ │ │ │ - supported: function() { │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setExtent │ │ │ │ │ - * Set the visible part of the layer. │ │ │ │ │ - * │ │ │ │ │ - * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ - * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ - * next it is needed. │ │ │ │ │ - * We nullify the resolution cache (this.resolution) if resolutionChanged │ │ │ │ │ - * is set to true - this way it will be re-computed on the next │ │ │ │ │ - * getResolution() request. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * extent - {} │ │ │ │ │ - * resolutionChanged - {Boolean} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true to notify the layer that the new extent does not exceed │ │ │ │ │ - * the coordinate range, and the features will not need to be redrawn. │ │ │ │ │ - * False otherwise. │ │ │ │ │ - */ │ │ │ │ │ - setExtent: function(extent, resolutionChanged) { │ │ │ │ │ - this.extent = extent.clone(); │ │ │ │ │ - if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var ratio = extent.getWidth() / this.map.getExtent().getWidth(), │ │ │ │ │ - extent = extent.scale(1 / ratio); │ │ │ │ │ - this.extent = extent.wrapDateLine(this.map.getMaxExtent()).scale(ratio); │ │ │ │ │ - } │ │ │ │ │ - if (resolutionChanged) { │ │ │ │ │ - this.resolution = null; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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: │ │ │ │ │ - * {Float} The current map's resolution │ │ │ │ │ - */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ - return this.resolution; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Draw the feature. The optional style argument can be used │ │ │ │ │ - * to override the feature's own style. This method should only │ │ │ │ │ - * be called from layer.drawFeature(). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * style - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ - * undefined if the feature had no geometry │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - } else { │ │ │ │ │ - this.removeText(feature.id); │ │ │ │ │ - } │ │ │ │ │ - return rendered; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateFeatureDx │ │ │ │ │ - * {Number} Calculates the feature offset in x direction. Looking at the │ │ │ │ │ - * center of the feature bounds and the renderer extent, we calculate how │ │ │ │ │ - * many world widths the two are away from each other. This distance is │ │ │ │ │ - * used to shift the feature as close as possible to the center of the │ │ │ │ │ - * current enderer extent, which ensures that the feature is visible in the │ │ │ │ │ - * current viewport. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} Bounds of the feature │ │ │ │ │ - * worldBounds - {} Bounds of the world │ │ │ │ │ - */ │ │ │ │ │ - calculateFeatureDx: function(bounds, worldBounds) { │ │ │ │ │ - this.featureDx = 0; │ │ │ │ │ - if (worldBounds) { │ │ │ │ │ - var worldWidth = worldBounds.getWidth(), │ │ │ │ │ - rendererCenterX = (this.extent.left + this.extent.right) / 2, │ │ │ │ │ - featureCenterX = (bounds.left + bounds.right) / 2, │ │ │ │ │ - worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth); │ │ │ │ │ - this.featureDx = worldsAway * worldWidth; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawGeometry │ │ │ │ │ - * │ │ │ │ │ - * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ - * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ - * virtual function │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * style - {Object} │ │ │ │ │ - * featureId - {} │ │ │ │ │ - */ │ │ │ │ │ - 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} │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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/Spherical.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: Spherical │ │ │ │ │ - * The OpenLayers.Spherical namespace includes utility functions for │ │ │ │ │ - * calculations on the basis of a spherical earth (ignoring ellipsoidal │ │ │ │ │ - * effects), which is accurate enough for most purposes. │ │ │ │ │ - * │ │ │ │ │ - * Relevant links: │ │ │ │ │ - * * http://www.movable-type.co.uk/scripts/latlong.html │ │ │ │ │ - * * http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: computeDistanceBetween │ │ │ │ │ - * Computes the distance between two LonLats. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ - * a JavaScript literal with lon lat properties. │ │ │ │ │ - * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ - * JavaScript literal with lon lat properties. │ │ │ │ │ - * radius - {Float} The radius. Optional. Defaults to 6378137 meters. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The distance in meters. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Spherical.computeDistanceBetween = function(from, to, radius) { │ │ │ │ │ - var R = radius || OpenLayers.Spherical.DEFAULT_RADIUS; │ │ │ │ │ - var sinHalfDeltaLon = Math.sin(Math.PI * (to.lon - from.lon) / 360); │ │ │ │ │ - var sinHalfDeltaLat = Math.sin(Math.PI * (to.lat - from.lat) / 360); │ │ │ │ │ - var a = sinHalfDeltaLat * sinHalfDeltaLat + │ │ │ │ │ - sinHalfDeltaLon * sinHalfDeltaLon * Math.cos(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ - return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: computeHeading │ │ │ │ │ - * Computes the heading from one LonLat to another LonLat. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ - * a JavaScript literal with lon lat properties. │ │ │ │ │ - * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ - * JavaScript literal with lon lat properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The heading in degrees. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Spherical.computeHeading = function(from, to) { │ │ │ │ │ - var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ - var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) - │ │ │ │ │ - Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180); │ │ │ │ │ - return 180 * Math.atan2(y, x) / Math.PI; │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Protocol.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Protocol │ │ │ │ │ - * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the protocol subclasses instead. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {} The format used by this protocol. │ │ │ │ │ - */ │ │ │ │ │ - format: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: autoDestroy │ │ │ │ │ - * {Boolean} The creator of the protocol can set autoDestroy to false │ │ │ │ │ - * to fully control when the protocol is destroyed. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultFilter │ │ │ │ │ - * {} Optional default filter to read requests │ │ │ │ │ - */ │ │ │ │ │ - defaultFilter: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Protocol │ │ │ │ │ - * Abstract class for vector protocols. Create instances of a subclass. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mergeWithDefaultFilter │ │ │ │ │ - * Merge filter passed to the read method with the default one │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} │ │ │ │ │ - */ │ │ │ │ │ - mergeWithDefaultFilter: function(filter) { │ │ │ │ │ - var merged; │ │ │ │ │ - if (filter && this.defaultFilter) { │ │ │ │ │ - merged = new OpenLayers.Filter.Logical({ │ │ │ │ │ - type: OpenLayers.Filter.Logical.AND, │ │ │ │ │ - filters: [this.defaultFilter, filter] │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - merged = filter || this.defaultFilter || undefined; │ │ │ │ │ - } │ │ │ │ │ - return merged; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up 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/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/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: threshold │ │ │ │ │ - * In most cases changing the threshold isn't needed. │ │ │ │ │ - * In px/ms, default to 0. │ │ │ │ │ - */ │ │ │ │ │ - threshold: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: deceleration │ │ │ │ │ - * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ - */ │ │ │ │ │ - deceleration: 0.0035, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: begin │ │ │ │ │ - * Begins the dragging. │ │ │ │ │ - */ │ │ │ │ │ - begin: function() { │ │ │ │ │ - OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ - this.timerId = undefined; │ │ │ │ │ - this.points = []; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Updates during the dragging. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The new position. │ │ │ │ │ - */ │ │ │ │ │ - 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The last position. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with two properties: "speed", and "theta". The │ │ │ │ │ - * "speed" and "theta" values are to be passed to the move │ │ │ │ │ - * function when starting the animation. │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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/Popup.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. */ │ │ │ │ │ │ │ │ │ │ @@ -31879,718 +31160,14 @@ │ │ │ │ │ │ │ │ │ │ OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - 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/Marker.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Icon.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Marker │ │ │ │ │ - * Instances of OpenLayers.Marker are a combination of a │ │ │ │ │ - * and an . │ │ │ │ │ - * │ │ │ │ │ - * Markers are generally added to a special layer called │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var markers = new OpenLayers.Layer.Markers( "Markers" ); │ │ │ │ │ - * map.addLayer(markers); │ │ │ │ │ - * │ │ │ │ │ - * var size = new OpenLayers.Size(21,25); │ │ │ │ │ - * var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); │ │ │ │ │ - * var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset); │ │ │ │ │ - * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon)); │ │ │ │ │ - * markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone())); │ │ │ │ │ - * │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Note that if you pass an icon into the Marker constructor, it will take │ │ │ │ │ - * that icon and use it. This means that you should not share icons between │ │ │ │ │ - * markers -- you use them once, but you should clone() for any additional │ │ │ │ │ - * markers using that same icon. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: icon │ │ │ │ │ - * {} The icon used by this marker. │ │ │ │ │ - */ │ │ │ │ │ - icon: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} location of object │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} the event handler. │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} the map this marker is attached to │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Marker │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {} the position of this marker │ │ │ │ │ - * icon - {} the icon for this marker │ │ │ │ │ - */ │ │ │ │ │ - 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 │ │ │ │ │ - * Destroy the marker. You must first remove the marker from any │ │ │ │ │ - * layer which it has been added to, or you will get buggy behavior. │ │ │ │ │ - * (This can not be done within the marker since the marker does not │ │ │ │ │ - * know which layer it is attached to.) │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - // erase any drawn features │ │ │ │ │ - this.erase(); │ │ │ │ │ - │ │ │ │ │ - this.map = null; │ │ │ │ │ - │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.destroy(); │ │ │ │ │ - this.icon = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Calls draw on the icon, and returns that output. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ - * location passed-in │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - return this.icon.draw(px); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erases any drawn elements for this marker. │ │ │ │ │ - */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.erase(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Move the marker to the new location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.icon != null)) { │ │ │ │ │ - this.icon.moveTo(px); │ │ │ │ │ - } │ │ │ │ │ - this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ - */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ - return isDrawn; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ - */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - return onScreen; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: inflate │ │ │ │ │ - * Englarges the markers icon by the specified ratio. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ - * will double the size). │ │ │ │ │ - */ │ │ │ │ │ - inflate: function(inflate) { │ │ │ │ │ - if (this.icon) { │ │ │ │ │ - this.icon.setSize({ │ │ │ │ │ - w: this.icon.size.w * inflate, │ │ │ │ │ - h: this.icon.size.h * inflate │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the opacity of the marker by changin the opacity of │ │ │ │ │ - * its icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {float} Specified as fraction (0.4, etc) │ │ │ │ │ - */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - this.icon.setOpacity(opacity); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setUrl │ │ │ │ │ - * Change URL of the Icon Image. │ │ │ │ │ - * │ │ │ │ │ - * url - {String} │ │ │ │ │ - */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - this.icon.setUrl(url); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.icon.display(display); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Marker" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: defaultIcon │ │ │ │ │ - * Creates a default . │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A default OpenLayers.Icon to use for a marker │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Marker.defaultIcon = function() { │ │ │ │ │ - return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"), { │ │ │ │ │ - w: 21, │ │ │ │ │ - h: 25 │ │ │ │ │ - }, { │ │ │ │ │ - x: -10.5, │ │ │ │ │ - y: -25 │ │ │ │ │ - }); │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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/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. */ │ │ │ │ │ @@ -32958,22350 +31535,22591 @@ │ │ │ │ │ OpenLayers.Control.TYPE_TOGGLE = 2; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Constant: OpenLayers.Control.TYPE_TOOL │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Control.TYPE_TOOL = 3; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Events/buttonclick.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/Events.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.buttonclick │ │ │ │ │ - * Extension event type for handling buttons on top of a dom element. This │ │ │ │ │ - * event type fires "buttonclick" on its when a button was │ │ │ │ │ - * clicked. Buttons are detected by the "olButton" class. │ │ │ │ │ - * │ │ │ │ │ - * This event type makes sure that button clicks do not interfere with other │ │ │ │ │ - * events that are registered on the same . │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - *buttonclick* Triggered when a button is clicked. Listeners receive an │ │ │ │ │ - * object with a *buttonElement* property referencing the dom element of │ │ │ │ │ - * the clicked button, and an *buttonXY* property with the click position │ │ │ │ │ - * relative to the button. │ │ │ │ │ + * Class: OpenLayers.Rule │ │ │ │ │ + * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.buttonclick = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: target │ │ │ │ │ - * {} The events instance that the buttonclick event will │ │ │ │ │ - * be triggered on. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - target: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {Array} Events to observe and conditionally stop from propagating when │ │ │ │ │ - * an element with the olButton class (or its olAlphaImg child) is │ │ │ │ │ - * clicked. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} name of this rule │ │ │ │ │ */ │ │ │ │ │ - events: [ │ │ │ │ │ - 'mousedown', 'mouseup', 'click', 'dblclick', │ │ │ │ │ - 'touchstart', 'touchmove', 'touchend', 'keydown' │ │ │ │ │ - ], │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that start │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this rule (set if included in SLD) │ │ │ │ │ */ │ │ │ │ │ - startRegEx: /^mousedown|touchstart$/, │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: cancelRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that cancel │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ */ │ │ │ │ │ - cancelRegEx: /^touchmove$/, │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: completeRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that complete │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - completeRegEx: /^mouseup|touchend$/, │ │ │ │ │ + context: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startEvt │ │ │ │ │ - * {Event} The event that started the click sequence │ │ │ │ │ + * Property: filter │ │ │ │ │ + * {} Optional filter for the rule. │ │ │ │ │ */ │ │ │ │ │ + filter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Events.buttonclick │ │ │ │ │ - * Construct a buttonclick event type. Applications are not supposed to │ │ │ │ │ - * create instances of this class - they are created on demand by │ │ │ │ │ - * instances. │ │ │ │ │ + * 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: │ │ │ │ │ - * target - {} The events instance that the buttonclick │ │ │ │ │ - * event will be triggered on. │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * rule │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(target) { │ │ │ │ │ - this.target = target; │ │ │ │ │ - for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ - this.target.register(this.events[i], this, this.buttonClick, { │ │ │ │ │ - extension: true │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.symbolizer = {}; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + if (this.symbolizers) { │ │ │ │ │ + delete this.symbolizer; │ │ │ │ │ } │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ - this.target.unregister(this.events[i], this, this.buttonClick); │ │ │ │ │ + for (var i in this.symbolizer) { │ │ │ │ │ + this.symbolizer[i] = null; │ │ │ │ │ } │ │ │ │ │ - delete this.target; │ │ │ │ │ + this.symbolizer = null; │ │ │ │ │ + delete this.symbolizers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getPressedButton │ │ │ │ │ - * Get the pressed button, if any. Returns undefined if no button │ │ │ │ │ - * was pressed. │ │ │ │ │ - * │ │ │ │ │ - * Arguments: │ │ │ │ │ - * element - {DOMElement} The event target. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * evaluates this rule for a specific feature │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} feature to apply the rule to. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The button element, or undefined. │ │ │ │ │ + * {Boolean} true if the rule applies, false if it does not. │ │ │ │ │ + * This rule is the default rule and always returns true. │ │ │ │ │ */ │ │ │ │ │ - getPressedButton: function(element) { │ │ │ │ │ - var depth = 3, // limit the search depth │ │ │ │ │ - button; │ │ │ │ │ - do { │ │ │ │ │ - if (OpenLayers.Element.hasClass(element, "olButton")) { │ │ │ │ │ - // hit! │ │ │ │ │ - button = element; │ │ │ │ │ - break; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - element = element.parentNode; │ │ │ │ │ - } while (--depth > 0 && element); │ │ │ │ │ - return button; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return applies; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: ignore │ │ │ │ │ - * Check for event target elements that should be ignored by OpenLayers. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} The event target. │ │ │ │ │ + * Method: getContext │ │ │ │ │ + * Gets the context for evaluating this rule │ │ │ │ │ + * │ │ │ │ │ + * Paramters: │ │ │ │ │ + * feature - {} feature to take the context from if │ │ │ │ │ + * none is specified. │ │ │ │ │ */ │ │ │ │ │ - ignore: function(element) { │ │ │ │ │ - var depth = 3, │ │ │ │ │ - ignore = false; │ │ │ │ │ - do { │ │ │ │ │ - if (element.nodeName.toLowerCase() === 'a') { │ │ │ │ │ - ignore = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - element = element.parentNode; │ │ │ │ │ - } while (--depth > 0 && element); │ │ │ │ │ - return ignore; │ │ │ │ │ + getContext: function(feature) { │ │ │ │ │ + var context = this.context; │ │ │ │ │ + if (!context) { │ │ │ │ │ + context = feature.attributes || feature.data; │ │ │ │ │ + } │ │ │ │ │ + if (typeof this.context == "function") { │ │ │ │ │ + context = this.context(feature); │ │ │ │ │ + } │ │ │ │ │ + return context; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buttonClick │ │ │ │ │ - * Check if a button was clicked, and fire the buttonclick event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this rule. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this rule. │ │ │ │ │ */ │ │ │ │ │ - buttonClick: function(evt) { │ │ │ │ │ - var propagate = true, │ │ │ │ │ - element = OpenLayers.Event.element(evt); │ │ │ │ │ - if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) { │ │ │ │ │ - // was a button pressed? │ │ │ │ │ - var button = this.getPressedButton(element); │ │ │ │ │ - if (button) { │ │ │ │ │ - if (evt.type === "keydown") { │ │ │ │ │ - switch (evt.keyCode) { │ │ │ │ │ - case OpenLayers.Event.KEY_RETURN: │ │ │ │ │ - case OpenLayers.Event.KEY_SPACE: │ │ │ │ │ - this.target.triggerEvent("buttonclick", { │ │ │ │ │ - buttonElement: button │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else if (this.startEvt) { │ │ │ │ │ - if (this.completeRegEx.test(evt.type)) { │ │ │ │ │ - var pos = OpenLayers.Util.pagePosition(button); │ │ │ │ │ - var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ - var scrollTop = window.pageYOffset || viewportElement.scrollTop; │ │ │ │ │ - var scrollLeft = window.pageXOffset || viewportElement.scrollLeft; │ │ │ │ │ - pos[0] = pos[0] - scrollLeft; │ │ │ │ │ - pos[1] = pos[1] - scrollTop; │ │ │ │ │ - │ │ │ │ │ - this.target.triggerEvent("buttonclick", { │ │ │ │ │ - buttonElement: button, │ │ │ │ │ - buttonXY: { │ │ │ │ │ - x: this.startEvt.clientX - pos[0], │ │ │ │ │ - y: this.startEvt.clientY - pos[1] │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (this.cancelRegEx.test(evt.type)) { │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ - } │ │ │ │ │ - if (this.startRegEx.test(evt.type)) { │ │ │ │ │ - this.startEvt = evt; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - propagate = false; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - propagate = !this.ignore(OpenLayers.Event.element(evt)); │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return propagate; │ │ │ │ │ - } │ │ │ │ │ + // clone filter │ │ │ │ │ + options.filter = this.filter && this.filter.clone(); │ │ │ │ │ + // clone context │ │ │ │ │ + options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ + return new OpenLayers.Rule(options); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Rule" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Click.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/Handler.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.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.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. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.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, │ │ │ │ │ +OpenLayers.Renderer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: container │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: 0, │ │ │ │ │ + container: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dblclickTolerance │ │ │ │ │ - * {Number} Maximum distance in pixels between clicks for a sequence of │ │ │ │ │ - * events to be considered a double click. Default is 13. If the │ │ │ │ │ - * distance between two clicks is greater than this value, a double- │ │ │ │ │ - * click will not be fired. │ │ │ │ │ + * Property: root │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - dblclickTolerance: 13, │ │ │ │ │ + root: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: stopSingle │ │ │ │ │ - * {Boolean} Stop other listeners from being notified of clicks. Default │ │ │ │ │ - * is false. If true, any listeners registered before this one for │ │ │ │ │ - * click or rightclick events will not be notified. │ │ │ │ │ + /** │ │ │ │ │ + * Property: extent │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - stopSingle: false, │ │ │ │ │ + extent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopDouble │ │ │ │ │ - * {Boolean} Stop other listeners from being notified of double-clicks. │ │ │ │ │ - * Default is false. If true, any click listeners registered before │ │ │ │ │ - * this one will not be notified of *any* double-click events. │ │ │ │ │ - * │ │ │ │ │ - * The one caveat with stopDouble is that given a map with two click │ │ │ │ │ - * handlers, one with stopDouble true and the other with stopSingle │ │ │ │ │ - * true, the stopSingle handler should be activated last to get │ │ │ │ │ - * uniform cross-browser performance. Since IE triggers one click │ │ │ │ │ - * with a dblclick and FF triggers two, if a stopSingle handler is │ │ │ │ │ - * activated first, all it gets in IE is a single click when the │ │ │ │ │ - * second handler stops propagation on the dblclick. │ │ │ │ │ + * Property: 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. │ │ │ │ │ */ │ │ │ │ │ - stopDouble: false, │ │ │ │ │ + locked: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: down │ │ │ │ │ - * {Object} Object that store relevant information about the last │ │ │ │ │ - * mousedown or touchstart. Its 'xy' OpenLayers.Pixel property gives │ │ │ │ │ - * the average location of the mouse/touch event. Its 'touches' │ │ │ │ │ - * property records clientX/clientY of each touches. │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} cache of current map resolution │ │ │ │ │ */ │ │ │ │ │ - down: null, │ │ │ │ │ + resolution: 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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: first │ │ │ │ │ - * {Object} When waiting for double clicks, this object will store │ │ │ │ │ - * information about the first click in a two click sequence. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ */ │ │ │ │ │ - first: null, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: rightclickTimerId │ │ │ │ │ - * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ - * . │ │ │ │ │ + * Property: featureDx │ │ │ │ │ + * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ + * applied to the current feature while rendering (see │ │ │ │ │ + * ). │ │ │ │ │ */ │ │ │ │ │ - rightclickTimerId: null, │ │ │ │ │ + featureDx: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Click │ │ │ │ │ - * Create a new click handler. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Renderer │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * 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: touchstart │ │ │ │ │ - * Handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.container = null; │ │ │ │ │ + this.extent = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Store position of last move, because touchend event can have │ │ │ │ │ - * an empty "touches" property. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: supported │ │ │ │ │ + * This should be overridden by specific subclasses │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + supported: function() { │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ - * touches property from last touchstart or touchmove │ │ │ │ │ + * Method: setExtent │ │ │ │ │ + * Set the visible part of the layer. │ │ │ │ │ + * │ │ │ │ │ + * Resolution has probably changed, so we nullify the resolution │ │ │ │ │ + * cache (this.resolution) -- this way it will be re-computed when │ │ │ │ │ + * next it is needed. │ │ │ │ │ + * We nullify the resolution cache (this.resolution) if resolutionChanged │ │ │ │ │ + * is set to true - this way it will be re-computed on the next │ │ │ │ │ + * getResolution() request. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * extent - {} │ │ │ │ │ + * resolutionChanged - {Boolean} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + this.resolution = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ + /** │ │ │ │ │ + * Method: getResolution │ │ │ │ │ + * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Float} The current map's resolution │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - │ │ │ │ │ - // Collect right mouse clicks from the mouseup │ │ │ │ │ - // IE - ignores the second right click in mousedown so using │ │ │ │ │ - // mouseup instead │ │ │ │ │ - if (this.checkModifiers(evt) && this.control.handleRightClicks && │ │ │ │ │ - OpenLayers.Event.isRightClick(evt)) { │ │ │ │ │ - propagate = this.rightclick(evt); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return propagate; │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ + return this.resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: rightclick │ │ │ │ │ - * Handle rightclick. For a dblrightclick, we get two clicks so we need │ │ │ │ │ - * to always register for dblrightclick to properly handle single │ │ │ │ │ - * clicks. │ │ │ │ │ - * │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Draw the feature. The optional style argument can be used │ │ │ │ │ + * to override the feature's own style. This method should only │ │ │ │ │ + * be called from layer.drawFeature(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ + * style - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ + * undefined if the feature had no geometry │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + drawFeature: function(feature, style) { │ │ │ │ │ + if (style == null) { │ │ │ │ │ + style = feature.style; │ │ │ │ │ } │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ - }, │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + var bounds = feature.geometry.getBounds(); │ │ │ │ │ + if (bounds) { │ │ │ │ │ + var worldBounds; │ │ │ │ │ + if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { │ │ │ │ │ + worldBounds = this.map.getMaxExtent(); │ │ │ │ │ + } │ │ │ │ │ + if (!bounds.intersectsBounds(this.extent, { │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + })) { │ │ │ │ │ + style = { │ │ │ │ │ + display: "none" │ │ │ │ │ + }; │ │ │ │ │ + } else { │ │ │ │ │ + this.calculateFeatureDx(bounds, worldBounds); │ │ │ │ │ + } │ │ │ │ │ + var rendered = this.drawGeometry(feature.geometry, style, feature.id); │ │ │ │ │ + if (style.display != "none" && style.label && rendered !== false) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: 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]); │ │ │ │ │ + var location = feature.geometry.getCentroid(); │ │ │ │ │ + if (style.labelXOffset || style.labelYOffset) { │ │ │ │ │ + var xOffset = isNaN(style.labelXOffset) ? 0 : style.labelXOffset; │ │ │ │ │ + var yOffset = isNaN(style.labelYOffset) ? 0 : style.labelYOffset; │ │ │ │ │ + var res = this.getResolution(); │ │ │ │ │ + location.move(xOffset * res, yOffset * res); │ │ │ │ │ + } │ │ │ │ │ + this.drawText(feature.id, style, location); │ │ │ │ │ + } else { │ │ │ │ │ + this.removeText(feature.id); │ │ │ │ │ + } │ │ │ │ │ + return rendered; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: 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. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} Bounds of the feature │ │ │ │ │ + * worldBounds - {} Bounds of the world │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - if (!this.last) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ + calculateFeatureDx: function(bounds, worldBounds) { │ │ │ │ │ + this.featureDx = 0; │ │ │ │ │ + if (worldBounds) { │ │ │ │ │ + var worldWidth = worldBounds.getWidth(), │ │ │ │ │ + rendererCenterX = (this.extent.left + this.extent.right) / 2, │ │ │ │ │ + featureCenterX = (bounds.left + bounds.right) / 2, │ │ │ │ │ + worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth); │ │ │ │ │ + this.featureDx = worldsAway * worldWidth; │ │ │ │ │ } │ │ │ │ │ - this.handleSingle(evt); │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: drawGeometry │ │ │ │ │ + * │ │ │ │ │ + * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ + * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ + * virtual function │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * featureId - {} │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleSingle │ │ │ │ │ - * Handle single click sequence. │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawText │ │ │ │ │ + * Function for drawing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ + * style - │ │ │ │ │ + * location - {} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + drawText: function(featureId, style, location) {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: queuePotentialClick │ │ │ │ │ - * This method is separated out largely to make testing easier (so we │ │ │ │ │ - * don't have to override window.setTimeout) │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeText │ │ │ │ │ + * Function for removing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - queuePotentialClick: function(evt) { │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ - this.delay │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + removeText: function(featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the event is within the optional pixel tolerance. Note │ │ │ │ │ - * that the pixel tolerance check only works if mousedown events get to │ │ │ │ │ - * the listeners registered here. If they are stopped by other elements, │ │ │ │ │ - * the will have no effect here (this method will always │ │ │ │ │ - * return true). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The click is within the pixel tolerance (if specified). │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear all vectors from the renderer. │ │ │ │ │ + * virtual function. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return passes; │ │ │ │ │ - }, │ │ │ │ │ + clear: function() {}, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getTouchDistance │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The pixel displacement between two touches. │ │ │ │ │ + * {String} A feature id or undefined. │ │ │ │ │ */ │ │ │ │ │ - getTouchDistance: function(from, to) { │ │ │ │ │ - return Math.sqrt( │ │ │ │ │ - Math.pow(from.clientX - to.clientX, 2) + │ │ │ │ │ - Math.pow(from.clientY - to.clientY, 2) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: eraseFeatures │ │ │ │ │ + * This is called by the layer to erase features │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} │ │ │ │ │ */ │ │ │ │ │ - passesDblclickTolerance: function(evt) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.down && this.first) { │ │ │ │ │ - passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: eraseGeometry │ │ │ │ │ + * Remove a geometry from the renderer (by id). │ │ │ │ │ + * virtual function. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.rightclickTimerId != null) { │ │ │ │ │ - window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Sets to null. And optionally triggers the click callback if │ │ │ │ │ - * evt is set. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback("click", [evt]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + moveRoot: function(renderer) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getEventInfo │ │ │ │ │ - * This method allows us to store event information without storing the │ │ │ │ │ - * actual event. In touch devices (at least), the same event is │ │ │ │ │ - * modified between touchstart, touchmove, and touchend. │ │ │ │ │ - * │ │ │ │ │ + * Method: 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: │ │ │ │ │ - * {Object} An object with event related info. │ │ │ │ │ + * {String} the id of the output layer. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + getRenderLayerId: function() { │ │ │ │ │ + return this.container.id; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ + * Method: applyDefaultSymbolizer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * symbolizer - {Object} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + applyDefaultSymbolizer: function(symbolizer) { │ │ │ │ │ + var result = OpenLayers.Util.extend({}, │ │ │ │ │ + OpenLayers.Renderer.defaultSymbolizer); │ │ │ │ │ + if (symbolizer.stroke === false) { │ │ │ │ │ + delete result.strokeWidth; │ │ │ │ │ + delete result.strokeColor; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + if (symbolizer.fill === false) { │ │ │ │ │ + delete result.fillColor; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.extend(result, symbolizer); │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Renderer" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Renderer.defaultSymbolizer │ │ │ │ │ + * {Object} Properties from this symbolizer will be applied to symbolizers │ │ │ │ │ + * with missing properties. This can also be used to set a global │ │ │ │ │ + * symbolizer default in OpenLayers. To be SLD 1.x compliant, add the │ │ │ │ │ + * following code before rendering any vector features: │ │ │ │ │ + * (code) │ │ │ │ │ + * OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ + * fillColor: "#808080", │ │ │ │ │ + * fillOpacity: 1, │ │ │ │ │ + * strokeColor: "#000000", │ │ │ │ │ + * strokeOpacity: 1, │ │ │ │ │ + * strokeWidth: 1, │ │ │ │ │ + * pointRadius: 3, │ │ │ │ │ + * graphicName: "square" │ │ │ │ │ + * }; │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Renderer.defaultSymbolizer = { │ │ │ │ │ + fillColor: "#000000", │ │ │ │ │ + strokeColor: "#000000", │ │ │ │ │ + strokeWidth: 2, │ │ │ │ │ + fillOpacity: 1, │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + pointRadius: 0, │ │ │ │ │ + labelAlign: 'cm' │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Renderer.symbol │ │ │ │ │ + * Coordinate arrays for well known (named) symbols. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Renderer.symbol = { │ │ │ │ │ + "star": [350, 75, 379, 161, 469, 161, 397, 215, 423, 301, 350, 250, 277, 301, │ │ │ │ │ + 303, 215, 231, 161, 321, 161, 350, 75 │ │ │ │ │ + ], │ │ │ │ │ + "cross": [4, 0, 6, 0, 6, 4, 10, 4, 10, 6, 6, 6, 6, 10, 4, 10, 4, 6, 0, 6, 0, 4, 4, 4, │ │ │ │ │ + 4, 0 │ │ │ │ │ + ], │ │ │ │ │ + "x": [0, 0, 25, 0, 50, 35, 75, 0, 100, 0, 65, 50, 100, 100, 75, 100, 50, 65, 25, 100, 0, 100, 35, 50, 0, 0], │ │ │ │ │ + "square": [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], │ │ │ │ │ + "triangle": [0, 10, 10, 10, 5, 0, 0, 10] │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Drag.js │ │ │ │ │ + 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/Handler.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer.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: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Point │ │ │ │ │ + * A symbolizer used to render point features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.Symbolizer.Point = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - started: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ - * on the same element. Default is true. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - dragging: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {} The last pixel location of the drag. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - last: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {} The first pixel location of the drag. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - start: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastMoveEvt │ │ │ │ │ - * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ - * position the map correctly when our "delay drag" │ │ │ │ │ - * timeout expired. │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - lastMoveEvt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: oldOnselectstart │ │ │ │ │ - * {Function} │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - oldOnselectstart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} In order to increase performance, an interval (in │ │ │ │ │ - * milliseconds) can be set to reduce the number of drag events │ │ │ │ │ - * called. If set, a new drag event will not be set until the │ │ │ │ │ - * interval has passed. │ │ │ │ │ - * Defaults to 0, meaning no interval. │ │ │ │ │ + * APIProperty: pointRadius │ │ │ │ │ + * {Number} Pixel point radius. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timeoutId │ │ │ │ │ - * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ - * This is "private", and should be left alone. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - timeoutId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, the handler will also handle mouse moves when │ │ │ │ │ - * the cursor has moved out of the map viewport. Default is false. │ │ │ │ │ + * APIProperty: graphicWidth │ │ │ │ │ + * {Number} Pixel width for sizing an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: documentEvents │ │ │ │ │ - * {Boolean} Are we currently observing document events? │ │ │ │ │ + * APIProperty: graphicHeight │ │ │ │ │ + * {Number} Pixel height for sizing an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - documentEvents: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ - * Returns OpenLayers.Handler.Drag │ │ │ │ │ + * APIProperty: graphicOpacity │ │ │ │ │ + * {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ * │ │ │ │ │ - * 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} │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - var me = this; │ │ │ │ │ - this._docMove = function(evt) { │ │ │ │ │ - me.mousemove({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ - }, │ │ │ │ │ - element: document │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - this._docUp = function(evt) { │ │ │ │ │ - me.mouseup({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragstart │ │ │ │ │ - * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ + * 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: 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. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Point │ │ │ │ │ + * Create a symbolizer for rendering points. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * A new point symbolizer. │ │ │ │ │ */ │ │ │ │ │ - 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]); │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Point" │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Line │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Line = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragmove │ │ │ │ │ - * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - dragmove: function(evt) { │ │ │ │ │ - this.lastMoveEvt = evt; │ │ │ │ │ - if (this.started && !this.timeoutId && (evt.xy.x != this.last.x || │ │ │ │ │ - evt.xy.y != this.last.y)) { │ │ │ │ │ - if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ - if (evt.element === document) { │ │ │ │ │ - this.adjustXY(evt); │ │ │ │ │ - // do setEvent manually because the documentEvents are not │ │ │ │ │ - // registered with the map │ │ │ │ │ - this.setEvent(evt); │ │ │ │ │ - } else { │ │ │ │ │ - this.removeDocumentEvents(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.interval > 0) { │ │ │ │ │ - this.timeoutId = setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.removeTimeout, this), │ │ │ │ │ - this.interval); │ │ │ │ │ - } │ │ │ │ │ - this.dragging = true; │ │ │ │ │ - │ │ │ │ │ - this.move(evt); │ │ │ │ │ - this.callback("move", [evt.xy]); │ │ │ │ │ - if (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart; │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ - this.last = evt.xy; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragend │ │ │ │ │ - * This private method is factorized from mouseup and touchend methods │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ - * to do their own processing related to these mouse events. │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * This method is called during the handling of the mouse down event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse down event │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - * │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * This method is called during the handling of the mouse up event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Line │ │ │ │ │ + * Create a symbolizer for rendering lines. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse up event │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * A new line symbolizer. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) {}, │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Line" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Polygon = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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. │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mousemove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeTimeout │ │ │ │ │ - * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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: mouseup │ │ │ │ │ - * Handle mouseup events │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * Create a symbolizer for rendering polygons. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * config - {Object} An object containing properties to be set on the │ │ │ │ │ + * symbolizer. Any documented symbolizer property can be set at │ │ │ │ │ + * construction. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * A new polygon symbolizer. │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Polygon" │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Handle mouseout events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - this.addDocumentEvents(); │ │ │ │ │ - } else { │ │ │ │ │ - var dragged = (this.start != this.last); │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.out(evt); │ │ │ │ │ - this.callback("out", []); │ │ │ │ │ - if (dragged) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ - } │ │ │ │ │ - if (document.onselectstart) { │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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} │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - // let the click event propagate only if the mouse moved │ │ │ │ │ - return (this.start == this.last); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontFamily │ │ │ │ │ + * {String} The font family for the label. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontSize │ │ │ │ │ + * {String} The font size for the label. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontWeight │ │ │ │ │ + * {String} The font weight for the label. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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. │ │ │ │ │ + * Property: fontStyle │ │ │ │ │ + * {String} The font style for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - 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. │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Text │ │ │ │ │ + * Create a symbolizer for rendering text labels. │ │ │ │ │ + * │ │ │ │ │ + * 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 text symbolizer. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Drag" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Text" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/OverviewMap.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/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 │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.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: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Raster │ │ │ │ │ + * A symbolizer used to render raster images. │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ +OpenLayers.Symbolizer.Raster = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - size: { │ │ │ │ │ - w: 180, │ │ │ │ │ - h: 90 │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Raster" │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Style2.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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", │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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: 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, │ │ │ │ │ +/** │ │ │ │ │ + * @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 │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Style2 │ │ │ │ │ + * This class represents a collection of rules for rendering features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style2 = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - mapOptions: null, │ │ │ │ │ + id: 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. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} Style identifier. │ │ │ │ │ */ │ │ │ │ │ - autoPan: false, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {String} Title of this style. │ │ │ │ │ */ │ │ │ │ │ - handlers: null, │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolutionFactor │ │ │ │ │ - * {Object} │ │ │ │ │ + * APIProperty: description │ │ │ │ │ + * {String} Description of this style. │ │ │ │ │ */ │ │ │ │ │ - resolutionFactor: 1, │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maximized │ │ │ │ │ - * {Boolean} Start as maximized (visible). Defaults to false. │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {} Name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ */ │ │ │ │ │ - maximized: false, │ │ │ │ │ + layerName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maximizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * maximize div. Defaults to "" (no title). │ │ │ │ │ + * APIProperty: isDefault │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - maximizeTitle: "", │ │ │ │ │ + isDefault: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minimizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * minimize div. Defaults to "" (no title). │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: rules │ │ │ │ │ + * {Array()} Collection of rendering rules. │ │ │ │ │ */ │ │ │ │ │ - minimizeTitle: "", │ │ │ │ │ + rules: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.OverviewMap │ │ │ │ │ - * Create a new overview map │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Style2 │ │ │ │ │ + * Creates a style representing a collection of rendering rules. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * 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(options) { │ │ │ │ │ - this.layers = []; │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Deconstruct the control │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ 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; │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ + this.rules[i].destroy(); │ │ │ │ │ } │ │ │ │ │ + delete this.rules; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.ovmap) { │ │ │ │ │ - this.ovmap.destroy(); │ │ │ │ │ - this.ovmap = null; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this style. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this style. │ │ │ │ │ + */ │ │ │ │ │ + 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()); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return new OpenLayers.Style2(config); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.element.removeChild(this.mapDiv); │ │ │ │ │ - this.mapDiv = null; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Spherical.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - this.div.removeChild(this.element); │ │ │ │ │ - this.element = 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 (this.maximizeDiv) { │ │ │ │ │ - this.div.removeChild(this.maximizeDiv); │ │ │ │ │ - this.maximizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.div.removeChild(this.minimizeDiv); │ │ │ │ │ - this.minimizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * 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 │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - changebaselayer: this.baseLayerDraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ +OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * 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)); │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - // 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'); │ │ │ │ │ +/** │ │ │ │ │ + * APIFunction: computeHeading │ │ │ │ │ + * Computes the heading from one LonLat to another LonLat. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * from - {} or {Object} Starting point. A LonLat or │ │ │ │ │ + * a JavaScript literal with lon lat properties. │ │ │ │ │ + * to - {} or {Object} Ending point. A LonLat or a │ │ │ │ │ + * JavaScript literal with lon lat properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The heading in degrees. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Spherical.computeHeading = function(from, to) { │ │ │ │ │ + var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180); │ │ │ │ │ + var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) - │ │ │ │ │ + Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180); │ │ │ │ │ + return 180 * Math.atan2(y, x) / Math.PI; │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Protocol.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - this.extentRectangle = document.createElement('div'); │ │ │ │ │ - this.extentRectangle.style.position = 'absolute'; │ │ │ │ │ - this.extentRectangle.style.zIndex = 1000; //HACK │ │ │ │ │ - this.extentRectangle.className = this.displayClass + 'ExtentRectangle'; │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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.element.appendChild(this.mapDiv); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Protocol │ │ │ │ │ + * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the protocol subclasses instead. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ + /** │ │ │ │ │ + * Property: format │ │ │ │ │ + * {} The format used by this protocol. │ │ │ │ │ + */ │ │ │ │ │ + format: null, │ │ │ │ │ │ │ │ │ │ - // 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(); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ + */ │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ - if (this.maximized) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultFilter │ │ │ │ │ + * {} Optional default filter to read requests │ │ │ │ │ + */ │ │ │ │ │ + defaultFilter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: baseLayerDraw │ │ │ │ │ - * Draw the base layer - called if unable to complete in the initial draw │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - baseLayerDraw: function() { │ │ │ │ │ - this.draw(); │ │ │ │ │ - this.map.events.unregister("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: rectDrag │ │ │ │ │ - * Handle extent rectangle drag │ │ │ │ │ + * Method: mergeWithDefaultFilter │ │ │ │ │ + * Merge filter passed to the read method with the default one │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} The pixel location of the drag. │ │ │ │ │ + * filter - {} │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mapDivClick │ │ │ │ │ - * Handle browser events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} evt │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up the protocol. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.options = null; │ │ │ │ │ + this.format = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Construct a request for reading new features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - if (evt.buttonElement === this.minimizeDiv) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else if (evt.buttonElement === this.maximizeDiv) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } │ │ │ │ │ + read: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.filter = this.mergeWithDefaultFilter(options.filter); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: maximizeControl │ │ │ │ │ - * Unhide the control. Called when the control is in the map viewport. │ │ │ │ │ + * APIMethod: create │ │ │ │ │ + * Construct a request for writing newly created features. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - maximizeControl: function(e) { │ │ │ │ │ - this.element.style.display = ''; │ │ │ │ │ - this.showToggle(false); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + create: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: minimizeControl │ │ │ │ │ - * Hide all the contents of the control, shrink the size, │ │ │ │ │ - * add the maximize icon │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: update │ │ │ │ │ + * Construct a request updating modified features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - minimizeControl: function(e) { │ │ │ │ │ - this.element.style.display = 'none'; │ │ │ │ │ - this.showToggle(true); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + update: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: showToggle │ │ │ │ │ - * Hide/Show the toggle depending on whether the control is minimized │ │ │ │ │ + * APIMethod: delete │ │ │ │ │ + * Construct a request deleting a removed feature. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * minimize - {Boolean} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - showToggle: function(minimize) { │ │ │ │ │ - if (this.maximizeDiv) { │ │ │ │ │ - this.maximizeDiv.style.display = minimize ? '' : 'none'; │ │ │ │ │ - } │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.minimizeDiv.style.display = minimize ? 'none' : ''; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + "delete": function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Update the overview map after layers move. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - if (this.ovmap == null) { │ │ │ │ │ - this.createMap(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.autoPan || !this.isSuitableOverview()) { │ │ │ │ │ - this.updateOverview(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // update extent rectangle │ │ │ │ │ - this.updateRectToMap(); │ │ │ │ │ - }, │ │ │ │ │ + commit: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isSuitableOverview │ │ │ │ │ - * Determines if the overview map is suitable given the extent and │ │ │ │ │ - * resolution of the main map. │ │ │ │ │ + * Method: abort │ │ │ │ │ + * Abort an ongoing request. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * response - {} │ │ │ │ │ */ │ │ │ │ │ - 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))); │ │ │ │ │ - }, │ │ │ │ │ + abort: function(response) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method updateOverview │ │ │ │ │ - * Called by if returns true │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + 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({ │ │ │ │ │ /** │ │ │ │ │ - * Method: createMap │ │ │ │ │ - * Construct the map that this control contains │ │ │ │ │ + * Property: code │ │ │ │ │ + * {Number} - OpenLayers.Protocol.Response.SUCCESS or │ │ │ │ │ + * OpenLayers.Protocol.Response.FAILURE │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + code: null, │ │ │ │ │ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * Property: requestType │ │ │ │ │ + * {String} The type of request this response corresponds to. Either │ │ │ │ │ + * "create", "read", "update" or "delete". │ │ │ │ │ + */ │ │ │ │ │ + requestType: null, │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: last │ │ │ │ │ + * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ + * false otherwise, defaults to true. │ │ │ │ │ + */ │ │ │ │ │ + last: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateRectToMap │ │ │ │ │ - * Updates the extent rectangle position and size to match the map extent │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + features: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateMapToRect │ │ │ │ │ - * Updates the map extent to match the extent rectangle position and size │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ - }, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setRectPxBounds │ │ │ │ │ - * Set extent rectangle pixel bounds. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pxBounds - {} │ │ │ │ │ + * Property: reqFeatures │ │ │ │ │ + * {Array({})} or {} │ │ │ │ │ + * The features provided by the user and placed in the request by the │ │ │ │ │ + * protocol. │ │ │ │ │ */ │ │ │ │ │ - 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) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + reqFeatures: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: priv │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + priv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Property: error │ │ │ │ │ + * {Object} The error object in case a service exception was encountered. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + error: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromOverviewPx │ │ │ │ │ - * Get a map location from a pixel location │ │ │ │ │ + * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getOverviewPxFromLonLat │ │ │ │ │ - * Get a pixel location from a map location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * Method: success │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Location which is the passed-in OpenLayers.LonLat, │ │ │ │ │ - * translated into overview map pixels │ │ │ │ │ + * {Boolean} - true on success, false otherwise │ │ │ │ │ */ │ │ │ │ │ - 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)) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ + success: function() { │ │ │ │ │ + return this.code > 0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: 'OpenLayers.Control.OverviewMap' │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol.Response" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Protocol.Response.SUCCESS = 1; │ │ │ │ │ +OpenLayers.Protocol.Response.FAILURE = 0; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Vector.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/Layer.js │ │ │ │ │ - * @requires OpenLayers/Renderer.js │ │ │ │ │ - * @requires OpenLayers/StyleMap.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Vector │ │ │ │ │ - * Instances of OpenLayers.Layer.Vector are used to render vector data from │ │ │ │ │ - * a variety of sources. Create a new vector layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Strategy │ │ │ │ │ + * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the strategy subclasses instead. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 (in addition to those from ): │ │ │ │ │ - * beforefeatureadded - Triggered before a feature is added. Listeners │ │ │ │ │ - * will receive an object with a *feature* property referencing the │ │ │ │ │ - * feature to be added. To stop the feature from being added, a │ │ │ │ │ - * listener should return false. │ │ │ │ │ - * beforefeaturesadded - Triggered before an array of features is added. │ │ │ │ │ - * Listeners will receive an object with a *features* property │ │ │ │ │ - * referencing the feature to be added. To stop the features from │ │ │ │ │ - * being added, a listener should return false. │ │ │ │ │ - * featureadded - Triggered after a feature is added. The event │ │ │ │ │ - * object passed to listeners will have a *feature* property with a │ │ │ │ │ - * reference to the added feature. │ │ │ │ │ - * featuresadded - Triggered after features are added. The event │ │ │ │ │ - * object passed to listeners will have a *features* property with a │ │ │ │ │ - * reference to an array of added features. │ │ │ │ │ - * beforefeatureremoved - Triggered before a feature is removed. Listeners │ │ │ │ │ - * will receive an object with a *feature* property referencing the │ │ │ │ │ - * feature to be removed. │ │ │ │ │ - * beforefeaturesremoved - Triggered before multiple features are removed. │ │ │ │ │ - * Listeners will receive an object with a *features* property │ │ │ │ │ - * referencing the features to be removed. │ │ │ │ │ - * featureremoved - Triggerd after a feature is removed. The event │ │ │ │ │ - * object passed to listeners will have a *feature* property with a │ │ │ │ │ - * reference to the removed feature. │ │ │ │ │ - * featuresremoved - Triggered after features are removed. The event │ │ │ │ │ - * object passed to listeners will have a *features* property with a │ │ │ │ │ - * reference to an array of removed features. │ │ │ │ │ - * beforefeatureselected - Triggered before a feature is selected. Listeners │ │ │ │ │ - * will receive an object with a *feature* property referencing the │ │ │ │ │ - * feature to be selected. To stop the feature from being selectd, a │ │ │ │ │ - * listener should return false. │ │ │ │ │ - * featureselected - Triggered after a feature is selected. Listeners │ │ │ │ │ - * will receive an object with a *feature* property referencing the │ │ │ │ │ - * selected feature. │ │ │ │ │ - * featureunselected - Triggered after a feature is unselected. │ │ │ │ │ - * Listeners will receive an object with a *feature* property │ │ │ │ │ - * referencing the unselected feature. │ │ │ │ │ - * beforefeaturemodified - Triggered when a feature is selected to │ │ │ │ │ - * be modified. Listeners will receive an object with a *feature* │ │ │ │ │ - * property referencing the selected feature. │ │ │ │ │ - * featuremodified - Triggered when a feature has been modified. │ │ │ │ │ - * Listeners will receive an object with a *feature* property referencing │ │ │ │ │ - * the modified feature. │ │ │ │ │ - * afterfeaturemodified - Triggered when a feature is finished being modified. │ │ │ │ │ - * Listeners will receive an object with a *feature* property referencing │ │ │ │ │ - * the modified feature. │ │ │ │ │ - * vertexmodified - Triggered when a vertex within any feature geometry │ │ │ │ │ - * has been modified. Listeners will receive an object with a │ │ │ │ │ - * *feature* property referencing the modified feature, a *vertex* │ │ │ │ │ - * property referencing the vertex modified (always a point geometry), │ │ │ │ │ - * and a *pixel* property referencing the pixel location of the │ │ │ │ │ - * modification. │ │ │ │ │ - * vertexremoved - Triggered when a vertex within any feature geometry │ │ │ │ │ - * has been deleted. Listeners will receive an object with a │ │ │ │ │ - * *feature* property referencing the modified feature, a *vertex* │ │ │ │ │ - * property referencing the vertex modified (always a point geometry), │ │ │ │ │ - * and a *pixel* property referencing the pixel location of the │ │ │ │ │ - * removal. │ │ │ │ │ - * sketchstarted - Triggered when a feature sketch bound for this layer │ │ │ │ │ - * is started. Listeners will receive an object with a *feature* │ │ │ │ │ - * property referencing the new sketch feature and a *vertex* property │ │ │ │ │ - * referencing the creation point. │ │ │ │ │ - * sketchmodified - Triggered when a feature sketch bound for this layer │ │ │ │ │ - * is modified. Listeners will receive an object with a *vertex* │ │ │ │ │ - * property referencing the modified vertex and a *feature* property │ │ │ │ │ - * referencing the sketch feature. │ │ │ │ │ - * sketchcomplete - Triggered when a feature sketch bound for this layer │ │ │ │ │ - * is complete. Listeners will receive an object with a *feature* │ │ │ │ │ - * property referencing the sketch feature. By returning false, a │ │ │ │ │ - * listener can stop the sketch feature from being added to the layer. │ │ │ │ │ - * refresh - Triggered when something wants a strategy to ask the protocol │ │ │ │ │ - * for a new set of features. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The layer this strategy belongs to. │ │ │ │ │ */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer is a base layer. Default is false. Set this property │ │ │ │ │ - * in the layer options. │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isFixed │ │ │ │ │ - * {Boolean} Whether the layer remains in one place while dragging the │ │ │ │ │ - * map. Note that setting this to true will move the layer to the bottom │ │ │ │ │ - * of the layer stack. │ │ │ │ │ - */ │ │ │ │ │ - isFixed: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: features │ │ │ │ │ - * {Array()} │ │ │ │ │ - */ │ │ │ │ │ - features: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} The filter set in this layer, │ │ │ │ │ - * a strategy launching read requests can combined │ │ │ │ │ - * this filter with its own filter. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ */ │ │ │ │ │ - filter: null, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: selectedFeatures │ │ │ │ │ - * {Array()} │ │ │ │ │ + * Property: active │ │ │ │ │ + * {Boolean} The control is active. │ │ │ │ │ */ │ │ │ │ │ - selectedFeatures: null, │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: unrenderedFeatures │ │ │ │ │ - * {Object} hash of features, keyed by feature.id, that the renderer │ │ │ │ │ - * failed to draw │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - unrenderedFeatures: null, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: reportError │ │ │ │ │ - * {Boolean} report friendly error message when loading of renderer │ │ │ │ │ - * fails. │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ + * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - reportError: true, │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {Object} Default style for the layer │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - style: null, │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: styleMap │ │ │ │ │ - * {} │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up the strategy. │ │ │ │ │ */ │ │ │ │ │ - styleMap: null, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: strategies │ │ │ │ │ - * {Array(})} Optional list of strategies for the layer. │ │ │ │ │ + * Method: setLayer │ │ │ │ │ + * Called to set the property. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ */ │ │ │ │ │ - strategies: null, │ │ │ │ │ + setLayer: function(layer) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: protocol │ │ │ │ │ - * {} Optional protocol for the 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. │ │ │ │ │ */ │ │ │ │ │ - protocol: null, │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + this.active = true; │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: renderers │ │ │ │ │ - * {Array(String)} List of supported Renderer classes. Add to this list to │ │ │ │ │ - * add support for additional renderers. This list is ordered: │ │ │ │ │ - * the first renderer which returns true for the 'supported()' │ │ │ │ │ - * method will be used, if not defined in the 'renderer' option. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - renderers: ['SVG', 'VML', 'Canvas'], │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.active = false; │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: renderer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - renderer: null, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Strategy" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/StyleMap.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: rendererOptions │ │ │ │ │ - * {Object} Options for the renderer. See {} for │ │ │ │ │ - * supported options. │ │ │ │ │ - */ │ │ │ │ │ - rendererOptions: 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: geometryType │ │ │ │ │ - * {String} geometryType allows you to limit the types of geometries this │ │ │ │ │ - * layer supports. This should be set to something like │ │ │ │ │ - * "OpenLayers.Geometry.Point" to limit types. │ │ │ │ │ - */ │ │ │ │ │ - geometryType: null, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: drawn │ │ │ │ │ - * {Boolean} Whether the Vector Layer features have been drawn yet. │ │ │ │ │ +/** │ │ │ │ │ + * 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"). │ │ │ │ │ */ │ │ │ │ │ - drawn: false, │ │ │ │ │ + styles: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: ratio │ │ │ │ │ - * {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - ratio: 1, │ │ │ │ │ + extendDefault: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Vector │ │ │ │ │ - * Create a new vector layer │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.StyleMap │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * options - {Object} Optional object with non-default properties to set on │ │ │ │ │ - * the layer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A new vector layer │ │ │ │ │ + * 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(name, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - // allow user-set renderer, otherwise assign one │ │ │ │ │ - if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ - this.assignRenderer(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if no valid renderer found, display error │ │ │ │ │ - if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ - this.renderer = null; │ │ │ │ │ - this.displayError(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!this.styleMap) { │ │ │ │ │ - this.styleMap = new OpenLayers.StyleMap(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.features = []; │ │ │ │ │ - this.selectedFeatures = []; │ │ │ │ │ - this.unrenderedFeatures = {}; │ │ │ │ │ + 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"]) │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - // Allow for custom layer behavior │ │ │ │ │ - if (this.strategies) { │ │ │ │ │ - for (var i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ - this.strategies[i].setLayer(this); │ │ │ │ │ + // 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this layer │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - if (this.strategies) { │ │ │ │ │ - var strategy, i, len; │ │ │ │ │ - for (i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ - strategy = this.strategies[i]; │ │ │ │ │ - if (strategy.autoDestroy) { │ │ │ │ │ - strategy.destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.strategies = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.protocol) { │ │ │ │ │ - if (this.protocol.autoDestroy) { │ │ │ │ │ - this.protocol.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.protocol = null; │ │ │ │ │ - } │ │ │ │ │ - this.destroyFeatures(); │ │ │ │ │ - this.features = null; │ │ │ │ │ - this.selectedFeatures = null; │ │ │ │ │ - this.unrenderedFeatures = null; │ │ │ │ │ - if (this.renderer) { │ │ │ │ │ - this.renderer.destroy(); │ │ │ │ │ + for (var key in this.styles) { │ │ │ │ │ + this.styles[key].destroy(); │ │ │ │ │ } │ │ │ │ │ - this.renderer = null; │ │ │ │ │ - this.geometryType = null; │ │ │ │ │ - this.drawn = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ + this.styles = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer. │ │ │ │ │ + * 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). │ │ │ │ │ * │ │ │ │ │ - * Note: Features of the layer are also cloned. │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * {Object} symbolizer hash │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Vector(this.name, this.getOptions()); │ │ │ │ │ + createSymbolizer: function(feature, intent) { │ │ │ │ │ + if (!feature) { │ │ │ │ │ + feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - var features = this.features; │ │ │ │ │ - var len = features.length; │ │ │ │ │ - var clonedFeatures = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; ++i) { │ │ │ │ │ - clonedFeatures[i] = features[i].clone(); │ │ │ │ │ + if (!this.styles[intent]) { │ │ │ │ │ + intent = "default"; │ │ │ │ │ } │ │ │ │ │ - obj.features = clonedFeatures; │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + 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: refresh │ │ │ │ │ - * Ask the layer to request features again and redraw them. Triggers │ │ │ │ │ - * the refresh event if the layer is in range and visible. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * obj - {Object} Optional object with properties for any listener of │ │ │ │ │ - * the refresh event. │ │ │ │ │ + * renderIntent - {String} rendering intent to add the rules to │ │ │ │ │ + * property - {String} values of feature attributes to create the │ │ │ │ │ + * rules for │ │ │ │ │ + * symbolizers - {Object} Hash of symbolizers, keyed by the desired │ │ │ │ │ + * property values │ │ │ │ │ + * context - {Object} An optional object with properties that │ │ │ │ │ + * symbolizers' property values should be evaluated │ │ │ │ │ + * against. If no context is specified, feature.attributes │ │ │ │ │ + * will be used │ │ │ │ │ */ │ │ │ │ │ - refresh: function(obj) { │ │ │ │ │ - if (this.calculateInRange() && this.visibility) { │ │ │ │ │ - this.events.triggerEvent("refresh", obj); │ │ │ │ │ + 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: assignRenderer │ │ │ │ │ - * Iterates through the available renderer implementations and selects │ │ │ │ │ - * and assigns the first one whose "supported()" function returns true. │ │ │ │ │ + CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + 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/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: threshold │ │ │ │ │ + * In most cases changing the threshold isn't needed. │ │ │ │ │ + * In px/ms, default to 0. │ │ │ │ │ */ │ │ │ │ │ - assignRenderer: function() { │ │ │ │ │ - for (var i = 0, len = this.renderers.length; i < len; i++) { │ │ │ │ │ - var rendererClass = this.renderers[i]; │ │ │ │ │ - var renderer = (typeof rendererClass == "function") ? │ │ │ │ │ - rendererClass : │ │ │ │ │ - OpenLayers.Renderer[rendererClass]; │ │ │ │ │ - if (renderer && renderer.prototype.supported()) { │ │ │ │ │ - this.renderer = new renderer(this.div, this.rendererOptions); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + threshold: 0, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: displayError │ │ │ │ │ - * Let the user know their browser isn't supported. │ │ │ │ │ + /** │ │ │ │ │ + * Property: deceleration │ │ │ │ │ + * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ */ │ │ │ │ │ - displayError: function() { │ │ │ │ │ - if (this.reportError) { │ │ │ │ │ - OpenLayers.Console.userError(OpenLayers.i18n("browserNotSupported", { │ │ │ │ │ - renderers: this.renderers.join('\n') │ │ │ │ │ - })); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + deceleration: 0.0035, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * The layer has been added to the map. │ │ │ │ │ - * │ │ │ │ │ - * If there is no renderer set, the layer can't be used. Remove it. │ │ │ │ │ - * Otherwise, give the renderer a reference to the map and set its size. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: nbPoints │ │ │ │ │ + * {Integer} the number of points we use to calculate the kinetic │ │ │ │ │ + * initial values. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ + nbPoints: 100, │ │ │ │ │ │ │ │ │ │ - if (!this.renderer) { │ │ │ │ │ - this.map.removeLayer(this); │ │ │ │ │ - } else { │ │ │ │ │ - this.renderer.map = this.map; │ │ │ │ │ + /** │ │ │ │ │ + * Property: delay │ │ │ │ │ + * {Float} time to consider to calculate the kinetic initial values. │ │ │ │ │ + * In ms, default to 200. │ │ │ │ │ + */ │ │ │ │ │ + delay: 200, │ │ │ │ │ │ │ │ │ │ - var newSize = this.map.getSize(); │ │ │ │ │ - newSize.w = newSize.w * this.ratio; │ │ │ │ │ - newSize.h = newSize.h * this.ratio; │ │ │ │ │ - this.renderer.setSize(newSize); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: points │ │ │ │ │ + * List of points use to calculate the kinetic initial values. │ │ │ │ │ + */ │ │ │ │ │ + points: undefined, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: afterAdd │ │ │ │ │ - * Called at the end of the map.addLayer sequence. At this point, the map │ │ │ │ │ - * will have a base layer. Any autoActivate strategies will be │ │ │ │ │ - * activated here. │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * ID of the timer. │ │ │ │ │ */ │ │ │ │ │ - afterAdd: function() { │ │ │ │ │ - if (this.strategies) { │ │ │ │ │ - var strategy, i, len; │ │ │ │ │ - for (i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ - strategy = this.strategies[i]; │ │ │ │ │ - if (strategy.autoActivate) { │ │ │ │ │ - strategy.activate(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + timerId: undefined, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * The layer has been removed from the map. │ │ │ │ │ + * Constructor: OpenLayers.Kinetic │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - this.drawn = false; │ │ │ │ │ - if (this.strategies) { │ │ │ │ │ - var strategy, i, len; │ │ │ │ │ - for (i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ - strategy = this.strategies[i]; │ │ │ │ │ - if (strategy.autoActivate) { │ │ │ │ │ - strategy.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMapResize │ │ │ │ │ - * Notify the renderer of the change in size. │ │ │ │ │ - * │ │ │ │ │ + * Method: begin │ │ │ │ │ + * Begins the dragging. │ │ │ │ │ */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - OpenLayers.Layer.prototype.onMapResize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - var newSize = this.map.getSize(); │ │ │ │ │ - newSize.w = newSize.w * this.ratio; │ │ │ │ │ - newSize.h = newSize.h * this.ratio; │ │ │ │ │ - this.renderer.setSize(newSize); │ │ │ │ │ + begin: function() { │ │ │ │ │ + OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ + this.timerId = undefined; │ │ │ │ │ + this.points = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Reset the vector layer's div so that it once again is lined up with │ │ │ │ │ - * the map. Notify the renderer of the change of extent, and in the │ │ │ │ │ - * case of a change of zoom level (resolution), have the │ │ │ │ │ - * renderer redraw features. │ │ │ │ │ - * │ │ │ │ │ - * If the layer has not yet been drawn, cycle through the layer's │ │ │ │ │ - * features and draw each one. │ │ │ │ │ - * │ │ │ │ │ + * Method: update │ │ │ │ │ + * Updates during the dragging. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * xy - {} The new position. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - var coordSysUnchanged = true; │ │ │ │ │ - if (!dragging) { │ │ │ │ │ - this.renderer.root.style.visibility = 'hidden'; │ │ │ │ │ - │ │ │ │ │ - var viewSize = this.map.getSize(), │ │ │ │ │ - viewWidth = viewSize.w, │ │ │ │ │ - viewHeight = viewSize.h, │ │ │ │ │ - offsetLeft = (viewWidth / 2 * this.ratio) - viewWidth / 2, │ │ │ │ │ - offsetTop = (viewHeight / 2 * this.ratio) - viewHeight / 2; │ │ │ │ │ - offsetLeft += this.map.layerContainerOriginPx.x; │ │ │ │ │ - offsetLeft = -Math.round(offsetLeft); │ │ │ │ │ - offsetTop += this.map.layerContainerOriginPx.y; │ │ │ │ │ - offsetTop = -Math.round(offsetTop); │ │ │ │ │ - │ │ │ │ │ - this.div.style.left = offsetLeft + 'px'; │ │ │ │ │ - this.div.style.top = offsetTop + 'px'; │ │ │ │ │ - │ │ │ │ │ - var extent = this.map.getExtent().scale(this.ratio); │ │ │ │ │ - coordSysUnchanged = this.renderer.setExtent(extent, zoomChanged); │ │ │ │ │ - │ │ │ │ │ - this.renderer.root.style.visibility = 'visible'; │ │ │ │ │ - │ │ │ │ │ - // Force a reflow on gecko based browsers to prevent jump/flicker. │ │ │ │ │ - // This seems to happen on only certain configurations; it was originally │ │ │ │ │ - // noticed in FF 2.0 and Linux. │ │ │ │ │ - if (OpenLayers.IS_GECKO === true) { │ │ │ │ │ - this.div.scrollLeft = this.div.scrollLeft; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!zoomChanged && coordSysUnchanged) { │ │ │ │ │ - for (var i in this.unrenderedFeatures) { │ │ │ │ │ - var feature = this.unrenderedFeatures[i]; │ │ │ │ │ - this.drawFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (!this.drawn || zoomChanged || !coordSysUnchanged) { │ │ │ │ │ - this.drawn = true; │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = 0, len = this.features.length; i < len; i++) { │ │ │ │ │ - this.renderer.locked = (i !== (len - 1)); │ │ │ │ │ - feature = this.features[i]; │ │ │ │ │ - this.drawFeature(feature); │ │ │ │ │ - } │ │ │ │ │ + update: function(xy) { │ │ │ │ │ + this.points.unshift({ │ │ │ │ │ + xy: xy, │ │ │ │ │ + tick: new Date().getTime() │ │ │ │ │ + }); │ │ │ │ │ + if (this.points.length > this.nbPoints) { │ │ │ │ │ + this.points.pop(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: display │ │ │ │ │ - * Hide or show the Layer │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: end │ │ │ │ │ + * Ends the dragging, start the kinetic. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - OpenLayers.Layer.prototype.display.apply(this, arguments); │ │ │ │ │ - // we need to set the display style of the root in case it is attached │ │ │ │ │ - // to a foreign layer │ │ │ │ │ - var currentDisplay = this.div.style.display; │ │ │ │ │ - if (currentDisplay != this.renderer.root.style.display) { │ │ │ │ │ - this.renderer.root.style.display = currentDisplay; │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addFeatures │ │ │ │ │ - * Add Features to the layer. │ │ │ │ │ + * Method: move │ │ │ │ │ + * Launch the kinetic move pan. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * 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). │ │ │ │ │ */ │ │ │ │ │ - addFeatures: function(features, options) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ - } │ │ │ │ │ + move: function(info, callback) { │ │ │ │ │ + var v0 = info.speed; │ │ │ │ │ + var fx = Math.cos(info.theta); │ │ │ │ │ + var fy = -Math.sin(info.theta); │ │ │ │ │ │ │ │ │ │ - var notify = !options || !options.silent; │ │ │ │ │ - if (notify) { │ │ │ │ │ - var event = { │ │ │ │ │ - features: features │ │ │ │ │ - }; │ │ │ │ │ - var ret = this.events.triggerEvent("beforefeaturesadded", event); │ │ │ │ │ - if (ret === false) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - features = event.features; │ │ │ │ │ - } │ │ │ │ │ + var initialTime = new Date().getTime(); │ │ │ │ │ │ │ │ │ │ - // Track successfully added features for featuresadded event, since │ │ │ │ │ - // beforefeatureadded can veto single features. │ │ │ │ │ - var featuresAdded = []; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; i++) { │ │ │ │ │ - if (i != (features.length - 1)) { │ │ │ │ │ - this.renderer.locked = true; │ │ │ │ │ - } else { │ │ │ │ │ - this.renderer.locked = false; │ │ │ │ │ - } │ │ │ │ │ - var feature = features[i]; │ │ │ │ │ + var lastX = 0; │ │ │ │ │ + var lastY = 0; │ │ │ │ │ │ │ │ │ │ - if (this.geometryType && │ │ │ │ │ - !(feature.geometry instanceof this.geometryType)) { │ │ │ │ │ - throw new TypeError('addFeatures: component should be an ' + │ │ │ │ │ - this.geometryType.prototype.CLASS_NAME); │ │ │ │ │ + var timerCallback = function() { │ │ │ │ │ + if (this.timerId == null) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //give feature reference to its layer │ │ │ │ │ - feature.layer = this; │ │ │ │ │ - │ │ │ │ │ - if (!feature.style && this.style) { │ │ │ │ │ - feature.style = OpenLayers.Util.extend({}, this.style); │ │ │ │ │ - } │ │ │ │ │ + var t = new Date().getTime() - initialTime; │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - if (this.events.triggerEvent("beforefeatureadded", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }) === false) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - this.preFeatureInsert(feature); │ │ │ │ │ - } │ │ │ │ │ + var p = (-this.deceleration * Math.pow(t, 2)) / 2.0 + v0 * t; │ │ │ │ │ + var x = p * fx; │ │ │ │ │ + var y = p * fy; │ │ │ │ │ │ │ │ │ │ - featuresAdded.push(feature); │ │ │ │ │ - this.features.push(feature); │ │ │ │ │ - this.drawFeature(feature); │ │ │ │ │ + var args = {}; │ │ │ │ │ + args.end = false; │ │ │ │ │ + var v = -this.deceleration * t + v0; │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featureadded", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - this.onFeatureInsert(feature); │ │ │ │ │ + if (v <= 0) { │ │ │ │ │ + OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + args.end = true; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featuresadded", { │ │ │ │ │ - features: featuresAdded │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeFeatures │ │ │ │ │ - * Remove features from the layer. This erases any drawn features and │ │ │ │ │ - * removes them from the layer's control. The beforefeatureremoved │ │ │ │ │ - * and featureremoved events will be triggered for each feature. The │ │ │ │ │ - * featuresremoved event will be triggered after all features have │ │ │ │ │ - * been removed. To supress event triggering, use the silent option. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array()} List of features to be │ │ │ │ │ - * removed. │ │ │ │ │ - * options - {Object} Optional properties for changing behavior of the │ │ │ │ │ - * removal. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * silent - {Boolean} Supress event triggering. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - removeFeatures: function(features, options) { │ │ │ │ │ - if (!features || features.length === 0) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (features === this.features) { │ │ │ │ │ - return this.removeAllFeatures(options); │ │ │ │ │ - } │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ - } │ │ │ │ │ - if (features === this.selectedFeatures) { │ │ │ │ │ - features = features.slice(); │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - var notify = !options || !options.silent; │ │ │ │ │ - │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent( │ │ │ │ │ - "beforefeaturesremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + args.x = x - lastX; │ │ │ │ │ + args.y = y - lastY; │ │ │ │ │ + lastX = x; │ │ │ │ │ + lastY = y; │ │ │ │ │ + callback(args.x, args.y, args.end); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - for (var i = features.length - 1; i >= 0; i--) { │ │ │ │ │ - // We remain locked so long as we're not at 0 │ │ │ │ │ - // and the 'next' feature has a geometry. We do the geometry check │ │ │ │ │ - // because if all the features after the current one are 'null', we │ │ │ │ │ - // won't call eraseGeometry, so we break the 'renderer functions │ │ │ │ │ - // will always be called with locked=false *last*' rule. The end result │ │ │ │ │ - // is a possible gratiutious unlocking to save a loop through the rest │ │ │ │ │ - // of the list checking the remaining features every time. So long as │ │ │ │ │ - // null geoms are rare, this is probably okay. │ │ │ │ │ - if (i != 0 && features[i - 1].geometry) { │ │ │ │ │ - this.renderer.locked = true; │ │ │ │ │ - } else { │ │ │ │ │ - this.renderer.locked = false; │ │ │ │ │ - } │ │ │ │ │ + this.timerId = OpenLayers.Animation.start( │ │ │ │ │ + OpenLayers.Function.bind(timerCallback, this) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var feature = features[i]; │ │ │ │ │ - delete this.unrenderedFeatures[feature.id]; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Kinetic" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Events/featureclick.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("beforefeatureremoved", { │ │ │ │ │ - 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. */ │ │ │ │ │ │ │ │ │ │ - this.features = OpenLayers.Util.removeItem(this.features, feature); │ │ │ │ │ - // feature has no layer at this point │ │ │ │ │ - feature.layer = null; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - this.renderer.eraseFeatures(feature); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Events.featureclick │ │ │ │ │ + * │ │ │ │ │ + * Extension event type for handling feature click events, including overlapping │ │ │ │ │ + * features. │ │ │ │ │ + * │ │ │ │ │ + * Event types provided by this extension: │ │ │ │ │ + * - featureclick │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Events.featureclick = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - //in the case that this feature is one of the selected features, │ │ │ │ │ - // remove it from that array as well. │ │ │ │ │ - if (OpenLayers.Util.indexOf(this.selectedFeatures, feature) != -1) { │ │ │ │ │ - OpenLayers.Util.removeItem(this.selectedFeatures, feature); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: cache │ │ │ │ │ + * {Object} A cache of features under the mouse. │ │ │ │ │ + */ │ │ │ │ │ + cache: null, │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featureremoved", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} The map to register browser events on. │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featuresremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: provides │ │ │ │ │ + * {Array(String)} The event types provided by this extension. │ │ │ │ │ + */ │ │ │ │ │ + provides: ["featureclick", "nofeatureclick", "featureover", "featureout"], │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeAllFeatures │ │ │ │ │ - * Remove all features from the layer. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Events.featureclick │ │ │ │ │ + * Create a new featureclick event type. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional properties for changing behavior of the │ │ │ │ │ - * removal. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * silent - {Boolean} Supress event triggering. Default is false. │ │ │ │ │ + * target - {} The events instance to create the events │ │ │ │ │ + * for. │ │ │ │ │ */ │ │ │ │ │ - removeAllFeatures: function(options) { │ │ │ │ │ - var notify = !options || !options.silent; │ │ │ │ │ - var features = this.features; │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent( │ │ │ │ │ - "beforefeaturesremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = features.length - 1; i >= 0; i--) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("beforefeatureremoved", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - feature.layer = null; │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featureremoved", { │ │ │ │ │ - feature: feature │ │ │ │ │ + initialize: function(target) { │ │ │ │ │ + this.target = target; │ │ │ │ │ + if (target.object instanceof OpenLayers.Map) { │ │ │ │ │ + this.setMap(target.object); │ │ │ │ │ + } else if (target.object instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ + if (target.object.map) { │ │ │ │ │ + this.setMap(target.object.map); │ │ │ │ │ + } else { │ │ │ │ │ + target.object.events.register("added", this, function(evt) { │ │ │ │ │ + this.setMap(target.object.map); │ │ │ │ │ }); │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + throw ("Listeners for '" + this.provides.join("', '") + │ │ │ │ │ + "' events can only be registered for OpenLayers.Layer.Vector " + │ │ │ │ │ + "or OpenLayers.Map instances"); │ │ │ │ │ } │ │ │ │ │ - this.renderer.clear(); │ │ │ │ │ - this.features = []; │ │ │ │ │ - this.unrenderedFeatures = {}; │ │ │ │ │ - this.selectedFeatures = []; │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featuresremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ + for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ + target.extensions[this.provides[i]] = true; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroyFeatures │ │ │ │ │ - * Erase and destroy features on the layer. │ │ │ │ │ + * Method: setMap │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} An optional array of │ │ │ │ │ - * features to destroy. If not supplied, all features on the layer │ │ │ │ │ - * will be destroyed. │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * map - {} The map to register browser events on. │ │ │ │ │ */ │ │ │ │ │ - destroyFeatures: function(features, options) { │ │ │ │ │ - var all = (features == undefined); // evaluates to true if │ │ │ │ │ - // features is null │ │ │ │ │ - if (all) { │ │ │ │ │ - features = this.features; │ │ │ │ │ - } │ │ │ │ │ - if (features) { │ │ │ │ │ - this.removeFeatures(features, options); │ │ │ │ │ - for (var i = features.length - 1; i >= 0; i--) { │ │ │ │ │ - features[i].destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + this.cache = {}; │ │ │ │ │ + map.events.register("mousedown", this, this.start, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + map.events.register("mouseup", this, this.onClick, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + map.events.register("touchstart", this, this.start, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + map.events.register("touchmove", this, this.cancel, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + map.events.register("touchend", this, this.onClick, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + map.events.register("mousemove", this, this.onMousemove, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: drawFeature │ │ │ │ │ - * Draw (or redraw) a feature on the layer. If the optional style argument │ │ │ │ │ - * is included, this style will be used. If no style is included, the │ │ │ │ │ - * feature's style will be used. If the feature doesn't have a style, │ │ │ │ │ - * the layer's style will be used. │ │ │ │ │ - * │ │ │ │ │ - * This function is not designed to be used when adding features to │ │ │ │ │ - * the layer (use addFeatures instead). It is meant to be used when │ │ │ │ │ - * the style of a feature has changed, or in some other way needs to │ │ │ │ │ - * visually updated *after* it has already been added to a layer. You │ │ │ │ │ - * must add the feature to the layer for most layer-related events to │ │ │ │ │ - * happen. │ │ │ │ │ + * Method: start │ │ │ │ │ + * Sets startEvt = evt. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * style - {String | Object} Named render intent or full symbolizer object. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function(feature, style) { │ │ │ │ │ - // don't try to draw the feature with the renderer if the layer is not │ │ │ │ │ - // drawn itself │ │ │ │ │ - if (!this.drawn) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (typeof style != "object") { │ │ │ │ │ - if (!style && feature.state === OpenLayers.State.DELETE) { │ │ │ │ │ - style = "delete"; │ │ │ │ │ - } │ │ │ │ │ - var renderIntent = style || feature.renderIntent; │ │ │ │ │ - style = feature.style || this.style; │ │ │ │ │ - if (!style) { │ │ │ │ │ - style = this.styleMap.createSymbolizer(feature, renderIntent); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var drawn = this.renderer.drawFeature(feature, style); │ │ │ │ │ - //TODO remove the check for null when we get rid of Renderer.SVG │ │ │ │ │ - if (drawn === false || drawn === null) { │ │ │ │ │ - this.unrenderedFeatures[feature.id] = feature; │ │ │ │ │ - } else { │ │ │ │ │ - delete this.unrenderedFeatures[feature.id]; │ │ │ │ │ - } │ │ │ │ │ + start: function(evt) { │ │ │ │ │ + this.startEvt = evt; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: eraseFeatures │ │ │ │ │ - * Erase features from the layer. │ │ │ │ │ + * Method: cancel │ │ │ │ │ + * Deletes the start event. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - eraseFeatures: function(features) { │ │ │ │ │ - this.renderer.eraseFeatures(features); │ │ │ │ │ + cancel: function(evt) { │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureFromEvent │ │ │ │ │ - * Given an event, return a feature if the event occurred over one. │ │ │ │ │ - * Otherwise, return null. │ │ │ │ │ + * Method: onClick │ │ │ │ │ + * Listener for the click event. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature if one was under the event. │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - getFeatureFromEvent: function(evt) { │ │ │ │ │ - if (!this.renderer) { │ │ │ │ │ - throw new Error('getFeatureFromEvent called on layer with no ' + │ │ │ │ │ - 'renderer. This usually means you destroyed a ' + │ │ │ │ │ - 'layer, but not some handler which is associated ' + │ │ │ │ │ - 'with it.'); │ │ │ │ │ + onClick: function(evt) { │ │ │ │ │ + if (!this.startEvt || evt.type !== "touchend" && │ │ │ │ │ + !OpenLayers.Event.isLeftClick(evt)) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - var feature = null; │ │ │ │ │ - var featureId = this.renderer.getFeatureIdFromEvent(evt); │ │ │ │ │ - if (featureId) { │ │ │ │ │ - if (typeof featureId === "string") { │ │ │ │ │ - feature = this.getFeatureById(featureId); │ │ │ │ │ - } else { │ │ │ │ │ - feature = featureId; │ │ │ │ │ + var features = this.getFeatures(this.startEvt); │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ + // fire featureclick events │ │ │ │ │ + var feature, layer, more, clicked = {}; │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + layer = feature.layer; │ │ │ │ │ + clicked[layer.id] = true; │ │ │ │ │ + more = this.triggerEvent("featureclick", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + if (more === false) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // fire nofeatureclick events on all vector layers with no targets │ │ │ │ │ + for (i = 0, len = this.map.layers.length; i < len; ++i) { │ │ │ │ │ + layer = this.map.layers[i]; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Vector && !clicked[layer.id]) { │ │ │ │ │ + this.triggerEvent("nofeatureclick", { │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return feature; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getFeatureBy │ │ │ │ │ - * Given a property value, return the feature if it exists in the features array │ │ │ │ │ + * Method: onMousemove │ │ │ │ │ + * Listener for the mousemove event. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * property - {String} │ │ │ │ │ - * value - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature corresponding to the given │ │ │ │ │ - * property value or null if there is no such feature. │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - getFeatureBy: function(property, value) { │ │ │ │ │ - //TBD - would it be more efficient to use a hash for this.features? │ │ │ │ │ - var feature = null; │ │ │ │ │ - for (var i = 0, len = this.features.length; i < len; ++i) { │ │ │ │ │ - if (this.features[i][property] == value) { │ │ │ │ │ - feature = this.features[i]; │ │ │ │ │ + onMousemove: function(evt) { │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ + var features = this.getFeatures(evt); │ │ │ │ │ + var over = {}, │ │ │ │ │ + newly = [], │ │ │ │ │ + feature; │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + over[feature.id] = feature; │ │ │ │ │ + if (!this.cache[feature.id]) { │ │ │ │ │ + newly.push(feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // check if already over features │ │ │ │ │ + var out = []; │ │ │ │ │ + for (var id in this.cache) { │ │ │ │ │ + feature = this.cache[id]; │ │ │ │ │ + if (feature.layer && feature.layer.map) { │ │ │ │ │ + if (!over[feature.id]) { │ │ │ │ │ + out.push(feature); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // removed │ │ │ │ │ + delete this.cache[id]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // fire featureover events │ │ │ │ │ + var more; │ │ │ │ │ + for (i = 0, len = newly.length; i < len; ++i) { │ │ │ │ │ + feature = newly[i]; │ │ │ │ │ + this.cache[feature.id] = feature; │ │ │ │ │ + more = this.triggerEvent("featureover", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + if (more === false) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // fire featureout events │ │ │ │ │ + for (i = 0, len = out.length; i < len; ++i) { │ │ │ │ │ + feature = out[i]; │ │ │ │ │ + delete this.cache[feature.id]; │ │ │ │ │ + more = this.triggerEvent("featureout", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + if (more === false) { │ │ │ │ │ break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return feature; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getFeatureById │ │ │ │ │ - * Given a feature id, return the feature if it exists in the features array │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featureId - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature corresponding to the given │ │ │ │ │ - * featureId or null if there is no such feature. │ │ │ │ │ - */ │ │ │ │ │ - getFeatureById: function(featureId) { │ │ │ │ │ - return this.getFeatureBy('id', featureId); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getFeatureByFid │ │ │ │ │ - * Given a feature fid, return the feature if it exists in the features array │ │ │ │ │ + * Method: triggerEvent │ │ │ │ │ + * Determines where to trigger the event and triggers it. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * featureFid - {String} │ │ │ │ │ + * type - {String} The event type to trigger │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A feature corresponding to the given │ │ │ │ │ - * featureFid or null if there is no such feature. │ │ │ │ │ + * {Boolean} The last listener return. │ │ │ │ │ */ │ │ │ │ │ - getFeatureByFid: function(featureFid) { │ │ │ │ │ - return this.getFeatureBy('fid', featureFid); │ │ │ │ │ + triggerEvent: function(type, evt) { │ │ │ │ │ + var layer = evt.feature ? evt.feature.layer : evt.layer, │ │ │ │ │ + object = this.target.object; │ │ │ │ │ + if (object instanceof OpenLayers.Map || object === layer) { │ │ │ │ │ + return this.target.triggerEvent(type, evt); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getFeaturesByAttribute │ │ │ │ │ - * Returns an array of features that have the given attribute key set to the │ │ │ │ │ - * given value. Comparison of attribute values takes care of datatypes, e.g. │ │ │ │ │ - * the string '1234' is not equal to the number 1234. │ │ │ │ │ + * Method: getFeatures │ │ │ │ │ + * Get all features at the given screen location. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * attrName - {String} │ │ │ │ │ - * attrValue - {Mixed} │ │ │ │ │ + * evt - {Object} Event object. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * Array({}) An array of features that have the │ │ │ │ │ - * passed named attribute set to the given value. │ │ │ │ │ + * {Array()} List of features at the given point. │ │ │ │ │ */ │ │ │ │ │ - getFeaturesByAttribute: function(attrName, attrValue) { │ │ │ │ │ - var i, │ │ │ │ │ - feature, │ │ │ │ │ - len = this.features.length, │ │ │ │ │ - foundFeatures = []; │ │ │ │ │ - for (i = 0; i < len; i++) { │ │ │ │ │ - feature = this.features[i]; │ │ │ │ │ - if (feature && feature.attributes) { │ │ │ │ │ - if (feature.attributes[attrName] === attrValue) { │ │ │ │ │ - foundFeatures.push(feature); │ │ │ │ │ + getFeatures: function(evt) { │ │ │ │ │ + var x = evt.clientX, │ │ │ │ │ + y = evt.clientY, │ │ │ │ │ + features = [], │ │ │ │ │ + targets = [], │ │ │ │ │ + layers = [], │ │ │ │ │ + layer, target, feature, i, len; │ │ │ │ │ + // go through all layers looking for targets │ │ │ │ │ + for (i = this.map.layers.length - 1; i >= 0; --i) { │ │ │ │ │ + layer = this.map.layers[i]; │ │ │ │ │ + if (layer.div.style.display !== "none") { │ │ │ │ │ + if (layer.renderer instanceof OpenLayers.Renderer.Elements) { │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ + target = document.elementFromPoint(x, y); │ │ │ │ │ + while (target && target._featureId) { │ │ │ │ │ + feature = layer.getFeatureById(target._featureId); │ │ │ │ │ + if (feature) { │ │ │ │ │ + features.push(feature); │ │ │ │ │ + target.style.display = "none"; │ │ │ │ │ + targets.push(target); │ │ │ │ │ + target = document.elementFromPoint(x, y); │ │ │ │ │ + } else { │ │ │ │ │ + // sketch, all bets off │ │ │ │ │ + target = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + layer.div.style.display = "none"; │ │ │ │ │ + } else if (layer.renderer instanceof OpenLayers.Renderer.Canvas) { │ │ │ │ │ + feature = layer.renderer.getFeatureIdFromEvent(evt); │ │ │ │ │ + if (feature) { │ │ │ │ │ + features.push(feature); │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return foundFeatures; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Unselect the selected features │ │ │ │ │ - * i.e. clears the featureSelection array │ │ │ │ │ - * change the style back │ │ │ │ │ - clearSelection: function() { │ │ │ │ │ - │ │ │ │ │ - var vectorLayer = this.map.vectorLayer; │ │ │ │ │ - for (var i = 0; i < this.map.featureSelection.length; i++) { │ │ │ │ │ - var featureSelection = this.map.featureSelection[i]; │ │ │ │ │ - vectorLayer.drawFeature(featureSelection, vectorLayer.style); │ │ │ │ │ + // restore feature visibility │ │ │ │ │ + for (i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ + targets[i].style.display = ""; │ │ │ │ │ } │ │ │ │ │ - this.map.featureSelection = []; │ │ │ │ │ + // restore layer visibility │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + layers[i].div.style.display = "block"; │ │ │ │ │ + } │ │ │ │ │ + return features; │ │ │ │ │ }, │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: onFeatureInsert │ │ │ │ │ - * method called after a feature is inserted. │ │ │ │ │ - * Does nothing by default. Override this if you │ │ │ │ │ - * need to do something on feature updates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - onFeatureInsert: function(feature) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: preFeatureInsert │ │ │ │ │ - * method called before a feature is inserted. │ │ │ │ │ - * Does nothing by default. Override this if you │ │ │ │ │ - * need to do something when features are first added to the │ │ │ │ │ - * layer, but before they are drawn, such as adjust the style. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - preFeatureInsert: function(feature) {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the features. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} or null if the layer has no features with │ │ │ │ │ - * geometries. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up. │ │ │ │ │ */ │ │ │ │ │ - getDataExtent: function() { │ │ │ │ │ - var maxExtent = null; │ │ │ │ │ - var features = this.features; │ │ │ │ │ - if (features && (features.length > 0)) { │ │ │ │ │ - var geometry = null; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; i++) { │ │ │ │ │ - geometry = features[i].geometry; │ │ │ │ │ - if (geometry) { │ │ │ │ │ - if (maxExtent === null) { │ │ │ │ │ - maxExtent = new OpenLayers.Bounds(); │ │ │ │ │ - } │ │ │ │ │ - maxExtent.extend(geometry.getBounds()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ + delete this.target.extensions[this.provides[i]]; │ │ │ │ │ } │ │ │ │ │ - return maxExtent; │ │ │ │ │ - }, │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + mousemove: this.onMousemove, │ │ │ │ │ + mousedown: this.start, │ │ │ │ │ + mouseup: this.onClick, │ │ │ │ │ + touchstart: this.start, │ │ │ │ │ + touchmove: this.cancel, │ │ │ │ │ + touchend: this.onClick, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + delete this.cache; │ │ │ │ │ + delete this.map; │ │ │ │ │ + delete this.target; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Vector" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Events.nofeatureclick │ │ │ │ │ + * │ │ │ │ │ + * Extension event type for handling click events that do not hit a feature. │ │ │ │ │ + * │ │ │ │ │ + * Event types provided by this extension: │ │ │ │ │ + * - nofeatureclick │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Events.nofeatureclick = OpenLayers.Events.featureclick; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Events.featureover │ │ │ │ │ + * │ │ │ │ │ + * Extension event type for handling hovering over a feature. │ │ │ │ │ + * │ │ │ │ │ + * Event types provided by this extension: │ │ │ │ │ + * - featureover │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Events.featureover = OpenLayers.Events.featureclick; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Events.featureout │ │ │ │ │ + * │ │ │ │ │ + * Extension event type for handling leaving a feature. │ │ │ │ │ + * │ │ │ │ │ + * Event types provided by this extension: │ │ │ │ │ + * - featureout │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Events.featureout = OpenLayers.Events.featureclick; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Graticule.js │ │ │ │ │ + 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 │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - * @requires OpenLayers/Rule.js │ │ │ │ │ - * @requires OpenLayers/StyleMap.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Graticule │ │ │ │ │ - * The Graticule displays a grid of latitude/longitude lines reprojected on │ │ │ │ │ - * the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Events.buttonclick │ │ │ │ │ + * Extension event type for handling buttons on top of a dom element. This │ │ │ │ │ + * event type fires "buttonclick" on its when a button was │ │ │ │ │ + * clicked. Buttons are detected by the "olButton" class. │ │ │ │ │ + * │ │ │ │ │ + * This event type makes sure that button clicks do not interfere with other │ │ │ │ │ + * events that are registered on the same . │ │ │ │ │ + * │ │ │ │ │ + * Event types provided by this extension: │ │ │ │ │ + * - *buttonclick* Triggered when a button is clicked. Listeners receive an │ │ │ │ │ + * object with a *buttonElement* property referencing the dom element of │ │ │ │ │ + * the clicked button, and an *buttonXY* property with the click position │ │ │ │ │ + * relative to the button. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Events.buttonclick = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: target │ │ │ │ │ + * {} The events instance that the buttonclick event will │ │ │ │ │ + * be triggered on. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + target: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: intervals │ │ │ │ │ - * {Array(Float)} A list of possible graticule widths in degrees. │ │ │ │ │ + * Property: events │ │ │ │ │ + * {Array} Events to observe and conditionally stop from propagating when │ │ │ │ │ + * an element with the olButton class (or its olAlphaImg child) is │ │ │ │ │ + * clicked. │ │ │ │ │ */ │ │ │ │ │ - intervals: [45, 30, 20, 10, 5, 2, 1, │ │ │ │ │ - 0.5, 0.2, 0.1, 0.05, 0.01, │ │ │ │ │ - 0.005, 0.002, 0.001 │ │ │ │ │ + events: [ │ │ │ │ │ + 'mousedown', 'mouseup', 'click', 'dblclick', │ │ │ │ │ + 'touchstart', 'touchmove', 'touchend', 'keydown' │ │ │ │ │ ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Allows the Graticule control to be switched on and off by │ │ │ │ │ - * LayerSwitcher control. Defaults is true. │ │ │ │ │ - */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: visible │ │ │ │ │ - * {Boolean} should the graticule be initially visible (default=true) │ │ │ │ │ - */ │ │ │ │ │ - visible: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: targetSize │ │ │ │ │ - * {Integer} The maximum size of the grid in pixels on the map │ │ │ │ │ - */ │ │ │ │ │ - targetSize: 200, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {String} The name to be displayed in the layer switcher, default is set │ │ │ │ │ - * by {}. │ │ │ │ │ - */ │ │ │ │ │ - layerName: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: labelled │ │ │ │ │ - * {Boolean} Should the graticule lines be labelled?. default=true │ │ │ │ │ - */ │ │ │ │ │ - labelled: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: labelFormat │ │ │ │ │ - * {String} the format of the labels, default = 'dm'. See │ │ │ │ │ - * for other options. │ │ │ │ │ + * Property: startRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that start │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - labelFormat: 'dm', │ │ │ │ │ + startRegEx: /^mousedown|touchstart$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: lineSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render lines │ │ │ │ │ + * Property: cancelRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that cancel │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - lineSymbolizer: { │ │ │ │ │ - strokeColor: "#333", │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeOpacity: 0.5 │ │ │ │ │ - }, │ │ │ │ │ + cancelRegEx: /^touchmove$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: labelSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render labels │ │ │ │ │ + * Property: completeRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that complete │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - labelSymbolizer: {}, │ │ │ │ │ + completeRegEx: /^mouseup|touchend$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: gratLayer │ │ │ │ │ - * {} vector layer used to draw the graticule on │ │ │ │ │ + * Property: startEvt │ │ │ │ │ + * {Event} The event that started the click sequence │ │ │ │ │ */ │ │ │ │ │ - gratLayer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Graticule │ │ │ │ │ - * Create a new graticule control to display a grid of latitude longitude │ │ │ │ │ - * lines. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Events.buttonclick │ │ │ │ │ + * Construct a buttonclick event type. Applications are not supposed to │ │ │ │ │ + * create instances of this class - they are created on demand by │ │ │ │ │ + * instances. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * target - {} The events instance that the buttonclick │ │ │ │ │ + * event will be triggered on. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.layerName = options.layerName || OpenLayers.i18n("Graticule"); │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - this.labelSymbolizer.stroke = false; │ │ │ │ │ - this.labelSymbolizer.fill = false; │ │ │ │ │ - this.labelSymbolizer.label = "${label}"; │ │ │ │ │ - this.labelSymbolizer.labelAlign = "${labelAlign}"; │ │ │ │ │ - this.labelSymbolizer.labelXOffset = "${xOffset}"; │ │ │ │ │ - this.labelSymbolizer.labelYOffset = "${yOffset}"; │ │ │ │ │ + initialize: function(target) { │ │ │ │ │ + this.target = target; │ │ │ │ │ + for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ + this.target.register(this.events[i], this, this.buttonClick, { │ │ │ │ │ + extension: true │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.gratLayer) { │ │ │ │ │ - this.gratLayer.destroy(); │ │ │ │ │ - this.gratLayer = null; │ │ │ │ │ + for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ + this.target.unregister(this.events[i], this, this.buttonClick); │ │ │ │ │ } │ │ │ │ │ + delete this.target; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: getPressedButton │ │ │ │ │ + * Get the pressed button, if any. Returns undefined if no button │ │ │ │ │ + * was pressed. │ │ │ │ │ + * │ │ │ │ │ + * Arguments: │ │ │ │ │ + * element - {DOMElement} The event target. │ │ │ │ │ * │ │ │ │ │ - * initializes the graticule layer and does the initial update │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * {DOMElement} The button element, or undefined. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getPressedButton: function(element) { │ │ │ │ │ + var depth = 3, // limit the search depth │ │ │ │ │ + button; │ │ │ │ │ + do { │ │ │ │ │ + if (OpenLayers.Element.hasClass(element, "olButton")) { │ │ │ │ │ + // hit! │ │ │ │ │ + button = element; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + element = element.parentNode; │ │ │ │ │ + } while (--depth > 0 && element); │ │ │ │ │ + return button; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ + * Method: ignore │ │ │ │ │ + * Check for event target elements that should be ignored by OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The event target. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + ignore: function(element) { │ │ │ │ │ + var depth = 3, │ │ │ │ │ + ignore = false; │ │ │ │ │ + do { │ │ │ │ │ + if (element.nodeName.toLowerCase() === 'a') { │ │ │ │ │ + ignore = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + element = element.parentNode; │ │ │ │ │ + } while (--depth > 0 && element); │ │ │ │ │ + return ignore; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - /** │ │ │ │ │ - * Method: update │ │ │ │ │ + * Method: buttonClick │ │ │ │ │ + * Check if a button was clicked, and fire the buttonclick event │ │ │ │ │ * │ │ │ │ │ - * calculates the grid to be displayed and actually draws it │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - //wait for the map to be initialized before proceeding │ │ │ │ │ - var mapBounds = this.map.getExtent(); │ │ │ │ │ - if (!mapBounds) { │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); │ │ │ │ │ - centerLatPoints.push(newPoint); │ │ │ │ │ - } while (mapBounds.containsPixel(mapXY) && ++iter < 1000); │ │ │ │ │ + buttonClick: function(evt) { │ │ │ │ │ + var propagate = true, │ │ │ │ │ + element = OpenLayers.Event.element(evt); │ │ │ │ │ + if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) { │ │ │ │ │ + // was a button pressed? │ │ │ │ │ + var button = this.getPressedButton(element); │ │ │ │ │ + if (button) { │ │ │ │ │ + if (evt.type === "keydown") { │ │ │ │ │ + switch (evt.keyCode) { │ │ │ │ │ + case OpenLayers.Event.KEY_RETURN: │ │ │ │ │ + case OpenLayers.Event.KEY_SPACE: │ │ │ │ │ + this.target.triggerEvent("buttonclick", { │ │ │ │ │ + buttonElement: button │ │ │ │ │ + }); │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else if (this.startEvt) { │ │ │ │ │ + if (this.completeRegEx.test(evt.type)) { │ │ │ │ │ + var pos = OpenLayers.Util.pagePosition(button); │ │ │ │ │ + var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ + var scrollTop = window.pageYOffset || viewportElement.scrollTop; │ │ │ │ │ + var scrollLeft = window.pageXOffset || viewportElement.scrollLeft; │ │ │ │ │ + pos[0] = pos[0] - scrollLeft; │ │ │ │ │ + pos[1] = pos[1] - scrollTop; │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ + this.target.triggerEvent("buttonclick", { │ │ │ │ │ + buttonElement: button, │ │ │ │ │ + buttonXY: { │ │ │ │ │ + x: this.startEvt.clientX - pos[0], │ │ │ │ │ + y: this.startEvt.clientY - pos[1] │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (this.cancelRegEx.test(evt.type)) { │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - if (this.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 geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ - lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //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.startRegEx.test(evt.type)) { │ │ │ │ │ + this.startEvt = evt; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + propagate = !this.ignore(OpenLayers.Event.element(evt)); │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + return propagate; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Graticule" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Hover.js │ │ │ │ │ + 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/Handler.js │ │ │ │ │ + * @requires OpenLayers/Format/XML.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.Format.WMSGetFeatureInfo │ │ │ │ │ + * Class to read GetFeatureInfo responses from Web Mapping Services │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -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. │ │ │ │ │ - */ │ │ │ │ │ - delay: 500, │ │ │ │ │ +OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ - * an event to be considered a hover. Default is null. │ │ │ │ │ + * APIProperty: layerIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of layer nodes. │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: null, │ │ │ │ │ + layerIdentifier: '_layer', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopMove │ │ │ │ │ - * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: featureIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of feature nodes for each layer node found. │ │ │ │ │ */ │ │ │ │ │ - stopMove: false, │ │ │ │ │ + featureIdentifier: '_feature', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {} - The location of the last mousemove, expressed │ │ │ │ │ - * in pixels. │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - px: null, │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} - The id of the timer. │ │ │ │ │ + * Property: gmlFormat │ │ │ │ │ + * {} internal GML format for parsing geometries │ │ │ │ │ + * in msGMLOutput │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + gmlFormat: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ - * Construct a hover handler. │ │ │ │ │ + * Constructor: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ + * Create a new parser for WMS GetFeatureInfo responses │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Called when the mouse moves on the map. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read WMS GetFeatureInfo data from a string, and return an array of features │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + var result; │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ } │ │ │ │ │ - return !this.stopMove; │ │ │ │ │ + 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: mouseout │ │ │ │ │ - * Called when the mouse goes out of the map. │ │ │ │ │ + * Method: read_msGMLOutput │ │ │ │ │ + * Parse msGMLOutput nodes. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('move', [evt]); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ + * Method: read_FeatureInfoResponse │ │ │ │ │ + * Parse FeatureInfoResponse nodes. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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 passes; │ │ │ │ │ + return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * 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 │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * Array({DOMElement}) An array of sibling xml nodes │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ + 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: delayedCall │ │ │ │ │ - * Triggers pause callback. │ │ │ │ │ + * Method: parseAttributes │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.callback('pause', [evt]); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return attributes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + * Method: parseGeometry │ │ │ │ │ + * Parse the geometry and the feature bounds out of the node using │ │ │ │ │ + * Format.GML │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {Object} An object containing the geometry and the feature bounds │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - deactivated = true; │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + 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.Handler.Hover" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/UTFGrid.js │ │ │ │ │ + OpenLayers/Format/WMSDescribeLayer.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/Format/XML/VersionedOGC.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); │ │ │ │ │ + * Class: OpenLayers.Format.WMSDescribeLayer │ │ │ │ │ + * Read SLD WMS DescribeLayer response │ │ │ │ │ + * DescribeLayer is meant to couple WMS to WFS and WCS │ │ │ │ │ * │ │ │ │ │ - * var control = new OpenLayers.Control.UTFGrid({ │ │ │ │ │ - * layers: [world_utfgrid], │ │ │ │ │ - * handlerMode: 'move', │ │ │ │ │ - * callback: function(infoLookup) { │ │ │ │ │ - * // do something with returned data │ │ │ │ │ - * │ │ │ │ │ - * } │ │ │ │ │ - * }) │ │ │ │ │ - * (end code) │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * APIProperty: defaultVersion │ │ │ │ │ + * {String} Version number to assume if none found. Default is "1.1.1". │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + defaultVersion: "1.1.1", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: Layers │ │ │ │ │ - * List of layers to consider. Must be Layer.UTFGrids │ │ │ │ │ - * `null` is the default indicating all UTFGrid Layers are queried. │ │ │ │ │ - * {Array} │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.WMSDescribeLayer │ │ │ │ │ + * Create a new parser for WMS DescribeLayer responses. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ │ │ │ │ │ - /* Property: defaultHandlerOptions │ │ │ │ │ - * The default opts passed to the handler constructors │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read DescribeLayer data from a string, and return the response. │ │ │ │ │ + * The OGC currently defines 2 formats which are allowed for output, │ │ │ │ │ + * so we need to parse these 2 types │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} Array of {} objects which have: │ │ │ │ │ + * - {String} owsType: WFS/WCS │ │ │ │ │ + * - {String} owsURL: the online resource │ │ │ │ │ + * - {String} typeName: the name of the typename on the service │ │ │ │ │ */ │ │ │ │ │ - defaultHandlerOptions: { │ │ │ │ │ - 'delay': 300, │ │ │ │ │ - 'pixelTolerance': 4, │ │ │ │ │ - 'stopMove': false, │ │ │ │ │ - 'single': true, │ │ │ │ │ - 'double': false, │ │ │ │ │ - 'stopSingle': false, │ │ │ │ │ - 'stopDouble': false │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /* APIProperty: handlerMode │ │ │ │ │ - * Defaults to 'click'. Can be 'hover' or 'move'. │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/Context.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 │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.Context │ │ │ │ │ + * Base class for both Format.WMC and Format.OWSContext │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.Context = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerOptions │ │ │ │ │ + * {Object} Default options for layers created by the parser. These │ │ │ │ │ + * options are overridden by the options which are read from the │ │ │ │ │ + * capabilities document. │ │ │ │ │ */ │ │ │ │ │ - handlerMode: 'click', │ │ │ │ │ + layerOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setHandler │ │ │ │ │ - * sets this.handlerMode and calls resetHandler() │ │ │ │ │ + * Property: layerParams │ │ │ │ │ + * {Object} Default parameters for layers created by the parser. This │ │ │ │ │ + * can be used e.g. to override DEFAULT_PARAMS for │ │ │ │ │ + * OpenLayers.Layer.WMS. │ │ │ │ │ + */ │ │ │ │ │ + layerParams: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.Context │ │ │ │ │ + * Create a new parser for Context documents. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * hm - {String} Handler Mode string; 'click', 'hover' or 'move'. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - setHandler: function(hm) { │ │ │ │ │ - this.handlerMode = hm; │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read Context data from a string, and return an object with map │ │ │ │ │ + * properties and a list of layers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * options - {Object} The options object must contain a map property. If │ │ │ │ │ + * the map property is a string, it must be the id of a dom element │ │ │ │ │ + * where the new map will be placed. If the map property is an │ │ │ │ │ + * , the layers from the context document will be added │ │ │ │ │ + * to the map. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A map based on the context. │ │ │ │ │ + */ │ │ │ │ │ + read: function(data, options) { │ │ │ │ │ + var context = OpenLayers.Format.XML.VersionedOGC.prototype.read.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + var map; │ │ │ │ │ + if (options && options.map) { │ │ │ │ │ + this.context = context; │ │ │ │ │ + if (options.map instanceof OpenLayers.Map) { │ │ │ │ │ + map = this.mergeContextToMap(context, options.map); │ │ │ │ │ + } else { │ │ │ │ │ + var mapOptions = options.map; │ │ │ │ │ + if (OpenLayers.Util.isElement(mapOptions) || │ │ │ │ │ + typeof mapOptions == "string") { │ │ │ │ │ + // we assume mapOptions references a div │ │ │ │ │ + // element │ │ │ │ │ + mapOptions = { │ │ │ │ │ + div: mapOptions │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + map = this.contextToMap(context, mapOptions); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // not documented as part of the API, provided as a non-API option │ │ │ │ │ + map = context; │ │ │ │ │ + } │ │ │ │ │ + return map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetHandler │ │ │ │ │ - * Deactivates the old hanlder and creates a new │ │ │ │ │ - * based on the mode specified in │ │ │ │ │ - * this.handlerMode │ │ │ │ │ + * Method: getLayerFromContext │ │ │ │ │ + * Create a WMS layer from a layerContext object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layerContext - {Object} An object representing a WMS layer. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A WMS layer. │ │ │ │ │ */ │ │ │ │ │ - resetHandler: function() { │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.deactivate(); │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ + getLayerFromContext: function(layerContext) { │ │ │ │ │ + var i, len; │ │ │ │ │ + // fill initial options object from layerContext │ │ │ │ │ + var options = { │ │ │ │ │ + queryable: layerContext.queryable, //keep queryable for api compatibility │ │ │ │ │ + visibility: layerContext.visibility, │ │ │ │ │ + maxExtent: layerContext.maxExtent, │ │ │ │ │ + metadata: OpenLayers.Util.applyDefaults(layerContext.metadata, { │ │ │ │ │ + styles: layerContext.styles, │ │ │ │ │ + formats: layerContext.formats, │ │ │ │ │ + "abstract": layerContext["abstract"], │ │ │ │ │ + dataURL: layerContext.dataURL │ │ │ │ │ + }), │ │ │ │ │ + numZoomLevels: layerContext.numZoomLevels, │ │ │ │ │ + units: layerContext.units, │ │ │ │ │ + isBaseLayer: layerContext.isBaseLayer, │ │ │ │ │ + opacity: layerContext.opacity, │ │ │ │ │ + displayInLayerSwitcher: layerContext.displayInLayerSwitcher, │ │ │ │ │ + singleTile: layerContext.singleTile, │ │ │ │ │ + tileSize: (layerContext.tileSize) ? │ │ │ │ │ + new OpenLayers.Size( │ │ │ │ │ + layerContext.tileSize.width, │ │ │ │ │ + layerContext.tileSize.height │ │ │ │ │ + ) : undefined, │ │ │ │ │ + minScale: layerContext.minScale || layerContext.maxScaleDenominator, │ │ │ │ │ + maxScale: layerContext.maxScale || layerContext.minScaleDenominator, │ │ │ │ │ + srs: layerContext.srs, │ │ │ │ │ + dimensions: layerContext.dimensions, │ │ │ │ │ + metadataURL: layerContext.metadataURL │ │ │ │ │ + }; │ │ │ │ │ + if (this.layerOptions) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(options, this.layerOptions); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.handlerMode == 'hover') { │ │ │ │ │ - // Handle this event on hover │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'pause': this.handleEvent, │ │ │ │ │ - 'move': this.reset │ │ │ │ │ - }, │ │ │ │ │ - this.handlerOptions │ │ │ │ │ + var params = { │ │ │ │ │ + layers: layerContext.name, │ │ │ │ │ + transparent: layerContext.transparent, │ │ │ │ │ + version: layerContext.version │ │ │ │ │ + }; │ │ │ │ │ + if (layerContext.formats && layerContext.formats.length > 0) { │ │ │ │ │ + // set default value for params if current attribute is not positionned │ │ │ │ │ + params.format = layerContext.formats[0].value; │ │ │ │ │ + for (i = 0, len = layerContext.formats.length; i < len; i++) { │ │ │ │ │ + var format = layerContext.formats[i]; │ │ │ │ │ + if (format.current == true) { │ │ │ │ │ + params.format = format.value; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (layerContext.styles && layerContext.styles.length > 0) { │ │ │ │ │ + for (i = 0, len = layerContext.styles.length; i < len; i++) { │ │ │ │ │ + var style = layerContext.styles[i]; │ │ │ │ │ + if (style.current == true) { │ │ │ │ │ + // three style types to consider │ │ │ │ │ + // 1) linked SLD │ │ │ │ │ + // 2) inline SLD │ │ │ │ │ + // 3) named style │ │ │ │ │ + if (style.href) { │ │ │ │ │ + params.sld = style.href; │ │ │ │ │ + } else if (style.body) { │ │ │ │ │ + params.sld_body = style.body; │ │ │ │ │ + } else { │ │ │ │ │ + params.styles = style.name; │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.layerParams) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(params, this.layerParams); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var layer = null; │ │ │ │ │ + var service = layerContext.service; │ │ │ │ │ + if (service == OpenLayers.Format.Context.serviceTypes.WFS) { │ │ │ │ │ + options.strategies = [new OpenLayers.Strategy.BBOX()]; │ │ │ │ │ + options.protocol = new OpenLayers.Protocol.WFS({ │ │ │ │ │ + url: layerContext.url, │ │ │ │ │ + // since we do not know featureNS, let the protocol │ │ │ │ │ + // determine it automagically using featurePrefix │ │ │ │ │ + featurePrefix: layerContext.name.split(":")[0], │ │ │ │ │ + featureType: layerContext.name.split(":").pop() │ │ │ │ │ + }); │ │ │ │ │ + layer = new OpenLayers.Layer.Vector( │ │ │ │ │ + layerContext.title || layerContext.name, │ │ │ │ │ + options │ │ │ │ │ ); │ │ │ │ │ - } else if (this.handlerMode == 'click') { │ │ │ │ │ - // Handle this event on click │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, { │ │ │ │ │ - 'click': this.handleEvent │ │ │ │ │ - }, this.handlerOptions │ │ │ │ │ + } else if (service == OpenLayers.Format.Context.serviceTypes.KML) { │ │ │ │ │ + // use a vector layer with an HTTP Protcol and a Fixed strategy │ │ │ │ │ + options.strategies = [new OpenLayers.Strategy.Fixed()]; │ │ │ │ │ + options.protocol = new OpenLayers.Protocol.HTTP({ │ │ │ │ │ + url: layerContext.url, │ │ │ │ │ + format: new OpenLayers.Format.KML() │ │ │ │ │ + }); │ │ │ │ │ + layer = new OpenLayers.Layer.Vector( │ │ │ │ │ + layerContext.title || layerContext.name, │ │ │ │ │ + options │ │ │ │ │ ); │ │ │ │ │ - } 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 │ │ │ │ │ + } else if (service == OpenLayers.Format.Context.serviceTypes.GML) { │ │ │ │ │ + // use a vector layer with a HTTP Protocol and a Fixed strategy │ │ │ │ │ + options.strategies = [new OpenLayers.Strategy.Fixed()]; │ │ │ │ │ + options.protocol = new OpenLayers.Protocol.HTTP({ │ │ │ │ │ + url: layerContext.url, │ │ │ │ │ + format: new OpenLayers.Format.GML() │ │ │ │ │ + }); │ │ │ │ │ + layer = new OpenLayers.Layer.Vector( │ │ │ │ │ + layerContext.title || layerContext.name, │ │ │ │ │ + options │ │ │ │ │ + ); │ │ │ │ │ + } else if (layerContext.features) { │ │ │ │ │ + // inline GML or KML features │ │ │ │ │ + layer = new OpenLayers.Layer.Vector( │ │ │ │ │ + layerContext.title || layerContext.name, │ │ │ │ │ + options │ │ │ │ │ + ); │ │ │ │ │ + layer.addFeatures(layerContext.features); │ │ │ │ │ + } else if (layerContext.categoryLayer !== true) { │ │ │ │ │ + layer = new OpenLayers.Layer.WMS( │ │ │ │ │ + layerContext.title || layerContext.name, │ │ │ │ │ + layerContext.url, │ │ │ │ │ + params, │ │ │ │ │ + options │ │ │ │ │ ); │ │ │ │ │ } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ + return layer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: │ │ │ │ │ + * Method: getLayersFromContext │ │ │ │ │ + * Create an array of layers from an array of layerContext objects. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * layersContext - {Array(Object)} An array of objects representing layers. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} An array of layers. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || this.defaultHandlerOptions; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ + getLayersFromContext: function(layersContext) { │ │ │ │ │ + var layers = []; │ │ │ │ │ + for (var i = 0, len = layersContext.length; i < len; i++) { │ │ │ │ │ + var layer = this.getLayerFromContext(layersContext[i]); │ │ │ │ │ + if (layer !== null) { │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return layers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleEvent │ │ │ │ │ - * Internal method called when specified event is triggered. │ │ │ │ │ - * │ │ │ │ │ - * 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 │ │ │ │ │ + * Method: contextToMap │ │ │ │ │ + * Create a map given a context object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * context - {Object} The context object. │ │ │ │ │ + * options - {Object} Default map options. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A map based on the context object. │ │ │ │ │ */ │ │ │ │ │ - handleEvent: function(evt) { │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - this.reset(); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + contextToMap: function(context, options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults({ │ │ │ │ │ + maxExtent: context.maxExtent, │ │ │ │ │ + projection: context.projection, │ │ │ │ │ + units: context.units │ │ │ │ │ + }, options); │ │ │ │ │ │ │ │ │ │ - var lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ - if (!lonLat) { │ │ │ │ │ - return; │ │ │ │ │ + if (options.maxExtent) { │ │ │ │ │ + options.maxResolution = │ │ │ │ │ + options.maxExtent.getWidth() / OpenLayers.Map.TILE_WIDTH; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + var metadata = { │ │ │ │ │ + contactInformation: context.contactInformation, │ │ │ │ │ + "abstract": context["abstract"], │ │ │ │ │ + keywords: context.keywords, │ │ │ │ │ + logo: context.logo, │ │ │ │ │ + descriptionURL: context.descriptionURL │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + options.metadata = metadata; │ │ │ │ │ + │ │ │ │ │ + var map = new OpenLayers.Map(options); │ │ │ │ │ + map.addLayers(this.getLayersFromContext(context.layersContext)); │ │ │ │ │ + map.setCenter( │ │ │ │ │ + context.bounds.getCenterLonLat(), │ │ │ │ │ + map.getZoomForExtent(context.bounds, true) │ │ │ │ │ + ); │ │ │ │ │ + return map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: mergeContextToMap │ │ │ │ │ + * Add layers from a context object to a map. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ - */ │ │ │ │ │ - callback: function(infoLookup) { │ │ │ │ │ - // to be provided in the constructor │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: reset │ │ │ │ │ - * Calls the callback with null. │ │ │ │ │ + * context - {Object} The context object. │ │ │ │ │ + * map - {} The map. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The same map with layers added. │ │ │ │ │ */ │ │ │ │ │ - reset: function(evt) { │ │ │ │ │ - this.callback(null); │ │ │ │ │ + mergeContextToMap: function(context, map) { │ │ │ │ │ + map.addLayers(this.getLayersFromContext(context.layersContext)); │ │ │ │ │ + return map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ - * │ │ │ │ │ - * The default value of this.layers is null; this causes the │ │ │ │ │ - * findLayers method to return ALL UTFGrid layers encountered. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Write a context document given a map. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * None │ │ │ │ │ + * obj - { | Object} A map or context object. │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Array} Layers to handle on each event │ │ │ │ │ + * {String} A context document string. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + write: function(obj, options) { │ │ │ │ │ + obj = this.toContext(obj); │ │ │ │ │ + return OpenLayers.Format.XML.VersionedOGC.prototype.write.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.UTFGrid" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.Context" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Format.Context.serviceTypes │ │ │ │ │ + * Enumeration for service types │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.Context.serviceTypes = { │ │ │ │ │ + "WMS": "urn:ogc:serviceType:WMS", │ │ │ │ │ + "WFS": "urn:ogc:serviceType:WFS", │ │ │ │ │ + "WCS": "urn:ogc:serviceType:WCS", │ │ │ │ │ + "GML": "urn:ogc:serviceType:GML", │ │ │ │ │ + "SLD": "urn:ogc:serviceType:SLD", │ │ │ │ │ + "FES": "urn:ogc:serviceType:FES", │ │ │ │ │ + "KML": "urn:ogc:serviceType:KML" │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DrawFeature.js │ │ │ │ │ + OpenLayers/Format/KML.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/Date.js │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Request/XMLHttpRequest.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.DrawFeature │ │ │ │ │ - * The DrawFeature control draws point, line or polygon features on a vector │ │ │ │ │ - * layer when active. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Format.KML │ │ │ │ │ + * Read/Write KML. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + namespaces: { │ │ │ │ │ + kml: "http://www.opengis.net/kml/2.2", │ │ │ │ │ + gx: "http://www.google.com/kml/ext/2.2" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ + * APIProperty: kmlns │ │ │ │ │ + * {String} KML Namespace to use. Defaults to 2.0 namespace. │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + kmlns: "http://earth.google.com/kml/2.0", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: placemarksDesc │ │ │ │ │ + * {String} Name of the placemarks. Default is "No description available". │ │ │ │ │ */ │ │ │ │ │ + placemarksDesc: "No description available", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multi │ │ │ │ │ - * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ - * layer. Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: foldersName │ │ │ │ │ + * {String} Name of the folders. Default is "OpenLayers export". │ │ │ │ │ + * If set to null, no name element will be created. │ │ │ │ │ */ │ │ │ │ │ - multi: false, │ │ │ │ │ + foldersName: "OpenLayers export", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: featureAdded │ │ │ │ │ - * {Function} Called after each feature is added │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: foldersDesc │ │ │ │ │ + * {String} Description of the folders. Default is "Exported on [date]." │ │ │ │ │ + * If set to null, no description element will be created. │ │ │ │ │ */ │ │ │ │ │ - featureAdded: function() {}, │ │ │ │ │ + foldersDesc: "Exported on " + new Date(), │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * APIProperty: extractAttributes │ │ │ │ │ + * {Boolean} Extract attributes from KML. Default is true. │ │ │ │ │ + * Extracting styleUrls requires this to be set to true │ │ │ │ │ + * Note that currently only Data and SimpleData │ │ │ │ │ + * elements are handled. │ │ │ │ │ */ │ │ │ │ │ + extractAttributes: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.DrawFeature │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * handler - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * APIProperty: kvpAttributes │ │ │ │ │ + * {Boolean} Only used if extractAttributes is true. │ │ │ │ │ + * If set to true, attributes will be simple │ │ │ │ │ + * key-value pairs, compatible with other formats, │ │ │ │ │ + * Any displayName elements will be ignored. │ │ │ │ │ + * If set to false, attributes will be objects, │ │ │ │ │ + * retaining any displayName elements, but not │ │ │ │ │ + * compatible with other formats. Any CDATA in │ │ │ │ │ + * displayName will be read in as a string value. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + kvpAttributes: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ + * Property: extractStyles │ │ │ │ │ + * {Boolean} Extract styles from KML. Default is false. │ │ │ │ │ + * Extracting styleUrls also requires extractAttributes to be │ │ │ │ │ + * set to true │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + extractStyles: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertXY │ │ │ │ │ - * Insert a point in the current sketch given x & y coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Number} The x-coordinate of the point. │ │ │ │ │ - * y - {Number} The y-coordinate of the point. │ │ │ │ │ - */ │ │ │ │ │ - insertXY: function(x, y) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertXY(x, y); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + * APIProperty: extractTracks │ │ │ │ │ + * {Boolean} Extract gx:Track elements from Placemark elements. Default │ │ │ │ │ + * is false. If true, features will be generated for all points in │ │ │ │ │ + * all gx:Track elements. Features will have a when (Date) attribute │ │ │ │ │ + * based on when elements in the track. If tracks include angle │ │ │ │ │ + * elements, features will have heading, tilt, and roll attributes. │ │ │ │ │ + * If track point coordinates have three values, features will have │ │ │ │ │ + * an altitude attribute with the third coordinate value. │ │ │ │ │ + */ │ │ │ │ │ + extractTracks: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertDeltaXY │ │ │ │ │ - * Insert a point given offsets from the previously inserted point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} The x-coordinate offset of the point. │ │ │ │ │ - * dy - {Number} The y-coordinate offset of the point. │ │ │ │ │ + * APIProperty: trackAttributes │ │ │ │ │ + * {Array} If is true, points within gx:Track elements will │ │ │ │ │ + * be parsed as features with when, heading, tilt, and roll attributes. │ │ │ │ │ + * Any additional attribute names can be provided in . │ │ │ │ │ */ │ │ │ │ │ - insertDeltaXY: function(dx, dy) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeltaXY(dx, dy); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + trackAttributes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: insertDirectionLength │ │ │ │ │ - * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * Property: internalns │ │ │ │ │ + * {String} KML Namespace to use -- defaults to the namespace of the │ │ │ │ │ + * Placemark node being parsed, but falls back to kmlns. │ │ │ │ │ */ │ │ │ │ │ - insertDirectionLength: function(direction, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDirectionLength(direction, length); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + internalns: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: features │ │ │ │ │ + * {Array} Array of features │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - insertDeflectionLength: function(deflection, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeflectionLength(deflection, length); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + features: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: undo │ │ │ │ │ - * Remove the most recently added point in the current sketch geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was undone. │ │ │ │ │ + * Property: styles │ │ │ │ │ + * {Object} Storage of style objects │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - undo: function() { │ │ │ │ │ - return this.handler.undo && this.handler.undo(); │ │ │ │ │ - }, │ │ │ │ │ + styles: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: styleBaseUrl │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + styleBaseUrl: "", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: fetched │ │ │ │ │ + * {Object} Storage of KML URLs that have been fetched before │ │ │ │ │ + * in order to prevent reloading them. │ │ │ │ │ + */ │ │ │ │ │ + fetched: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxDepth │ │ │ │ │ + * {Integer} Maximum depth for recursive loading external KML URLs │ │ │ │ │ + * Defaults to 0: do no external fetching │ │ │ │ │ + */ │ │ │ │ │ + maxDepth: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.KML │ │ │ │ │ + * Create a new parser for KML. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was redone. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - redo: function() { │ │ │ │ │ - return this.handler.redo && this.handler.redo(); │ │ │ │ │ + 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), │ │ │ │ │ + kmlColor: (/(\w{2})(\w{2})(\w{2})(\w{2})/), │ │ │ │ │ + kmlIconPalette: (/root:\/\/icons\/palette-(\d+)(\.\w+)/), │ │ │ │ │ + straightBracket: (/\$\[(.*?)\]/g) │ │ │ │ │ + }; │ │ │ │ │ + // KML coordinates are always in longlat WGS84 │ │ │ │ │ + this.externalProjection = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read data from a string, and return a list of features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} List of features. │ │ │ │ │ */ │ │ │ │ │ - finishSketch: function() { │ │ │ │ │ - this.handler.finishGeometry(); │ │ │ │ │ + read: function(data) { │ │ │ │ │ + this.features = []; │ │ │ │ │ + this.styles = {}; │ │ │ │ │ + this.fetched = {}; │ │ │ │ │ + │ │ │ │ │ + // Set default options │ │ │ │ │ + var options = { │ │ │ │ │ + depth: 0, │ │ │ │ │ + styleBaseUrl: this.styleBaseUrl │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + return this.parseData(data, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Cancel the current sketch. This removes the current sketch and keeps │ │ │ │ │ - * the drawing control active. │ │ │ │ │ + * Method: parseData │ │ │ │ │ + * Read data from a string, and return a list of features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * options - {Object} Hash of options │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} List of features. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.handler.cancel(); │ │ │ │ │ - }, │ │ │ │ │ + parseData: function(data, options) { │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DrawFeature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Keyboard.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + // Loop throught the following node types in this order and │ │ │ │ │ + // process the nodes found │ │ │ │ │ + var types = ["Link", "NetworkLink", "Style", "StyleMap", "Placemark"]; │ │ │ │ │ + for (var i = 0, len = types.length; i < len; ++i) { │ │ │ │ │ + var type = types[i]; │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + var nodes = this.getElementsByTagNameNS(data, "*", type); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - */ │ │ │ │ │ + // skip to next type if no nodes are found │ │ │ │ │ + if (nodes.length == 0) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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, { │ │ │ │ │ + switch (type.toLowerCase()) { │ │ │ │ │ │ │ │ │ │ - /* http://www.quirksmode.org/js/keys.html explains key x-browser │ │ │ │ │ - key handling quirks in pretty nice detail */ │ │ │ │ │ + // Fetch external links │ │ │ │ │ + case "link": │ │ │ │ │ + case "networklink": │ │ │ │ │ + this.parseLinks(nodes, options); │ │ │ │ │ + break; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_EVENTS │ │ │ │ │ - * keydown, keypress, keyup │ │ │ │ │ - */ │ │ │ │ │ - KEY_EVENTS: ["keydown", "keyup"], │ │ │ │ │ + // parse style information │ │ │ │ │ + case "style": │ │ │ │ │ + if (this.extractStyles) { │ │ │ │ │ + this.parseStyles(nodes, options); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + case "stylemap": │ │ │ │ │ + if (this.extractStyles) { │ │ │ │ │ + this.parseStyleMaps(nodes, options); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: eventListener │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - eventListener: null, │ │ │ │ │ + // parse features │ │ │ │ │ + case "placemark": │ │ │ │ │ + this.parseFeatures(nodes, options); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: observeElement │ │ │ │ │ - * {DOMElement|String} The DOM element on which we listen for │ │ │ │ │ - * key events. Default to the document. │ │ │ │ │ - */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ + return this.features; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ - * Returns a new keyboard handler. │ │ │ │ │ + * Method: parseLinks │ │ │ │ │ + * Finds URLs of linked KML documents and fetches them │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * nodes - {Array} of {DOMElement} data to read/parse. │ │ │ │ │ + * options - {Object} Hash of options │ │ │ │ │ * │ │ │ │ │ - * 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 │ │ │ │ │ - ); │ │ │ │ │ + parseLinks: function(nodes, options) { │ │ │ │ │ + │ │ │ │ │ + // Fetch external links and │ │ │ │ │ + // Don't do anything if we have reached our maximum depth for recursion │ │ │ │ │ + if (options.depth >= this.maxDepth) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // increase depth │ │ │ │ │ + var newOptions = OpenLayers.Util.extend({}, options); │ │ │ │ │ + newOptions.depth++; │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = nodes.length; i < len; i++) { │ │ │ │ │ + var href = this.parseProperty(nodes[i], "*", "href"); │ │ │ │ │ + if (href && !this.fetched[href]) { │ │ │ │ │ + this.fetched[href] = true; // prevent reloading the same urls │ │ │ │ │ + var data = this.fetchLink(href); │ │ │ │ │ + if (data) { │ │ │ │ │ + this.parseData(data, newOptions); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: fetchLink │ │ │ │ │ + * Fetches a URL and returns the result │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * href - {String} url to be fetched │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.eventListener = null; │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ + fetchLink: function(href) { │ │ │ │ │ + var request = OpenLayers.Request.GET({ │ │ │ │ │ + url: href, │ │ │ │ │ + async: false │ │ │ │ │ + }); │ │ │ │ │ + if (request) { │ │ │ │ │ + return request.responseText; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: parseStyles │ │ │ │ │ + * Parses